X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FApplication%2FRoleSummation.pm;h=9d8264195b0701211c3f64bb4200ecd2efb0b8f0;hb=aead17e74252e3884f9f8e39912ca98fdf4b4dd5;hp=c298bf3a4df6fa8a66c4a4064006321d3ac29cfe;hpb=ab76842ea6760e3e08b2455b63aa55888b70deec;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index c298bf3..9d82641 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -4,13 +4,12 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; -use Data::Dumper; use Moose::Meta::Role::Composite; -our $VERSION = '0.01'; +our $VERSION = '0.62'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Role::Application'; @@ -66,18 +65,25 @@ my $uniq = sub { my %h; map { $h{$_}++ == 0 ? $_ : () } @_ }; sub check_role_exclusions { my ($self, $c) = @_; - my @all_excluded_roles = $uniq->(map { - $_->get_excluded_roles_list - } @{$c->get_roles}); + my %excluded_roles; + for my $role (@{ $c->get_roles }) { + my $name = $role->name; + + for my $excluded ($role->get_excluded_roles_list) { + push @{ $excluded_roles{$excluded} }, $name; + } + } foreach my $role (@{$c->get_roles}) { - foreach my $excluded (@all_excluded_roles) { - confess "Conflict detected: " . $role->name . " excludes role '" . $excluded . "'" - if $role->does_role($excluded); + foreach my $excluded (keys %excluded_roles) { + next unless $role->does_role($excluded); + + my @excluding = @{ $excluded_roles{$excluded} }; + Moose->throw_error(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded); } } - $c->add_excluded_roles(@all_excluded_roles); + $c->add_excluded_roles(keys %excluded_roles); } sub check_required_methods { @@ -119,8 +125,8 @@ sub apply_attributes { my %seen; foreach my $attr (@all_attributes) { if (exists $seen{$attr->{name}}) { - confess "We have encountered an attribute conflict with '" . $attr->{name} . "'" - . "during composition. This is fatal error and cannot be disambiguated." + Moose->throw_error("We have encountered an attribute conflict with '" . $attr->{name} . "' " + . "during composition. This is fatal error and cannot be disambiguated.") if $seen{$attr->{name}} != $attr->{attr}; } $seen{$attr->{name}} = $attr->{attr}; @@ -171,7 +177,7 @@ sub apply_methods { $method_map{$method->{name}} = $method->{method}; } - $c->alias_method($_ => $method_map{$_}) for keys %method_map; + $c->add_method($_ => $method_map{$_}) for keys %method_map; } sub apply_override_method_modifiers { @@ -189,14 +195,14 @@ sub apply_override_method_modifiers { my %seen; foreach my $override (@all_overrides) { - confess "Role '" . $c->name . "' has encountered an 'override' method conflict " . + Moose->throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " . "during composition (A local method of the same name as been found). This " . - "is fatal error." + "is fatal error." ) if $c->has_method($override->{name}); if (exists $seen{$override->{name}}) { - confess "We have encountered an 'override' method conflict during " . + Moose->throw_error( "We have encountered an 'override' method conflict during " . "composition (Two 'override' methods of the same name encountered). " . - "This is fatal error." + "This is fatal error.") if $seen{$override->{name}} != $override->{method}; } $seen{$override->{name}} = $override->{method};