Commit | Line | Data |
72c21074 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 1; |
7 | |
8 | BEGIN { |
9 | use_ok('Class::MOP'); |
10 | use_ok('Class::MOP::SafeMixin'); |
11 | } |
12 | |
13 | { |
14 | package FooMixin; |
15 | use metaclass; |
16 | |
17 | my %cache; |
18 | sub MODIFY_CODE_ATTRIBUTES { |
19 | my ($class, $code, @attrs) = @_; |
20 | ::diag join ", " => $code, "Attrs: ", @attrs; |
21 | $cache{$code} = $attrs[0]; |
22 | return (); |
23 | } |
24 | |
25 | sub FETCH_CODE_ATTRIBUTES { $cache{$_[1]} } |
26 | |
27 | sub foo : before { 'FooMixin::foo::before -> ' } |
28 | sub bar : after { ' -> FooMixin::bar::after' } |
29 | sub baz : around { |
30 | my $method = shift; |
31 | my ($self, @args) = @_; |
32 | 'FooMixin::baz::around(' . $self->$method(@args) . ')'; |
33 | } |
34 | |
35 | package Foo; |
36 | use metaclass 'Class::MOP::SafeMixin'; |
37 | |
38 | Foo->meta->mixin('FooMixin'); |
39 | |
40 | sub new { (shift)->meta->new_object(@_) } |
41 | |
42 | sub foo { 'Foo::foo' } |
43 | sub bar { 'Foo::bar' } |
44 | sub baz { 'Foo::baz' } |
45 | } |
46 | |
47 | diag attributes::get(\&FooMixin::foo) . "\n"; |
48 | |
49 | my $foo = Foo->new(); |
50 | isa_ok($foo, 'Foo'); |
51 | |
52 | is($foo->foo(), 'FooMixin::foo::before -> Foo::foo', '... before method worked'); |
53 | is($foo->bar(), 'Foo::bar -> FooMixin::bar::after', '... after method worked'); |
54 | is($foo->baz(), 'FooMixin::baz::around(Foo::baz)', '... around method worked'); |
55 | |
56 | |
57 | |
58 | |