From: Stevan Little Date: Tue, 11 Apr 2006 16:42:01 +0000 (+0000) Subject: stuff X-Git-Tag: 0_24~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c936afce28f5ef24318d90c8ad03d634c2d321a;p=gitmo%2FClass-MOP.git stuff --- diff --git a/Changes b/Changes index 3aa8709..4c450b5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Perl extension Class-MOP. +0.24 + * Class::MOP::Class + - cleaned up how the before/after/around method + modifiers get named with Sub::Name + 0.23 Thurs. March 30, 2006 * Class::MOP::Class - fixed the way attribute defaults are handled diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 2ff2c82..81aa4ea 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -9,7 +9,7 @@ use Scalar::Util 'blessed', 'reftype'; use Sub::Name 'subname'; use B 'svref_2object'; -our $VERSION = '0.09'; +our $VERSION = '0.10'; # Self-introspection @@ -221,7 +221,7 @@ sub class_precedence_list { # up otherwise. Yes, it's an ugly hack, better # suggestions are welcome. { $self->name->isa('This is a test for circular inheritance') } - # ... and no back to our regularly scheduled program + # ... and now back to our regularly scheduled program ( $self->name, map { @@ -278,30 +278,39 @@ sub add_method { sub add_before_method_modifier { my ($self, $method_name, $method_modifier) = @_; (defined $method_name && $method_name) - || confess "You must pass in a method name"; - my $full_method_modifier_name = ($self->name . '::' . $method_name . ':before'); + || confess "You must pass in a method name"; my $method = $fetch_and_prepare_method->($self, $method_name); - $method->add_before_modifier(subname $full_method_modifier_name => $method_modifier); + $method->add_before_modifier(subname ':before' => $method_modifier); } sub add_after_method_modifier { my ($self, $method_name, $method_modifier) = @_; (defined $method_name && $method_name) - || confess "You must pass in a method name"; - my $full_method_modifier_name = ($self->name . '::' . $method_name . ':after'); + || confess "You must pass in a method name"; my $method = $fetch_and_prepare_method->($self, $method_name); - $method->add_after_modifier(subname $full_method_modifier_name => $method_modifier); + $method->add_after_modifier(subname ':after' => $method_modifier); } sub add_around_method_modifier { my ($self, $method_name, $method_modifier) = @_; (defined $method_name && $method_name) || confess "You must pass in a method name"; - my $full_method_modifier_name = ($self->name . '::' . $method_name . ':around'); my $method = $fetch_and_prepare_method->($self, $method_name); - $method->add_around_modifier(subname $full_method_modifier_name => $method_modifier); + $method->add_around_modifier(subname ':around' => $method_modifier); } + # NOTE: + # the methods above used to be named like this: + # ${pkg}::${method}:(before|after|around) + # but this proved problematic when using one modifier + # to wrap multiple methods (something which is likely + # to happen pretty regularly IMO). So instead of naming + # it like this, I have chosen to just name them purely + # with their modifier names, like so: + # :(before|after|around) + # The fact is that in a stack trace, it will be fairly + # evident from the context what method they are attached + # to, and so don't need the fully qualified name. } sub alias_method { @@ -589,6 +598,9 @@ Class::MOP::Class - Class Meta Object =head1 SYNOPSIS + # assuming that class Foo + # has been defined, you can + # use this for introspection ... # add a method to Foo ...