summary refs log tree commit diff
path: root/t/13_meta_method_protected.t
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-02-14 18:00:33 +0100
committerfranck cuny <franck@lumberjaph.net>2010-02-14 18:00:33 +0100
commit81aab6d1a8fdd1334792bffd703d35a81771e772 (patch)
treefa9782f995401cbb2b8bdb4c6cc5d9ef2ed84002 /t/13_meta_method_protected.t
parentPOD and confess (diff)
downloadmoosex-privacy-81aab6d1a8fdd1334792bffd703d35a81771e772.tar.gz
update tests
Diffstat (limited to 't/13_meta_method_protected.t')
-rw-r--r--t/13_meta_method_protected.t45
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;