uploadin
[gitmo/Class-MOP.git] / t / 301_safe_mixin_decorators.t
CommitLineData
72c21074 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7
8BEGIN {
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
47diag attributes::get(\&FooMixin::foo) . "\n";
48
49my $foo = Foo->new();
50isa_ok($foo, 'Foo');
51
52is($foo->foo(), 'FooMixin::foo::before -> Foo::foo', '... before method worked');
53is($foo->bar(), 'Foo::bar -> FooMixin::bar::after', '... after method worked');
54is($foo->baz(), 'FooMixin::baz::around(Foo::baz)', '... around method worked');
55
56
57
58