bump version to 0.56 and update changes for release
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application / RoleSummation.pm
index 408b331..5fdae8b 100644 (file)
@@ -6,15 +6,60 @@ use metaclass;
 
 use Carp            'confess';
 use Scalar::Util    'blessed';
-use Data::Dumper;
 
 use Moose::Meta::Role::Composite;
 
-our $VERSION   = '0.01';
+our $VERSION   = '0.56';
+$VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Moose::Meta::Role::Application';
 
+__PACKAGE__->meta->add_attribute('role_params' => (
+    reader  => 'role_params',
+    default => sub { {} }
+));
+
+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};
+        }
+        return [ $self->role_params->{$role}->{excludes} ];
+    }
+    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};
+    }
+    return {};    
+}
+
+sub is_method_excluded {
+    my ($self, $role, $method_name) = @_;
+    foreach ($self->get_exclusions_for_role($role->name)) {
+        return 1 if $_ eq $method_name;
+    }
+    return 0;
+}
+
+sub is_method_aliased {
+    my ($self, $role, $method_name) = @_;
+    exists $self->get_method_aliases_for_role($role->name)->{$method_name} ? 1 : 0
+}
+
+sub is_aliased_method {
+    my ($self, $role, $method_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 ? $_ : () } @_ };
 
@@ -44,14 +89,20 @@ sub check_required_methods {
 
     foreach my $role (@{$c->get_roles}) {
         foreach my $required (keys %all_required_methods) {
+            
             delete $all_required_methods{$required}
-                if $role->has_method($required);
+                if $role->has_method($required)
+                || $self->is_aliased_method($role, $required);
         }
     }
 
     $c->add_required_methods(keys %all_required_methods);
 }
 
+sub check_required_attributes {
+    
+}
+
 sub apply_attributes {
     my ($self, $c) = @_;
     
@@ -68,7 +119,7 @@ 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} . "'" 
+            confess "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};           
         }
@@ -84,13 +135,26 @@ sub apply_methods {
     my ($self, $c) = @_;
     
     my @all_methods = map {
-        my $role = $_;
-        map { 
-            +{ 
-                name   => $_,
-                method => $role->get_method($_),
-            }
-        } $role->get_method_list;
+        my $role     = $_;
+        my $aliases  = $self->get_method_aliases_for_role($role);
+        my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) };
+        (
+            (map { 
+                exists $excludes{$_} ? () :
+                +{ 
+                    role   => $role,
+                    name   => $_,
+                    method => $role->get_method($_),
+                }
+            } $role->get_method_list),
+            (map { 
+                +{ 
+                    role   => $role,
+                    name   => $aliases->{$_},
+                    method => $role->get_method($_),
+                }            
+            } keys %$aliases)
+        );
     } @{$c->get_roles};
     
     my (%seen, %method_map);
@@ -101,7 +165,8 @@ sub apply_methods {
                 delete $method_map{$method->{name}};
                 next;
             }           
-        }
+        }       
+        
         $seen{$method->{name}}       = $method->{method};
         $method_map{$method->{name}} = $method->{method};
     }
@@ -157,10 +222,6 @@ sub apply_method_modifiers {
     }
 }
 
-sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) }
-sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) }
-sub apply_after_method_modifiers  { (shift)->apply_method_modifiers('after'  => @_) }
-
 1;
 
 __END__
@@ -169,7 +230,7 @@ __END__
 
 =head1 NAME
 
-Moose::Meta::Role::Application::RoleSummation
+Moose::Meta::Role::Application::RoleSummation - Combine two or more roles
 
 =head1 DESCRIPTION
 
@@ -184,11 +245,25 @@ bindings and 'disabling' the conflicting bindings
 
 =item B<meta>
 
+=item B<role_params>
+
+=item B<get_exclusions_for_role>
+
+=item B<get_method_aliases_for_role>
+
+=item B<is_aliased_method>
+
+=item B<is_method_aliased>
+
+=item B<is_method_excluded>
+
 =item B<apply>
 
+=item B<check_role_exclusions>
+
 =item B<check_required_methods>
 
-=item B<check_role_exclusions>
+=item B<check_required_attributes>
 
 =item B<apply_attributes>
 
@@ -196,12 +271,6 @@ bindings and 'disabling' the conflicting bindings
 
 =item B<apply_method_modifiers>
 
-=item B<apply_before_method_modifiers>
-
-=item B<apply_after_method_modifiers>
-
-=item B<apply_around_method_modifiers>
-
 =item B<apply_override_method_modifiers>
 
 =back
@@ -218,7 +287,7 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006, 2007 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>