use Moose::Meta::Role::Composite;
-our $VERSION = '0.80';
+our $VERSION = '0.99';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
sub get_exclusions_for_role {
my ($self, $role) = @_;
$role = $role->name if blessed $role;
- if ($self->role_params->{$role} && defined $self->role_params->{$role}->{excludes}) {
- if (ref $self->role_params->{$role}->{excludes} eq 'ARRAY') {
- return $self->role_params->{$role}->{excludes};
+ my $excludes_key = exists $self->role_params->{$role}->{'-excludes'} ?
+ '-excludes' : 'excludes';
+ if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$excludes_key}) {
+ if (ref $self->role_params->{$role}->{$excludes_key} eq 'ARRAY') {
+ return $self->role_params->{$role}->{$excludes_key};
}
- return [ $self->role_params->{$role}->{excludes} ];
+ return [ $self->role_params->{$role}->{$excludes_key} ];
}
return [];
}
sub get_method_aliases_for_role {
my ($self, $role) = @_;
$role = $role->name if blessed $role;
- if ($self->role_params->{$role} && defined $self->role_params->{$role}->{alias}) {
- return $self->role_params->{$role}->{alias};
+ my $alias_key = exists $self->role_params->{$role}->{'-alias'} ?
+ '-alias' : 'alias';
+ if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$alias_key}) {
+ return $self->role_params->{$role}->{$alias_key};
}
return {};
}
sub apply_attributes {
my ($self, $c) = @_;
- my @all_attributes = map {
- my $role = $_;
- map {
- +{
- name => $_,
- attr => $role->get_attribute($_),
- }
- } $role->get_attribute_list
- } @{$c->get_roles};
+ my @all_attributes;
+
+ for my $role ( @{ $c->get_roles } ) {
+ push @all_attributes,
+ map { $role->get_attribute($_) } $role->get_attribute_list;
+ }
my %seen;
foreach my $attr (@all_attributes) {
- if (exists $seen{$attr->{name}}) {
- 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.")
- }
+ my $name = $attr->name;
+
+ if ( exists $seen{$name} ) {
+ next if $seen{$name}->is_same_as($attr);
+
+ my $role1 = $seen{$name}->associated_role->name;
+ my $role2 = $attr->associated_role->name;
+
+ require Moose;
+ Moose->throw_error(
+ "We have encountered an attribute conflict with '$name' "
+ . "during role composition. "
+ . " This attribute is defined in both $role1 and $role2."
+ . " This is fatal error and cannot be disambiguated." );
}
- $seen{$attr->{name}} = $attr->{attr};
+
+ $seen{$name} = $attr;
}
foreach my $attr (@all_attributes) {
- $c->add_attribute($attr->{name}, $attr->{attr});
+ $c->add_attribute( $attr->clone );
}
}
my $role = $_;
my $aliases = $self->get_method_aliases_for_role($role);
my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) };
+ $excludes{meta} = undef;
(
(map {
exists $excludes{$_} ? () :
=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<Moose/BUGS> for details on reporting bugs.
=head1 AUTHOR
=head1 COPYRIGHT AND LICENSE
-Copyright 2006-2009 by Infinity Interactive, Inc.
+Copyright 2006-2010 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>