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 | |
parent | POD and confess (diff) | |
download | moosex-privacy-81aab6d1a8fdd1334792bffd703d35a81771e772.tar.gz |
update tests
-rw-r--r-- | t/10_private_method.t | 26 | ||||
-rw-r--r-- | t/11_protected_method.t | 23 | ||||
-rw-r--r-- | t/12_meta_method_private.t | 43 | ||||
-rw-r--r-- | t/13_meta_method_protected.t | 45 |
4 files changed, 91 insertions, 46 deletions
diff --git a/t/10_private_method.t b/t/10_private_method.t index dabc8c9..b2f3056 100644 --- a/t/10_private_method.t +++ b/t/10_private_method.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 7; use Test::Exception; { @@ -10,7 +10,7 @@ use Test::Exception; use Moose; use MooseX::Privacy; - private_method 'bar' => sub { + private_method bar => sub { my $self = shift; return 'baz'; }; @@ -31,16 +31,6 @@ use Test::Exception; return 'foobar' . $str; }; - sub add_public_method { - my $self = shift; - $self->meta->add_method( - 'public_foo', - sub { - $self->private_meta_method; - } - ); - } - } { @@ -68,15 +58,3 @@ dies_ok { $bar->newbar() } "... can't call bar, method is private"; is scalar @{ $foo->meta->local_private_methods }, 2, '... got two privates method'; -my $private_method = Class::MOP::Method->wrap( - sub { return 23 }, - name => 'private_meta_method', - package_name => 'Foo' -); - -$foo->meta->add_private_method($private_method); - -dies_ok { $foo->private_meta_method } '... can\'t call the private method'; - -$foo->add_public_method; -is $foo->public_foo, 23, '... call private method via public method'; diff --git a/t/11_protected_method.t b/t/11_protected_method.t index 13e03e1..3618069 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 => 7; +use Test::More tests => 5; use Test::Exception; { @@ -26,17 +26,6 @@ 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(); @@ -50,15 +39,5 @@ 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'; diff --git a/t/12_meta_method_private.t b/t/12_meta_method_private.t new file mode 100644 index 0000000..3a64bdf --- /dev/null +++ b/t/12_meta_method_private.t @@ -0,0 +1,43 @@ +use strict; +use warnings; +use Test::More; + +use Moose::Meta::Class; +use MooseX::Privacy::Meta::Method::Private; + +my $metaclass = Moose::Meta::Class->create('Foo'); + +ok my $private_method = MooseX::Privacy::Meta::Method::Private->wrap( + name => 'foo', + package_name => 'Foo', + body => sub { return 23 } + ), + 'create Method::Private method'; + +isa_ok $private_method, 'MooseX::Privacy::Meta::Method::Private'; +eval { $private_method->execute }; +like $@, qr/The Foo::foo method is private/, + "can't execute private method in main package"; + +{ + + package Foo; + use Moose; + use MooseX::Privacy; + sub baz { return $_[0]->foo + $_[0]->bar } +} + +my $object = Foo->new(); +ok $object->meta->add_private_method( 'foo', $private_method ), + 'add_private_method accept a Method::Private instance'; +ok $object->meta->add_private_method( 'bar', sub { return 42 } ), + 'add_private_method create a new Method::Private instance'; +is scalar @{ $object->meta->local_private_methods }, 2, + 'got two private methods'; + +is $object->baz, 65, 'everything works fine'; + +done_testing; + + + 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; |