split accessor generator from the Meta::Attribute.
[gitmo/Mouse.git] / t / 403-method-modifiers.t
CommitLineData
4fd5e347 1#!/usr/bin/env perl
2use strict;
3use warnings;
c13900f1 4use Test::More;
5BEGIN {
6 if (eval "require Class::Method::Modifiers; 1") {
7 plan tests => 4;
8 }
9 else {
10 plan skip_all => "Class::Method::Modifiers required for this test";
11 }
12}
eab81545 13use Test::Exception;
4fd5e347 14
15my @calls;
16my ($before, $after, $around);
17
18do {
19 package Role;
20 use Mouse::Role;
21
22 $before = sub {
23 push @calls, 'Role::foo:before';
24 };
25 before foo => $before;
26
27 $after = sub {
28 push @calls, 'Role::foo:after';
29 };
30 after foo => $after;
31
32 $around = sub {
33 my $orig = shift;
34 push @calls, 'Role::foo:around_before';
35 $orig->(@_);
36 push @calls, 'Role::foo:around_after';
37 };
38 around foo => $around;
39
40 no Mouse::Role;
41};
42
43is_deeply([Role->meta->get_before_method_modifiers('foo')], [$before]);
44is_deeply([Role->meta->get_after_method_modifiers('foo')], [$after]);
45is_deeply([Role->meta->get_around_method_modifiers('foo')], [$around]);
46
47do {
48 package Class;
49 use Mouse;
50 with 'Role';
51
52 sub foo {
53 push @calls, 'Class::foo';
54 }
55
56 no Mouse;
57};
58
59Class->foo;
60is_deeply([splice @calls], [
61 'Role::foo:before',
62 'Role::foo:around_before',
63 'Class::foo',
64 'Role::foo:around_after',
65 'Role::foo:after',
66]);
67