Add required_method_metaclass attribute
[gitmo/Moose.git] / lib / Moose / Meta / Role.pm
index 5750156..7c69995 100644 (file)
@@ -7,8 +7,10 @@ use metaclass;
 
 use Scalar::Util 'blessed';
 use Carp         'confess';
+use Sub::Name    'subname';
+use Devel::GlobalDestruction 'in_global_destruction';
 
-our $VERSION   = '0.76';
+our $VERSION   = '0.79';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -123,6 +125,12 @@ $META->add_attribute(
     default => 'Moose::Meta::Role::Method',
 );
 
+$META->add_attribute(
+    'required_method_metaclass',
+    reader  => 'required_method_metaclass',
+    default => 'Moose::Meta::Role::Method::Required',
+);
+
 ## some things don't always fit, so they go here ...
 
 sub add_attribute {
@@ -399,7 +407,7 @@ sub add_method {
     my $full_method_name = ($self->name . '::' . $method_name);
     $self->add_package_symbol(
         { sigil => '&', type => 'CODE', name => $method_name },
-        Class::MOP::subname($full_method_name => $body)
+        subname($full_method_name => $body)
     );
 
     $self->update_package_cache_flag; # still valid, since we just added the method to the map, and if it was invalid before that then get_method_map updated it
@@ -452,10 +460,14 @@ sub combine {
 
     my (@roles, %role_params);
     while (@role_specs) {
-        my ($role, $params) = @{ splice @role_specs, 0, 1 };
-        push @roles => Class::MOP::class_of($role);
+        my ($role_name, $params) = @{ splice @role_specs, 0, 1 };
+        my $requested_role = Class::MOP::class_of($role_name);
+
+        my $actual_role = $requested_role->_role_for_combination($params);
+        push @roles => $actual_role;
+
         next unless defined $params;
-        $role_params{$role} = $params;
+        $role_params{$actual_role->name} = $params;
     }
 
     my $c = Moose::Meta::Role::Composite->new(roles => \@roles);
@@ -466,6 +478,11 @@ sub combine {
     return $c;
 }
 
+sub _role_for_combination {
+    my ($self, $params) = @_;
+    return $self;
+}
+
 sub create {
     my ( $role, $package_name, %options ) = @_;
 
@@ -554,7 +571,7 @@ sub create {
     sub DESTROY {
         my $self = shift;
 
-        return if Class::MOP::in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
+        return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
 
         no warnings 'uninitialized';
         return unless $self->name =~ /^$ANON_ROLE_PREFIX/;
@@ -887,13 +904,13 @@ Returns the list of methods required by the role.
 
 Returns true if the role requires the named method.
 
-=item B<< $metarole->add_required_methods(@names >>
+=item B<< $metarole->add_required_methods(@names) >>
 
-Adds the named methods to the roles list of required methods.
+Adds the named methods to the role's list of required methods.
 
 =item B<< $metarole->remove_required_methods(@names) >>
 
-Removes the named methods to the roles list of required methods.
+Removes the named methods to the role's list of required methods.
 
 =back