foo
Stevan Little [Mon, 9 Apr 2007 16:35:22 +0000 (16:35 +0000)]
lib/Moose/Meta/Role.pm
t/107_custom_attr_meta_with_roles.t [new file with mode: 0644]

index 3da2d89..c35f7cd 100644 (file)
@@ -9,7 +9,7 @@ use Carp         'confess';
 use Scalar::Util 'blessed';
 use B            'svref_2object';
 
-our $VERSION   = '0.06';
+our $VERSION   = '0.07';
 our $AUTHORITY = 'cpan:STEVAN';
 
 use Moose::Meta::Class;
@@ -367,10 +367,20 @@ sub _apply_attributes {
             }
         }
         else {
-            $other->add_attribute(
-                $attribute_name,
-                $self->get_attribute($attribute_name)
-            );
+            # NOTE:
+            # this is kinda ugly ...
+            if ($other->isa('Moose::Meta::Class')) { 
+                $other->_process_attribute(
+                    $attribute_name,
+                    %{$self->get_attribute($attribute_name)}
+                );             
+            }
+            else {
+                $other->add_attribute(
+                    $attribute_name,
+                    $self->get_attribute($attribute_name)
+                );                
+            }
         }
     }    
 }
diff --git a/t/107_custom_attr_meta_with_roles.t b/t/107_custom_attr_meta_with_roles.t
new file mode 100644 (file)
index 0000000..e22cf9b
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use Test::Exception;
+
+BEGIN {
+    use_ok('Moose');
+}
+
+{
+    package My::Custom::Meta::Attr;
+    use Moose;
+    
+    extends 'Moose::Meta::Attribute';
+}
+
+{
+    package My::Fancy::Role;
+    use Moose::Role;
+    
+    has 'bling_bling' => (
+        metaclass => 'My::Custom::Meta::Attr',
+        is        => 'rw',
+        isa       => 'Str',
+    );
+}
+
+{
+    package My::Class;
+    use Moose;
+    
+    with 'My::Fancy::Role';
+}
+
+my $c = My::Class->new;
+isa_ok($c, 'My::Class');
+
+ok($c->meta->has_attribute('bling_bling'), '... got the attribute');
+
+isa_ok($c->meta->get_attribute('bling_bling'), 'My::Custom::Meta::Attr');
+
+