X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoo.git;a=blobdiff_plain;f=lib%2FMoo.pm;h=fdd46e214ab91c0cabb495fc84b39ec471279faf;hp=35f72b51f4abe1b2b3ccd4175c778ac20ddbee8d;hb=141b507ace5957c098c52ceb7afaf21d5928a02d;hpb=52e8f144aff26f074f1376deb28e4df5839c001f diff --git a/lib/Moo.pm b/lib/Moo.pm index 35f72b5..fdd46e2 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -5,7 +5,7 @@ use Moo::_Utils; use B 'perlstring'; use Sub::Defer (); -our $VERSION = '1.000000'; # 1.0.0 +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. Unlike L this module does not aim at full compatibility with L's surface syntax, preferring instead of provide full interoperability -via the metaclass inflation capabilites described in L. +via the metaclass inflation capabilities described in L. For a full list of the minor differences between L and L's surface -syntax, see L. +syntax, see L. =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) ilmari - Dagfinn Ilmari Mannsåker (cpan:ILMARI) +tobyink - Toby Inkster (cpan:TOBYINK) + =head1 COPYRIGHT Copyright (c) 2010-2011 the Moo L and L