From 1ae3b8b58a365a3db69c7a705cda9b90f822b524 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sun, 14 Feb 2010 14:19:43 +0100 Subject: add_{private,protected}_method accept meta method --- t/11_protected_method.t | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 't/11_protected_method.t') diff --git a/t/11_protected_method.t b/t/11_protected_method.t index 587979b..13e03e1 100644 --- a/t/11_protected_method.t +++ b/t/11_protected_method.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 7; use Test::Exception; { @@ -26,6 +26,17 @@ use Test::Exception; my $self = shift; return $self->bar; } + + sub add_public_method { + my $self = shift; + $self->meta->add_method( + 'public_foo', + sub { + $self->protected_meta_method; + } + ); + } + } my $foo = Foo->new(); @@ -38,3 +49,16 @@ is $bar->baz(), 'baz', "... got the good value from &bar"; is scalar @{ $foo->meta->local_protected_methods }, 1, '... got one protected method'; + +my $protected_method = Class::MOP::Method->wrap( + sub { return 23 }, + name => 'protected_meta_method', + package_name => 'Foo' +); + +$foo->meta->add_protected_method($protected_method); + +dies_ok { $foo->protected_meta_method } '... can\'t call the protected method'; + +$bar->add_public_method; +is $bar->public_foo, 23, '... call protected method via public method'; -- cgit v1.2.3