X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole%2FComposite.pm;h=c019f40c5e082ca719470f191c61aa2682f3f8d8;hb=983d58a5ea543a21c48cb04311883f1b36de1874;hp=d7e004a0f5b8461b7bb56ed4fab068a5aa9f6d7e;hpb=823419c540f9e77090f31f11e04b14477c0372c4;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index d7e004a..c019f40 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -4,6 +4,25 @@ use Mouse::Meta::Role; use Mouse::Meta::Role::Application; our @ISA = qw(Mouse::Meta::Role); +# FIXME: Mouse::Meta::Role::Composite does things in different way from Moose's +# Moose: creates a new class for the consumer, and applies roles to it. +# Mouse: creates a coposite role and apply roles to the role, +# and then applies it to the consumer. + +sub new { + my $class = shift; + my $args = $class->Mouse::Object::BUILDARGS(@_); + my $roles = delete $args->{roles}; + my $self = $class->create_anon_role(%{$args}); + foreach my $role_spec(@{$roles}) { + my($role, $args) = ref($role_spec) eq 'ARRAY' + ? @{$role_spec} + : ($role_spec, {}); + $role->apply($self, %{$args}); + } + return $self; +} + sub get_method_list { my($self) = @_; return keys %{ $self->{methods} }; @@ -96,32 +115,30 @@ sub apply_methods { if(exists $role->{conflicting_methods}){ my $consumer_class_name = $consumer->name; - my @conflicting = grep{ !$consumer_class_name->can($_) } + my @conflicting = grep{ !$consumer_class_name->can($_) } keys %{ $role->{conflicting_methods} }; - if(@conflicting == 1){ - my $method_name = $conflicting[0]; - my $roles = Mouse::Util::quoted_english_list( map{ $_->name } - @{ $role->{composed_roles_by_method}{$method_name} }); - $self->throw_error( - sprintf q{Due to a method name conflict in roles %s, the method '%s' must be implemented or excluded by '%s'}, - $roles, $method_name, $consumer_class_name - ); - } - elsif(@conflicting > 1){ + if(@conflicting) { + my $method_name_conflict = (@conflicting == 1 + ? 'a method name conflict' + : 'method name conflicts'); + my %seen; my $roles = Mouse::Util::quoted_english_list( grep{ !$seen{$_}++ } # uniq map { $_->name } - map { @{$_} } @{ $role->{composed_roles_by_method} }{@conflicting} + map { @{$_} } + @{ $role->{composed_roles_by_method} }{@conflicting} ); - $self->throw_error( - sprintf q{Due to method name conflicts in roles %s, the methods %s must be implemented or excluded by '%s'}, - $roles, - Mouse::Util::quoted_english_list(@conflicting), - $consumer_class_name - ); + $self->throw_error(sprintf + q{Due to %s in roles %s,} + . q{ the method%s %s must be implemented or excluded by '%s'}, + $method_name_conflict, + $roles, + (@conflicting > 1 ? 's' : ''), + Mouse::Util::quoted_english_list(@conflicting), + $consumer_class_name); } } @@ -139,7 +156,7 @@ Mouse::Meta::Role::Composite - An object to represent the set of roles =head1 VERSION -This document describes Mouse version 0.70 +This document describes Mouse version 0.94 =head1 SEE ALSO