X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FClass.pm;h=fa5331560d1fb3d61cdbf16d90fd7f56c4a6900b;hb=45160c4b37efc1dce63d008c7a734d8250fb714c;hp=f38822fcf073275428fab5dcfea1263b5e71ee80;hpb=26a08c157f47d613aab9376a85512ae73ec34482;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index f38822f..fa53315 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -11,7 +11,7 @@ use List::Util qw( first ); use List::MoreUtils qw( any all uniq first_index ); use Scalar::Util 'weaken', 'blessed'; -our $VERSION = '0.93_01'; +our $VERSION = '0.99'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -68,32 +68,6 @@ sub initialize { ); } -sub reinitialize { - my $self = shift; - my $pkg = shift; - - my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); - - my %existing_classes; - if ($meta) { - %existing_classes = map { $_ => $meta->$_() } qw( - attribute_metaclass - method_metaclass - wrapped_method_metaclass - instance_metaclass - constructor_class - destructor_class - error_class - ); - } - - return $self->SUPER::reinitialize( - $pkg, - %existing_classes, - @_, - ); -} - sub _immutable_options { my ( $self, @args ) = @_; @@ -141,11 +115,8 @@ sub create_anon_class { my $cache_ok = delete $options{cache}; - # something like Super::Class|Super::Class::2=Role|Role::1 - my $cache_key = join '=' => ( - join('|', @{$options{superclasses} || []}), - join('|', sort @{$options{roles} || []}), - ); + my $cache_key + = _anon_cache_key( $options{superclasses}, $options{roles} ); if ($cache_ok && defined $ANON_CLASSES{$cache_key}) { return $ANON_CLASSES{$cache_key}; @@ -159,6 +130,59 @@ sub create_anon_class { return $new_class; } +sub _anon_cache_key { + # Makes something like Super::Class|Super::Class::2=Role|Role::1 + return join '=' => ( + join( '|', @{ $_[0] || [] } ), + join( '|', sort @{ $_[1] || [] } ), + ); +} + +sub reinitialize { + my $self = shift; + my $pkg = shift; + + my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg); + + my $cache_key; + + my %existing_classes; + if ($meta) { + %existing_classes = map { $_ => $meta->$_() } qw( + attribute_metaclass + method_metaclass + wrapped_method_metaclass + instance_metaclass + constructor_class + destructor_class + error_class + ); + + $cache_key = _anon_cache_key( + [ $meta->superclasses ], + [ map { $_->name } @{ $meta->roles } ], + ) if $meta->is_anon_class; + } + + my $new_meta = $self->SUPER::reinitialize( + $pkg, + %existing_classes, + @_, + ); + + return $new_meta unless defined $cache_key; + + my $new_cache_key = _anon_cache_key( + [ $meta->superclasses ], + [ map { $_->name } @{ $meta->roles } ], + ); + + delete $ANON_CLASSES{$cache_key}; + $ANON_CLASSES{$new_cache_key} = $new_meta; + + return $new_meta; +} + sub add_role { my ($self, $role) = @_; (blessed($role) && $role->isa('Moose::Meta::Role')) @@ -743,10 +767,11 @@ adds it to the class's list of role applications. This I actually apply any role to the class; it is only for tracking role applications. -=item B<< $metaclass->does_role($role_name) >> +=item B<< $metaclass->does_role($role) >> -This returns a boolean indicating whether or not the class does the -specified role. This tests both the class and its parents. +This returns a boolean indicating whether or not the class does the specified +role. The role provided can be either a role name or a L +object. This tests both the class and its parents. =item B<< $metaclass->excludes_role($role_name) >>