From: Shawn M Moore Date: Wed, 11 Jun 2008 09:15:22 +0000 (+0000) Subject: Add failing test for modifying a parent method after modifying a child method (the... X-Git-Tag: 0_64~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9766c839ceda96daec9422592992376fb1a0bc1c;p=gitmo%2FClass-MOP.git Add failing test for modifying a parent method after modifying a child method (the cache isn't updated) --- diff --git a/t/302_modify_parent_method.t b/t/302_modify_parent_method.t new file mode 100644 index 0000000..68f3e38 --- /dev/null +++ b/t/302_modify_parent_method.t @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 20; +use Test::Exception; + +BEGIN { + use_ok('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 base '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; + +is_deeply([splice @calls], [ + 'before Child::method', + 'before Parent::method', + 'Parent::method', + 'after Parent::method', + 'after Child::method', +]); +