Use blessed not ref
[gitmo/Moose.git] / lib / Moose / Meta / Role.pm
index 0fcfc40..19c2a4e 100644 (file)
@@ -10,7 +10,7 @@ use Carp         'confess';
 use Sub::Name    'subname';
 use Devel::GlobalDestruction 'in_global_destruction';
 
-our $VERSION   = '0.77';
+our $VERSION   = '0.79';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -65,7 +65,6 @@ foreach my $action (
         name        => 'required_methods',
         attr_reader => 'get_required_methods_map',
         methods     => {
-            add       => 'add_required_methods',
             remove    => 'remove_required_methods',
             get_list  => 'get_required_method_list',
             existence => 'requires_method',
@@ -125,6 +124,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 {
@@ -144,6 +149,20 @@ sub add_attribute {
     $self->get_attribute_map->{$name} = $attr_desc;
 }
 
+sub add_required_methods {
+    my $self = shift;
+
+    for (@_) {
+        my $method = $_;
+        if (!blessed($method)) {
+            $method = $self->required_method_metaclass->new(
+                name => $method,
+            );
+        }
+        $self->get_required_methods_map->{$method->name} = $method;
+    }
+}
+
 ## ------------------------------------------------------------------
 ## method modifiers
 
@@ -457,7 +476,7 @@ sub combine {
         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);
+        my $actual_role = $requested_role->_role_for_combination($params);
         push @roles => $actual_role;
 
         next unless defined $params;
@@ -472,7 +491,7 @@ sub combine {
     return $c;
 }
 
-sub role_for_combination {
+sub _role_for_combination {
     my ($self, $params) = @_;
     return $self;
 }
@@ -753,12 +772,6 @@ and C<alias> keys to control how methods are composed from the role.
 The return value is a new L<Moose::Meta::Role::Composite> that
 represents the combined roles.
 
-=item B<< Moose::Meta::Role->role_for_combination($options) >>
-
-This is a hook for incorporating role-combination parameters. This
-method returns a role meta-object (by default the invocant role) to be
-used for the combination.
-
 =item B<< Moose::Meta::Role->create($name, %options) >>
 
 This method is identical to the L<Moose::Meta::Class> C<create>
@@ -904,13 +917,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