Don't use $_ as loop variable when calling arbitrary code (RT#81072)
[gitmo/Moo.git] / lib / Moo.pm
index e651d39..fdd46e2 100644 (file)
@@ -5,7 +5,7 @@ use Moo::_Utils;
 use B 'perlstring';
 use Sub::Defer ();
 
-our $VERSION = '1.000001'; # 1.0.1
+our $VERSION = '1.000005'; # 1.0.5
 $VERSION = eval $VERSION;
 
 require Moo::sification;
@@ -35,12 +35,18 @@ sub import {
     $class->_maybe_reset_handlemoose($target);
   };
   _install_tracked $target => has => sub {
-    my ($name, %spec) = @_;
-    $class->_constructor_maker_for($target)
-          ->register_attribute_specs($name, \%spec);
-    $class->_accessor_maker_for($target)
-          ->generate_method($target, $name, \%spec);
-    $class->_maybe_reset_handlemoose($target);
+    my ($name_proto, %spec) = @_;
+    my $name_isref = ref $name_proto eq 'ARRAY';
+    foreach my $name ($name_isref ? @$name_proto : $name_proto) {
+      # Note that when $name_proto is an arrayref, each attribute
+      # needs a separate \%specs hashref
+      my $spec_ref = $name_isref ? +{%spec} : \%spec;
+      $class->_constructor_maker_for($target)
+            ->register_attribute_specs($name, $spec_ref);
+      $class->_accessor_maker_for($target)
+            ->generate_method($target, $name, $spec_ref);
+      $class->_maybe_reset_handlemoose($target);
+    }
     return;
   };
   foreach my $type (qw(before after around)) {
@@ -69,11 +75,11 @@ sub unimport {
 sub _set_superclasses {
   my $class = shift;
   my $target = shift;
-  for (@_) {
-    _load_module($_);
-    if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$_}) {
+  foreach my $superclass (@_) {
+    _load_module($superclass);
+    if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$superclass}) {
       require Carp;
-      Carp::croak("Can't extend role '$_'");
+      Carp::croak("Can't extend role '$superclass'");
     }
   }
   # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA
@@ -162,7 +168,7 @@ sub _constructor_maker_for {
           .'        '.$class.'->_constructor_maker_for($class,'.perlstring($target).');'."\n"
           .'        return $class->new(@_)'.";\n"
           .'      } elsif ($INC{"Moose.pm"} and my $meta = Class::MOP::get_metaclass_by_name($class)) {'."\n"
-          .'        return $meta->new_object(@_);'."\n"
+          .'        return $meta->new_object($class->BUILDARGS(@_));'."\n"
           .'      }'."\n"
         ),
       )
@@ -234,10 +240,10 @@ thirds of L<Moose>.
 
 Unlike L<Mouse> this module does not aim at full compatibility with
 L<Moose>'s surface syntax, preferring instead of provide full interoperability
-via the metaclass inflation capabilites described in L</MOO AND MOOSE>.
+via the metaclass inflation capabilities described in L</MOO AND MOOSE>.
 
 For a full list of the minor differences between L<Moose> and L<Moo>'s surface
-syntax, see L</INCOMPATIBILITIES>.
+syntax, see L</INCOMPATIBILITIES WITH MOOSE>.
 
 =head1 WHY MOO EXISTS
 
@@ -629,7 +635,8 @@ To do this, you can write
   use Sub::Quote;
 
   has foo => (
-    is => quote_sub(q{ die "Not <3" unless $_[0] < 3 })
+    is => 'ro',
+    isa => quote_sub(q{ die "Not <3" unless $_[0] < 3 })
   );
 
 which will be inlined as
@@ -642,7 +649,8 @@ which will be inlined as
 or to avoid localizing @_,
 
   has foo => (
-    is => quote_sub(q{ my ($val) = @_; die "Not <3" unless $val < 3 })
+    is => 'ro',
+    isa => quote_sub(q{ my ($val) = @_; die "Not <3" unless $val < 3 })
   );
 
 which will be inlined as
@@ -788,6 +796,8 @@ Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>
 
 ilmari - Dagfinn Ilmari MannsÃ¥ker (cpan:ILMARI) <ilmari@ilmari.org>
 
+tobyink - Toby Inkster (cpan:TOBYINK) <tobyink@cpan.org>
+
 =head1 COPYRIGHT
 
 Copyright (c) 2010-2011 the Moo L</AUTHOR> and L</CONTRIBUTORS>