X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole.pm;h=5c42f147de607a1489942b8b3d06b26726ddd792;hb=30518636145442894e3a55a06ef3a57db268c76d;hp=04e6cc1a6d49dba20fd376f84c999bad0613f60c;hpb=c9313657717f78bd96f0325c6aa1c93d0b0d41a5;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index 04e6cc1..5c42f14 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -29,11 +29,16 @@ sub create_anon_role{ return $self->create(undef, @_); } -sub is_anon_role{ - return exists $_[0]->{anon_serial_id}; -} +sub is_anon_role; + +sub get_roles; -sub get_roles { $_[0]->{roles} } +sub calculate_all_roles { + my $self = shift; + my %seen; + return grep { !$seen{ $_->name }++ } + ($self, map { $_->calculate_all_roles } @{ $self->get_roles }); +} sub get_required_method_list{ return @{ $_[0]->{required_methods} }; @@ -179,6 +184,8 @@ sub apply { my %args = (@_ == 1) ? %{ $_[0] } : @_; + my $instance; + if($applicant->isa('Mouse::Meta::Class')){ # Application::ToClass $args{_to} = 'class'; } @@ -187,14 +194,12 @@ sub apply { } else{ # Appplication::ToInstance $args{_to} = 'instance'; + $instance = $applicant; - my $metaclass = $applicant->meta->create_anon_class( - superclasses => [ref $applicant], + $applicant = (Mouse::Util::class_of($instance) || 'Mouse::Meta::Class')->create_anon_class( + superclasses => [ref $instance], cache => 1, ); - bless $applicant, $metaclass->name; # rebless - - $applicant = $metaclass; } if($args{alias} && !exists $args{-alias}){ @@ -224,6 +229,14 @@ sub apply { $self->_apply_methods($applicant, \%args); $self->_apply_modifiers($applicant, \%args); $self->_append_roles($applicant, \%args); + + + if(defined $instance){ # Application::ToInstance + # rebless instance + bless $instance, $applicant->name; + $applicant->_initialize_object($instance, $instance); + } + return; } @@ -306,6 +319,10 @@ __END__ Mouse::Meta::Role - The Mouse Role metaclass +=head1 VERSION + +This document describes Mouse version 0.40_01 + =head1 SEE ALSO L