Merge branch 'stable'
[gitmo/Class-MOP.git] / t / 302_modify_parent_method.t
CommitLineData
9766c839 1use strict;
2use warnings;
3
86a4d873 4use Test::More;
871e9eb5 5use Test::Fatal;
9766c839 6
efd3d14c 7use Class::MOP;
9766c839 8
9my @calls;
10
11{
12 package Parent;
13
14 use strict;
15 use warnings;
16 use metaclass;
17
18 use Carp 'confess';
19
20 sub method { push @calls, 'Parent::method' }
21
49ca2e97 22 package Child;
9766c839 23
49ca2e97 24 use strict;
25 use warnings;
9766c839 26 use metaclass;
27
49ca2e97 28 use base 'Parent';
9766c839 29
49ca2e97 30 Child->meta->add_around_method_modifier(
31 'method' => sub {
32 my $orig = shift;
33 push @calls, 'before Child::method';
34 $orig->(@_);
35 push @calls, 'after Child::method';
36 }
37 );
9766c839 38}
39
40Parent->method;
41
49ca2e97 42is_deeply(
43 [ splice @calls ],
44 [
45 'Parent::method',
46 ]
47);
9766c839 48
49Child->method;
50
49ca2e97 51is_deeply(
52 [ splice @calls ],
53 [
54 'before Child::method',
55 'Parent::method',
56 'after Child::method',
57 ]
58);
9766c839 59
60{
61 package Parent;
62
49ca2e97 63 Parent->meta->add_around_method_modifier(
64 'method' => sub {
65 my $orig = shift;
66 push @calls, 'before Parent::method';
67 $orig->(@_);
68 push @calls, 'after Parent::method';
69 }
70 );
9766c839 71}
72
73Parent->method;
74
49ca2e97 75is_deeply(
76 [ splice @calls ],
77 [
78 'before Parent::method',
79 'Parent::method',
80 'after Parent::method',
81 ]
82);
9766c839 83
84Child->method;
85
1dd3878d 86TODO: {
87 local $TODO = "pending fix";
49ca2e97 88 is_deeply(
89 [ splice @calls ],
90 [
91 'before Child::method',
92 'before Parent::method',
93 'Parent::method',
94 'after Parent::method',
95 'after Child::method',
96 ],
97 "cache is correctly invalidated when the parent method is wrapped"
98 );
1dd3878d 99}
9766c839 100
86a4d873 101done_testing;