Real attribute objects in roles is now working, with a few hacks and changes to the...
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application / ToInstance.pm
index f0ed1a7..a0c85cf 100644 (file)
@@ -4,10 +4,10 @@ use strict;
 use warnings;
 use metaclass;
 
-use Carp         'confess';
 use Scalar::Util 'blessed';
 
-our $VERSION   = '0.02';
+our $VERSION   = '0.93';
+$VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Moose::Meta::Role::Application::ToClass';
@@ -29,7 +29,16 @@ sub apply {
         $class = $ANON_CLASSES{$anon_role_key};
     }
     else {
-        $class = Moose::Meta::Class->create_anon_class(
+        my $obj_meta = Class::MOP::class_of($object) || 'Moose::Meta::Class';
+
+        # This is a special case to handle the case where the object's
+        # metaclass is a Class::MOP::Class, but _not_ a Moose::Meta::Class
+        # (for example, when applying a role to a Moose::Meta::Attribute
+        # object).
+        $obj_meta = 'Moose::Meta::Class'
+            unless $obj_meta->isa('Moose::Meta::Class');
+
+        $class = $obj_meta->create_anon_class(
             superclasses => [ blessed($object) ]
         );
         $ANON_CLASSES{$anon_role_key} = $class;
@@ -77,7 +86,7 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006-2008 by Infinity Interactive, Inc.
+Copyright 2006-2009 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>