From: Dave Rolsky Date: Tue, 7 Jul 2009 18:05:48 +0000 (-0500) Subject: give unique names to method modifiers X-Git-Tag: 0.90~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a642c024cf3e964eedddffa171cc501bac9265d;p=gitmo%2FClass-MOP.git give unique names to method modifiers --- diff --git a/Changes b/Changes index 4bba164..e23f523 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,10 @@ Revision history for Perl extension Class-MOP. - Anonymous classes were not destroyed properly when they went out of scope, leading to a memory leak. RT #47480 (Goro Fuji). + * Class::MOP::Class + - Give method modifiers unique names as they are added so that + introspection of caller() gives you something more useful. + 0.89 Fri Jul 3, 2009 * Class::MOP::Class diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 8810338..24234b8 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -672,7 +672,7 @@ sub add_method { || confess "You must pass in a method name"; my $method = $fetch_and_prepare_method->($self, $method_name); $method->add_before_modifier( - subname(':before' => $method_modifier) + subname(':before-' . $method_name => $method_modifier) ); } @@ -682,7 +682,7 @@ sub add_method { || confess "You must pass in a method name"; my $method = $fetch_and_prepare_method->($self, $method_name); $method->add_after_modifier( - subname(':after' => $method_modifier) + subname(':after-' . $method_name => $method_modifier) ); } @@ -692,7 +692,7 @@ sub add_method { || confess "You must pass in a method name"; my $method = $fetch_and_prepare_method->($self, $method_name); $method->add_around_modifier( - subname(':around' => $method_modifier) + subname(':around-' . $method_name => $method_modifier) ); } diff --git a/t/031_method_modifiers.t b/t/031_method_modifiers.t index 4ab736f..3b04428 100644 --- a/t/031_method_modifiers.t +++ b/t/031_method_modifiers.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 30; use Test::Exception; use Class::MOP; @@ -206,3 +206,25 @@ use Class::MOP::Method; 'check around_modifiers' ); } +# unique names for each modifier +{ + package Foo; + + sub orig1 { + return (caller(1))[3]; + } + + sub orig2 { + return (caller(1))[3]; + } + + my $meta = Class::MOP::Class->initialize(__PACKAGE__); + + $meta->add_around_method_modifier( 'orig1', sub { $_[0]->( $_[1] ) } ); + $meta->add_around_method_modifier( 'orig2', sub { $_[0]->( $_[1] ) } ); +} + +{ + is( Foo->orig1, 'Class::MOP::Class:::around-orig1', 'each modifier gets a unique name' ); + is( Foo->orig2, 'Class::MOP::Class:::around-orig2', 'each modifier gets a unique name' ); +}