bump version to 0.56 and update changes for release
[gitmo/Moose.git] / lib / Moose / Meta / Role.pm
index 9625ee3..4ff959d 100644 (file)
@@ -9,6 +9,7 @@ use Carp         'confess';
 use Scalar::Util 'blessed';
 
 our $VERSION   = '0.56';
+$VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use Moose::Meta::Class;
@@ -240,6 +241,14 @@ sub get_method_modifier_list {
     keys %{$self->$accessor};
 }
 
+sub reset_package_cache_flag  { (shift)->{'_package_cache_flag'} = undef }
+sub update_package_cache_flag {
+    my $self = shift;
+    $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name);
+}
+
+
+
 ## ------------------------------------------------------------------
 ## subroles
 
@@ -253,6 +262,7 @@ sub add_role {
     (blessed($role) && $role->isa('Moose::Meta::Role'))
         || confess "Roles must be instances of Moose::Meta::Role";
     push @{$self->get_roles} => $role;
+    $self->reset_package_cache_flag;
 }
 
 sub calculate_all_roles {
@@ -359,10 +369,24 @@ sub has_method {
 
 # FIXME this is copypasated from Class::MOP::Class
 # refactor to inherit from some common base
+sub wrap_method_body {
+    my ( $self, %args ) = @_;
+
+    my $body = delete $args{body}; # delete is for compat
+
+    ('CODE' eq ref($body))
+        || confess "Your code block must be a CODE reference";
+
+    $self->method_metaclass->wrap( $body => (
+        package_name => $self->name,
+        %args,
+    ));
+}
+
 sub add_method {
     my ($self, $method_name, $method) = @_;
     (defined $method_name && $method_name)
-        || confess "You must define a method name";
+    || confess "You must define a method name";
 
     my $body;
     if (blessed($method)) {
@@ -370,8 +394,8 @@ sub add_method {
         if ($method->package_name ne $self->name &&
             $method->name         ne $method_name) {
             warn "Hello there, got something for you."
-                . " Method says " . $method->package_name . " " . $method->name
-                . " Class says " . $self->name . " " . $method_name;
+            . " Method says " . $method->package_name . " " . $method->name
+            . " Class says " . $self->name . " " . $method_name;
             $method = $method->clone(
                 package_name => $self->name,
                 name         => $method_name
@@ -380,15 +404,11 @@ sub add_method {
     }
     else {
         $body = $method;
-        ('CODE' eq ref($body))
-            || confess "Your code block must be a CODE reference";
-        $method = $self->method_metaclass->wrap(
-            $body => (
-                package_name => $self->name,
-                name         => $method_name
-            )
-        );
+        $method = $self->wrap_method_body( body => $body, name => $method_name );
     }
+
+    $method->attach_to_class($self);
+
     $self->get_method_map->{$method_name} = $method;
 
     my $full_method_name = ($self->name . '::' . $method_name);
@@ -396,7 +416,8 @@ sub add_method {
         { sigil => '&', type => 'CODE', name => $method_name },
         Class::MOP::subname($full_method_name => $body)
     );
-    $self->update_package_cache_flag;
+
+    $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
 }
 
 sub find_method_by_name { (shift)->get_method(@_) }
@@ -445,16 +466,6 @@ sub apply {
     }  
 }
 
-sub apply_to_metaclass_instance {
-    my ($self, $meta, @args) = @_;
-
-    $meta->isa('Moose::Meta::Class') || $meta->isa('Moose::Meta::Role')
-        || confess "You must pass in a Moose::Meta::Class or Moose::Meta::Role instance";
-
-    require Moose::Meta::Role::Application::ToMetaclassInstance;
-    return Moose::Meta::Role::Application::ToMetaclassInstance->new(@args)->apply($self, $meta);
-}
-
 sub combine {
     my ($class, @role_specs) = @_;
     
@@ -677,6 +688,8 @@ probably not that much really).
 
 =item B<add_method>
 
+=item B<wrap_method_body>
+
 =item B<alias_method>
 
 =item B<get_method_list>