summaryrefslogtreecommitdiff
path: root/t/cmop/modify_parent_method.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/cmop/modify_parent_method.t
downloadMoose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz
Diffstat (limited to 't/cmop/modify_parent_method.t')
-rw-r--r--t/cmop/modify_parent_method.t99
1 files changed, 99 insertions, 0 deletions
diff --git a/t/cmop/modify_parent_method.t b/t/cmop/modify_parent_method.t
new file mode 100644
index 0000000..8ba6c43
--- /dev/null
+++ b/t/cmop/modify_parent_method.t
@@ -0,0 +1,99 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Class::MOP;
+
+my @calls;
+
+{
+ package Parent;
+
+ use strict;
+ use warnings;
+ use metaclass;
+
+ use Carp 'confess';
+
+ sub method { push @calls, 'Parent::method' }
+
+ package Child;
+
+ use strict;
+ use warnings;
+ use metaclass;
+
+ use parent -norequire => 'Parent';
+
+ Child->meta->add_around_method_modifier(
+ 'method' => sub {
+ my $orig = shift;
+ push @calls, 'before Child::method';
+ $orig->(@_);
+ push @calls, 'after Child::method';
+ }
+ );
+}
+
+Parent->method;
+
+is_deeply(
+ [ splice @calls ],
+ [
+ 'Parent::method',
+ ]
+);
+
+Child->method;
+
+is_deeply(
+ [ splice @calls ],
+ [
+ 'before Child::method',
+ 'Parent::method',
+ 'after Child::method',
+ ]
+);
+
+{
+ package Parent;
+
+ Parent->meta->add_around_method_modifier(
+ 'method' => sub {
+ my $orig = shift;
+ push @calls, 'before Parent::method';
+ $orig->(@_);
+ push @calls, 'after Parent::method';
+ }
+ );
+}
+
+Parent->method;
+
+is_deeply(
+ [ splice @calls ],
+ [
+ 'before Parent::method',
+ 'Parent::method',
+ 'after Parent::method',
+ ]
+);
+
+Child->method;
+
+TODO: {
+ local $TODO = "pending fix";
+ is_deeply(
+ [ splice @calls ],
+ [
+ 'before Child::method',
+ 'before Parent::method',
+ 'Parent::method',
+ 'after Parent::method',
+ 'after Child::method',
+ ],
+ "cache is correctly invalidated when the parent method is wrapped"
+ );
+}
+
+done_testing;