Checking in changes prior to tagging of version 0.96. Changelog diff is:
[gitmo/Class-MOP.git] / lib / Class / MOP / Package.pm
index 7589e2e..d7c8fa9 100644 (file)
@@ -8,7 +8,7 @@ use Scalar::Util 'blessed', 'reftype';
 use Carp         'confess';
 use Sub::Name    'subname';
 
-our $VERSION   = '0.93';
+our $VERSION   = '0.96';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -311,7 +311,7 @@ sub wrap_method_body {
 
 sub add_method {
     my ($self, $method_name, $method) = @_;
-    (defined $method_name && $method_name)
+    (defined $method_name && length $method_name)
         || confess "You must define a method name";
 
     my $body;
@@ -320,7 +320,7 @@ sub add_method {
         if ($method->package_name ne $self->name) {
             $method = $method->clone(
                 package_name => $self->name,
-                name         => $method_name            
+                name         => $method_name,
             ) if $method->can('clone');
         }
 
@@ -336,7 +336,7 @@ sub add_method {
 
     my ( $current_package, $current_name ) = Class::MOP::get_code_info($body);
 
-    if ( !defined $current_name || $current_name eq '__ANON__' ) {
+    if ( !defined $current_name || $current_name =~ /^__ANON__/ ) {
         my $full_method_name = ($self->name . '::' . $method_name);
         subname($full_method_name => $body);
     }
@@ -358,7 +358,8 @@ sub _code_is_mine {
 
 sub has_method {
     my ($self, $method_name) = @_;
-    (defined $method_name && $method_name)
+
+    (defined $method_name && length $method_name)
         || confess "You must define a method name";
 
     return defined($self->get_method($method_name));
@@ -366,7 +367,8 @@ sub has_method {
 
 sub get_method {
     my ( $self, $method_name ) = @_;
-    ( defined $method_name && $method_name )
+
+    (defined $method_name && length $method_name)
         || confess "You must define a method name";
 
     my $method_map = $self->_method_map;
@@ -379,10 +381,13 @@ sub get_method {
         }
     );
 
-    return $map_entry if blessed $map_entry && $map_entry->body == $code;
+    # This seems to happen in some weird cases where methods modifiers are
+    # added via roles or some other such bizareness. Honestly, I don't totally
+    # understand this, but returning the entry works, and keeps various MX
+    # modules from blowing up. - DR
+    return $map_entry if blessed $map_entry && !$code;
 
-    # we should never have a blessed map entry but no $code in the package
-    die 'WTF' if blessed $map_entry && ! $code;
+    return $map_entry if blessed $map_entry && $map_entry->body == $code;
 
     unless ($map_entry) {
         return unless $code && $self->_code_is_mine($code);
@@ -399,7 +404,7 @@ sub get_method {
 
 sub remove_method {
     my ($self, $method_name) = @_;
-    (defined $method_name && $method_name)
+    (defined $method_name && length $method_name)
         || confess "You must define a method name";
 
     my $removed_method = delete $self->_full_method_map->{$method_name};