Checking in changes prior to tagging of version 0.38. Changelog diff is:
[gitmo/Mouse.git] / lib / Mouse / Meta / Role.pm
index 3e3a724..ea4b1fa 100644 (file)
@@ -56,6 +56,7 @@ sub add_attribute {
     my $name = shift;
 
     $self->{attributes}->{$name} = (@_ == 1) ? $_[0] : { @_ };
+    return;
 }
 
 sub _check_required_methods{
@@ -178,6 +179,8 @@ sub apply {
 
     my %args = (@_ == 1) ? %{ $_[0] } : @_;
 
+    my $instance;
+
     if($applicant->isa('Mouse::Meta::Class')){  # Application::ToClass
         $args{_to} = 'class';
     }
@@ -186,14 +189,12 @@ sub apply {
     }
     else{                                       # Appplication::ToInstance
         $args{_to} = 'instance';
+        $instance = $applicant;
 
-        my $metaclass = $applicant->meta->create_anon_class(
-            superclasses => [ref $applicant],
+        $applicant = (Mouse::Util::class_of($instance) || 'Mouse::Meta::Class')->create_anon_class(
+            superclasses => [ref $instance],
             cache        => 1,
         );
-        bless $applicant, $metaclass->name; # rebless
-
-        $applicant = $metaclass;
     }
 
     if($args{alias} && !exists $args{-alias}){
@@ -223,6 +224,14 @@ sub apply {
     $self->_apply_methods($applicant, \%args);
     $self->_apply_modifiers($applicant, \%args);
     $self->_append_roles($applicant, \%args);
+
+
+    if(defined $instance){ # Application::ToInstance
+        # rebless instance
+        bless $instance, $applicant->name;
+        $applicant->_initialize_object($instance, $instance);
+    }
+
     return;
 }
 
@@ -244,17 +253,14 @@ sub combine {
 for my $modifier_type (qw/before after around/) {
 
     my $modifier = "${modifier_type}_method_modifiers";
+
     my $add_method_modifier =  sub {
         my ($self, $method_name, $method) = @_;
 
         push @{ $self->{$modifier}->{$method_name} ||= [] }, $method;
         return;
     };
-    my $has_method_modifiers = sub{
-        my($self, $method_name) = @_;
-        my $m = $self->{$modifier}->{$method_name};
-        return $m && @{$m} != 0;
-    };
+
     my $get_method_modifiers = sub {
         my ($self, $method_name) = @_;
         return @{ $self->{$modifier}->{$method_name} ||= [] }
@@ -262,8 +268,9 @@ for my $modifier_type (qw/before after around/) {
 
     no strict 'refs';
     *{ 'add_' . $modifier_type . '_method_modifier'  } = $add_method_modifier;
-    *{ 'has_' . $modifier_type . '_method_modifiers' } = $has_method_modifiers;
     *{ 'get_' . $modifier_type . '_method_modifiers' } = $get_method_modifiers;
+
+    # has_${modifier_type}_method_modifiers is moved into t::lib::Test::Mouse
 }
 
 sub add_override_method_modifier{
@@ -280,23 +287,11 @@ sub add_override_method_modifier{
     $self->{override_method_modifiers}->{$method_name} = $method;
 }
 
-sub has_override_method_modifier {
-    my ($self, $method_name) = @_;
-    return exists $self->{override_method_modifiers}->{$method_name};
-}
-
 sub get_override_method_modifier {
     my ($self, $method_name) = @_;
     return $self->{override_method_modifiers}->{$method_name};
 }
 
-sub get_method_modifier_list {
-    my($self, $modifier_type) = @_;
-
-    return keys %{ $self->{$modifier_type . '_method_modifiers'} };
-}
-
-# This is currently not passing all the Moose tests.
 sub does_role {
     my ($self, $role_name) = @_;
 
@@ -312,15 +307,17 @@ sub does_role {
     return 0;
 }
 
-
 1;
-
 __END__
 
 =head1 NAME
 
 Mouse::Meta::Role - The Mouse Role metaclass
 
+=head1 VERSION
+
+This document describes Mouse version 0.38
+
 =head1 SEE ALSO
 
 L<Moose::Meta::Role>