X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole.pm;h=adabdebc2bf9d1e132565f7662c0ba52539ff525;hb=576cd474fc09bba92843e299a33dd2634629a930;hp=1ff73a3fa516d1d18d5a1d56a868d725342b8640;hpb=f785aad8b8e799322985d8acce2bcb88fadc24a0;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 1ff73a3..adabdeb 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -9,7 +9,7 @@ use Scalar::Util 'blessed'; use Carp 'confess'; use Devel::GlobalDestruction 'in_global_destruction'; -our $VERSION = '0.93'; +our $VERSION = '1.03'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -197,6 +197,9 @@ sub add_attribute { my $class = ref $_[0]; Moose->throw_error( "Cannot add a $class as an attribute to a role" ); } + elsif (!blessed($_[0]) && $_[0] =~ /^\+(.*)/) { + Moose->throw_error( "has '+attr' is not supported in roles" ); + } return $self->SUPER::add_attribute(@_); } @@ -371,9 +374,10 @@ sub calculate_all_roles { } sub does_role { - my ($self, $role_name) = @_; - (defined $role_name) + my ($self, $role) = @_; + (defined $role) || Moose->throw_error("You must supply a role name to look for"); + my $role_name = blessed $role ? $role->name : $role; # if we are it,.. then return true return 1 if $role_name eq $self->name; # otherwise.. check our children @@ -398,7 +402,7 @@ sub alias_method { ## ------------------------------------------------------------------ sub apply { - my ($self, $other, @args) = @_; + my ($self, $other, %args) = @_; (blessed($other)) || Moose->throw_error("You must pass in an blessed instance"); @@ -415,7 +419,7 @@ sub apply { } Class::MOP::load_class($application_class); - return $application_class->new(@args)->apply($self, $other); + return $application_class->new(%args)->apply($self, $other, \%args); } sub composition_class_roles { } @@ -427,8 +431,11 @@ sub combine { my (@roles, %role_params); while (@role_specs) { - my ($role_name, $params) = @{ splice @role_specs, 0, 1 }; - my $requested_role = Class::MOP::class_of($role_name); + my ($role, $params) = @{ splice @role_specs, 0, 1 }; + my $requested_role + = blessed $role + ? $role + : Class::MOP::class_of($role); my $actual_role = $requested_role->_role_for_combination($params); push @roles => $actual_role; @@ -702,7 +709,7 @@ This method creates a new role object with the provided name. =item B<< Moose::Meta::Role->combine( [ $role => { ... } ], [ $role ], ... ) >> This method accepts a list of array references. Each array reference -should contain a role name as its first element. The second element is +should contain a role name or L object as its first element. The second element is an optional hash reference. The hash reference can contain C<-excludes> and C<-alias> keys to control how methods are composed from the role. @@ -766,10 +773,10 @@ list may include duplicates. This returns a I list of all roles that this role does, and all the roles that its roles do. -=item B<< $metarole->does_role($role_name) >> +=item B<< $metarole->does_role($role) >> -Given a role I, returns true if this role does the given -role. +Given a role I or L object, returns true if this role +does the given role. =item B<< $metarole->add_role($role) >> @@ -875,7 +882,7 @@ object, then add it to the required method list. =head2 Method modifiers -These methods act like their counterparts in L and +These methods act like their counterparts in L and L. However, method modifiers are simply stored internally, and are not @@ -932,9 +939,7 @@ This will return a L instance for this class. =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. +See L for details on reporting bugs. =head1 AUTHOR @@ -942,7 +947,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2009 by Infinity Interactive, Inc. +Copyright 2006-2010 by Infinity Interactive, Inc. L