X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole.pm;h=4c53da3334f97351e6ab912e0df857226840c038;hb=6e64f8097e17ea8b7b950fee35046dfa43a5b4f3;hp=04e6cc1a6d49dba20fd376f84c999bad0613f60c;hpb=c9313657717f78bd96f0325c6aa1c93d0b0d41a5;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index 04e6cc1..4c53da3 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -35,6 +35,13 @@ sub is_anon_role{ 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 +186,8 @@ sub apply { my %args = (@_ == 1) ? %{ $_[0] } : @_; + my $instance; + if($applicant->isa('Mouse::Meta::Class')){ # Application::ToClass $args{_to} = 'class'; } @@ -187,14 +196,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 +231,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 +321,10 @@ __END__ Mouse::Meta::Role - The Mouse Role metaclass +=head1 VERSION + +This document describes Mouse version 0.40 + =head1 SEE ALSO L