bump version to 0.84
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application / ToClass.pm
index c8c443c..2a9ce8b 100644 (file)
@@ -5,9 +5,9 @@ use warnings;
 use metaclass;
 
 use Moose::Util  'english_list';
-use Scalar::Util 'blessed';
+use Scalar::Util 'weaken', 'blessed';
 
-our $VERSION   = '0.77';
+our $VERSION   = '0.84';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -15,19 +15,18 @@ use base 'Moose::Meta::Role::Application';
 
 __PACKAGE__->meta->add_attribute('role' => (
     reader => 'role',
-    writer => 'set_role',
 ));
 
 __PACKAGE__->meta->add_attribute('class' => (
     reader => 'class',
-    writer => 'set_class',
 ));
 
 sub apply {
     my ($self, $role, $class) = @_;
 
-    $self->set_role($role);
-    $self->set_class($class);
+    # We need weak_ref in CMOP :(
+    weaken($self->{role}  = $role);
+    weaken($self->{class} = $class);
 
     $self->SUPER::apply($role, $class);
 
@@ -59,13 +58,14 @@ sub check_required_methods {
     # attribute accessors. However I am thinking
     # that maybe those are somehow exempt from
     # the require methods stuff.
-    foreach my $required_method_name ($role->get_required_method_list) {
+    foreach my $required_method ($role->get_required_method_list) {
+        my $required_method_name = $required_method->name;
 
         if (!$class->find_method_by_name($required_method_name)) {
 
             next if $self->is_aliased_method($required_method_name);
 
-            push @missing, $required_method_name;
+            push @missing, $required_method;
         }
     }
 
@@ -73,7 +73,22 @@ sub check_required_methods {
 
     my $error = '';
 
-    if (@missing) {
+    my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing;
+
+    if (@conflicts) {
+        my $conflict = $conflicts[0];
+        my $roles = Moose::Util::english_list( map { q{'} . $_ . q{'} } @{ $conflict->roles } );
+
+        $error
+            .= "Due to a method name conflict in roles "
+            .  $roles
+            . ", the method '"
+            . $conflict->name
+            . "' must be implemented or excluded by '"
+            . $class->name
+            . q{'};
+    }
+    elsif (@missing) {
         my $noun = @missing == 1 ? 'method' : 'methods';
 
         my $list