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