Commit | Line | Data |
9766c839 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
1dd3878d |
6 | use Test::More tests => 5; |
9766c839 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Class::MOP'); |
11 | } |
12 | |
13 | my @calls; |
14 | |
15 | { |
16 | package Parent; |
17 | |
18 | use strict; |
19 | use warnings; |
20 | use metaclass; |
21 | |
22 | use Carp 'confess'; |
23 | |
24 | sub method { push @calls, 'Parent::method' } |
25 | |
26 | package Child; |
27 | |
28 | use strict; |
29 | use warnings; |
30 | use metaclass; |
31 | |
32 | use base 'Parent'; |
33 | |
34 | Child->meta->add_around_method_modifier('method' => sub { |
35 | my $orig = shift; |
36 | push @calls, 'before Child::method'; |
37 | $orig->(@_); |
38 | push @calls, 'after Child::method'; |
39 | }); |
40 | } |
41 | |
42 | Parent->method; |
43 | |
44 | is_deeply([splice @calls], [ |
45 | 'Parent::method', |
46 | ]); |
47 | |
48 | Child->method; |
49 | |
50 | is_deeply([splice @calls], [ |
51 | 'before Child::method', |
52 | 'Parent::method', |
53 | 'after Child::method', |
54 | ]); |
55 | |
56 | { |
57 | package Parent; |
58 | |
59 | Parent->meta->add_around_method_modifier('method' => sub { |
60 | my $orig = shift; |
61 | push @calls, 'before Parent::method'; |
62 | $orig->(@_); |
63 | push @calls, 'after Parent::method'; |
64 | }); |
65 | } |
66 | |
67 | Parent->method; |
68 | |
69 | is_deeply([splice @calls], [ |
70 | 'before Parent::method', |
71 | 'Parent::method', |
72 | 'after Parent::method', |
73 | ]); |
74 | |
75 | Child->method; |
76 | |
1dd3878d |
77 | TODO: { |
78 | local $TODO = "pending fix"; |
79 | is_deeply([splice @calls], [ |
80 | 'before Child::method', |
81 | 'before Parent::method', |
82 | 'Parent::method', |
83 | 'after Parent::method', |
84 | 'after Child::method', |
85 | ], "cache is correctly invalidated when the parent method is wrapped"); |
86 | } |
9766c839 |
87 | |