From: Yuval Kogman Date: Fri, 8 Aug 2008 22:19:14 +0000 (+0000) Subject: accept fully named args in Class::MOP::Attribute::new X-Git-Tag: 0_64_01~76 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=649efb63b1e112b1f7f126d269d325ed70434525;p=gitmo%2FClass-MOP.git accept fully named args in Class::MOP::Attribute::new --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index bd51287..33ad8ce 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -509,9 +509,12 @@ Class::MOP::Attribute->meta->add_attribute( # so that it uses the attributes meta-objects # to construct itself. Class::MOP::Attribute->meta->add_method('new' => sub { - my $class = shift; - my $name = shift; - my %options = @_; + my ( $class, @args ) = @_; + + unshift @args, "name" if @args % 2 == 1; + my %options = @args; + + my $name = $options{name}; (defined $name && $name) || confess "You must provide a name for the attribute"; @@ -531,7 +534,7 @@ Class::MOP::Attribute->meta->add_method('new' => sub { } # return the new object - $class->meta->new_object(name => $name, %options); + $class->meta->new_object(%options); }); Class::MOP::Attribute->meta->add_method('clone' => sub { diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 697fb3a..4be906d 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -24,9 +24,12 @@ use base 'Class::MOP::Object'; # meta-objects. # - Ain't meta-circularity grand? :) sub new { - my $class = shift; - my $name = shift; - my %options = @_; + my ( $class, @args ) = @_; + + unshift @args, "name" if @args % 2 == 1; + my %options = @args; + + my $name = $options{name}; (defined $name && $name) || confess "You must provide a name for the attribute";