Add ability to use an arrayref with has() to create multiple attributes with the...
Scott McWhirter [Thu, 5 Apr 2007 21:40:37 +0000 (21:40 +0000)]
lib/Moose.pm
t/071_misc_attribute_tests.t

index 22ee850..23f8b5b 100644 (file)
@@ -92,8 +92,9 @@ use Moose::Util::TypeConstraints;
         has => sub {
             my $class = $CALLER;
             return subname 'Moose::has' => sub ($;%) {
-                my ($name, %options) = @_;              
-                $class->meta->_process_attribute($name, %options);
+                my ($name, %options) = @_;
+                my $attrs = (ref($name) eq 'ARRAY') ? $name : [($name)];
+                $class->meta->_process_attribute($_, %options) for @$attrs;
             };
         },
         before => sub {
index 3849d64..bdab707 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 8;
 use Test::Exception;
 
 BEGIN {
@@ -67,3 +67,20 @@ BEGIN {
         $test->good_lazy_attr;
     } '... this does not work';    
 }
+
+{
+    {
+        package Test::Arrayref::Attributes;
+        use Moose;
+
+        has [qw(foo bar baz)] => (
+            is => 'rw',
+        );
+        
+    }
+
+    my $test = Test::Arrayref::Attributes->new;
+    isa_ok($test, 'Test::Arrayref::Attributes');
+    can_ok($test, qw(foo bar baz));
+    
+}