diff options
author | franck cuny <franck@lumberjaph.net> | 2010-02-14 18:00:33 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-02-14 18:00:33 +0100 |
commit | 81aab6d1a8fdd1334792bffd703d35a81771e772 (patch) | |
tree | fa9782f995401cbb2b8bdb4c6cc5d9ef2ed84002 /t/13_meta_method_protected.t | |
parent | POD and confess (diff) | |
download | moosex-privacy-81aab6d1a8fdd1334792bffd703d35a81771e772.tar.gz |
update tests
Diffstat (limited to 't/13_meta_method_protected.t')
-rw-r--r-- | t/13_meta_method_protected.t | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/t/13_meta_method_protected.t b/t/13_meta_method_protected.t new file mode 100644 index 0000000..74cd13c --- /dev/null +++ b/t/13_meta_method_protected.t @@ -0,0 +1,45 @@ +use strict; +use warnings; +use Test::More; + +use Moose::Meta::Class; +use MooseX::Privacy::Meta::Method::Protected; + +my $metaclass = Moose::Meta::Class->create('Foo'); + +ok my $protected_method = MooseX::Privacy::Meta::Method::Protected->wrap( + name => 'foo', + package_name => 'Foo', + body => sub { return 23 } + ), + 'create Method::Protected method'; + +isa_ok $protected_method, 'MooseX::Privacy::Meta::Method::Protected'; +eval { $protected_method->execute }; +like $@, qr/The Foo::foo method is protected/, + "can't execute a protected method in main package"; + +{ + + package Foo; + use Moose; + use MooseX::Privacy; + + package Bar; + use Moose; + extends qw/Foo/; + sub baz { return $_[0]->foo + $_[0]->bar } +} + +my $foo_object = Foo->new; +ok $foo_object->meta->add_protected_method( 'foo', $protected_method ), + 'add_protected_method accept a Method::Protected instance'; +ok $foo_object->meta->add_protected_method( 'bar', sub { return 42 } ), + 'add_protected_method create a new Method::Protected instance'; +is scalar @{ $foo_object->meta->local_protected_methods }, 2, + 'got two protected methods'; + +my $bar_object = Bar->new; +is $bar_object->baz, 65, 'everything works fine'; + +done_testing; |