X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FApplication%2FRoleSummation.pm;h=a8254fef0f790c78258ccb0b96299359a49accbb;hb=85f8617c231a822a3ffe26fdcc90903437046d93;hp=c443e3df41e6ff06c7272584645b2f7d946155e8;hpb=88cfb4cb41715de3ac007f658c8063f92f847be9;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index c443e3d..a8254fe 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -5,10 +5,11 @@ use warnings; use metaclass; use Scalar::Util 'blessed'; +use List::MoreUtils qw(uniq); use Moose::Meta::Role::Composite; -our $VERSION = '0.61'; +our $VERSION = '0.78'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -37,7 +38,7 @@ sub get_method_aliases_for_role { if ($self->role_params->{$role} && defined $self->role_params->{$role}->{alias}) { return $self->role_params->{$role}->{alias}; } - return {}; + return {}; } sub is_method_excluded { @@ -55,13 +56,10 @@ sub is_method_aliased { sub is_aliased_method { my ($self, $role, $method_name) = @_; - my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)}; + my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)}; exists $aliased_names{$method_name} ? 1 : 0; } -# stolen from List::MoreUtils ... -my $uniq = sub { my %h; map { $h{$_}++ == 0 ? $_ : () } @_ }; - sub check_role_exclusions { my ($self, $c) = @_; @@ -79,7 +77,9 @@ sub check_role_exclusions { 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); + + require Moose; + Moose->throw_error(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded); } } @@ -89,13 +89,13 @@ sub check_role_exclusions { sub check_required_methods { my ($self, $c) = @_; - my %all_required_methods = map { $_ => undef } $uniq->(map { + my %all_required_methods = map { $_ => undef } uniq(map { $_->get_required_method_list } @{$c->get_roles}); foreach my $role (@{$c->get_roles}) { foreach my $required (keys %all_required_methods) { - + delete $all_required_methods{$required} if $role->has_method($required) || $self->is_aliased_method($role, $required); @@ -106,63 +106,65 @@ sub check_required_methods { } sub check_required_attributes { - + } sub apply_attributes { my ($self, $c) = @_; - + my @all_attributes = map { my $role = $_; - map { - +{ + map { + +{ name => $_, attr => $role->get_attribute($_), } } $role->get_attribute_list } @{$c->get_roles}; - + my %seen; foreach my $attr (@all_attributes) { if (exists $seen{$attr->{name}}) { - 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}; + if ( $seen{$attr->{name}} != $attr->{attr} ) { + require Moose; + Moose->throw_error("We have encountered an attribute conflict with '" . $attr->{name} . "' " + . "during composition. This is fatal error and cannot be disambiguated.") + } } $seen{$attr->{name}} = $attr->{attr}; } - foreach my $attr (@all_attributes) { + foreach my $attr (@all_attributes) { $c->add_attribute($attr->{name}, $attr->{attr}); } } sub apply_methods { my ($self, $c) = @_; - + my @all_methods = map { my $role = $_; my $aliases = $self->get_method_aliases_for_role($role); my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) }; ( - (map { + (map { exists $excludes{$_} ? () : - +{ + +{ role => $role, name => $_, method => $role->get_method($_), } } $role->get_method_list), - (map { - +{ + (map { + +{ role => $role, name => $aliases->{$_}, method => $role->get_method($_), - } + } } keys %$aliases) ); } @{$c->get_roles}; - + my (%seen, %method_map); foreach my $method (@all_methods) { if (exists $seen{$method->{name}}) { @@ -170,9 +172,9 @@ sub apply_methods { $c->add_required_methods($method->{name}); delete $method_map{$method->{name}}; next; - } - } - + } + } + $seen{$method->{name}} = $method->{method}; $method_map{$method->{name}} = $method->{method}; } @@ -182,36 +184,40 @@ sub apply_methods { sub apply_override_method_modifiers { my ($self, $c) = @_; - + my @all_overrides = map { my $role = $_; - map { - +{ + map { + +{ name => $_, method => $role->get_override_method_modifier($_), } } $role->get_method_modifier_list('override'); } @{$c->get_roles}; - + my %seen; foreach my $override (@all_overrides) { - 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." ) - if $c->has_method($override->{name}); + if ( $c->has_method($override->{name}) ){ + require Moose; + 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." ) + } if (exists $seen{$override->{name}}) { - Moose->throw_error( "We have encountered an 'override' method conflict during " . - "composition (Two 'override' methods of the same name encountered). " . - "This is fatal error.") - if $seen{$override->{name}} != $override->{method}; + if ( $seen{$override->{name}} != $override->{method} ) { + require Moose; + Moose->throw_error( "We have encountered an 'override' method conflict during " . + "composition (Two 'override' methods of the same name encountered). " . + "This is fatal error.") + } } $seen{$override->{name}} = $override->{method}; } - + $c->add_override_method_modifier( $_->{name}, $_->{method} ) for @all_overrides; - + } sub apply_method_modifiers { @@ -240,7 +246,7 @@ Moose::Meta::Role::Application::RoleSummation - Combine two or more roles =head1 DESCRIPTION -Summation composes two traits, forming the union of non-conflicting +Summation composes two traits, forming the union of non-conflicting bindings and 'disabling' the conflicting bindings =head2 METHODS @@ -293,7 +299,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2008 by Infinity Interactive, Inc. +Copyright 2006-2009 by Infinity Interactive, Inc. L