From: Tomas Doran Date: Fri, 16 May 2008 01:35:00 +0000 (+0000) Subject: Add test in Class:MOP for ->identifier() and immutable not playing nice. Fix by makin... X-Git-Tag: 0_64~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53299a7b3705f1a4d21784404e5ea1a92b779675;p=gitmo%2FClass-MOP.git Add test in Class:MOP for ->identifier() and immutable not playing nice. Fix by making ::Immutable take a new around option (with the semantics you would expect) to wrap methods. Wrap add_package_symbol thusly, erroring out with the error suggested by stevan in #moose --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index aa0602e..9977409 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -907,7 +907,6 @@ sub create_immutable_transformer { remove_method add_attribute remove_attribute - add_package_symbol remove_package_symbol /], memoize => { @@ -916,7 +915,14 @@ sub create_immutable_transformer { compute_all_applicable_attributes => 'ARRAY', get_meta_instance => 'SCALAR', get_method_map => 'SCALAR', - } + }, + around => { + add_package_symbol => sub { + my $original = shift; + confess "NO ADD SYMBOLS FOR YOU" unless caller eq 'get_package_symbol'; + $original->(@_); + }, + }, }); return $class; } diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index 3cb1054..f4a84b0 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -8,6 +8,7 @@ use Class::MOP::Method::Constructor; use Carp 'confess'; use Scalar::Util 'blessed'; +use Sub::Name 'subname'; our $VERSION = '0.05'; our $AUTHORITY = 'cpan:STEVAN'; @@ -233,6 +234,13 @@ sub create_methods_for_immutable_metaclass { $methods{$method_name} = sub { $_[0]->{'___' . $method_name} }; } } + + my $around_methods = $self->options->{around}; + foreach my $method_name (keys %{$around_methods}) { + my $method = $self->metaclass->meta->find_method_by_name($method_name); + $method = Class::MOP::Method::Wrapped->wrap($method); + $method->add_around_modifier(subname ':around' => $around_methods->{$method_name}); + } $methods{get_mutable_metaclass_name} = sub { (shift)->{'___original_class'} }; diff --git a/t/070_immutable_metaclass.t b/t/070_immutable_metaclass.t index c88d914..ffc8b76 100644 --- a/t/070_immutable_metaclass.t +++ b/t/070_immutable_metaclass.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 83; +use Test::More tests => 84; use Test::Exception; BEGIN { @@ -96,6 +96,7 @@ BEGIN { dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; + lives_ok{ $meta->identifier() } '... no exception for get_package_symbol special case'; my @supers; lives_ok {