Failing tests for method modifiers in a role
Shawn M Moore [Wed, 30 Jul 2008 15:30:09 +0000 (15:30 +0000)]
t/403-method-modifiers.t [new file with mode: 0644]

diff --git a/t/403-method-modifiers.t b/t/403-method-modifiers.t
new file mode 100644 (file)
index 0000000..67b0d6f
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 4;
+use Test::Exception;
+
+my @calls;
+my ($before, $after, $around);
+
+do {
+    package Role;
+    use Mouse::Role;
+
+    $before = sub {
+        push @calls, 'Role::foo:before';
+    };
+    before foo => $before;
+
+    $after = sub {
+        push @calls, 'Role::foo:after';
+    };
+    after foo => $after;
+
+    $around = sub {
+        my $orig = shift;
+        push @calls, 'Role::foo:around_before';
+        $orig->(@_);
+        push @calls, 'Role::foo:around_after';
+    };
+    around foo => $around;
+
+    no Mouse::Role;
+};
+
+is_deeply([Role->meta->get_before_method_modifiers('foo')], [$before]);
+is_deeply([Role->meta->get_after_method_modifiers('foo')],  [$after]);
+is_deeply([Role->meta->get_around_method_modifiers('foo')], [$around]);
+
+do {
+    package Class;
+    use Mouse;
+    with 'Role';
+
+    sub foo {
+        push @calls, 'Class::foo';
+    }
+
+    no Mouse;
+};
+
+Class->foo;
+is_deeply([splice @calls], [
+    'Role::foo:before',
+    'Role::foo:around_before',
+    'Class::foo',
+    'Role::foo:around_after',
+    'Role::foo:after',
+]);
+