add_method() stores code references instead of a true value
[gitmo/Mouse.git] / lib / Mouse / Meta / Module.pm
index 1c18447..a4ddb38 100755 (executable)
@@ -1,13 +1,9 @@
 package Mouse::Meta::Module;
-use strict;
-use warnings;
+use Mouse::Util qw/:meta get_code_package load_class not_supported/; # enables strict and warnings
 
 use Carp ();
 use Scalar::Util qw/blessed weaken/;
 
-use Mouse::Util qw/:meta get_code_package not_supported load_class/;
-
-
 my %METAS;
 
 sub _metaclass_cache { # DEPRECATED
@@ -88,10 +84,10 @@ sub add_method {
     }
 
     if(ref($code) ne 'CODE'){
-        not_supported 'add_method for a method object';
+        $code = \&{$code}; # coerce
     }
 
-    $self->{methods}->{$name}++; # Moose stores meta object here.
+    $self->{methods}->{$name} = $code; # Moose stores meta object here.
 
     my $pkg = $self->name;
     no strict 'refs';
@@ -115,6 +111,9 @@ sub _code_is_mine{
 sub has_method {
     my($self, $method_name) = @_;
 
+    defined($method_name)
+        or $self->throw_error('You must define a method name');
+
     return 1 if $self->{methods}->{$method_name};
 
     my $code = do{ no strict 'refs'; *{$self->{package} . '::' . $method_name}{CODE} };