From: gfx Date: Sat, 16 Jan 2010 05:35:01 +0000 (+0900) Subject: Use Mouse::Object::BUILDARGS, because it's safe and flexible. X-Git-Tag: 0.48~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2053291d1c9bd8c8008259f872fbce78f97d040c;p=gitmo%2FMouse.git Use Mouse::Object::BUILDARGS, because it's safe and flexible. --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index c4068e1..d376101 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -10,23 +10,22 @@ sub new { my $class = shift; my $name = shift; - my %args = (@_ == 1) ? %{ $_[0] } : @_; - + my $args = $class->Mouse::Object::BUILDARGS(@_); # XXX: for backward compatibility (with method modifiers) if($class->can('canonicalize_args') != \&canonicalize_args){ - %args = $class->canonicalize_args($name, %args); + %{$args} = $class->canonicalize_args($name, %{$args}); } - $class->_process_options($name, \%args); + $class->_process_options($name, $args); - $args{name} = $name; + $args->{name} = $name; - my $self = bless \%args, $class; + my $self = bless $args, $class; # extra attributes if($class ne __PACKAGE__){ - $class->meta->_initialize_object($self, \%args); + $class->meta->_initialize_object($self, $args); } # XXX: there is no fast way to check attribute validity @@ -136,18 +135,19 @@ sub _throw_type_constraint_error { } sub clone_and_inherit_options{ - my($self, %args) = @_; + my $self = shift; + my $args = $self->Mouse::Object::BUILDARGS(@_); - my($attribute_class, @traits) = ref($self)->interpolate_class(\%args); + my($attribute_class, @traits) = ref($self)->interpolate_class($args); - $args{traits} = \@traits if @traits; + $args->{traits} = \@traits if @traits; # do not inherit the 'handles' attribute foreach my $name(keys %{$self}){ - if(!exists $args{$name} && $name ne 'handles'){ - $args{$name} = $self->{$name}; + if(!exists $args->{$name} && $name ne 'handles'){ + $args->{$name} = $self->{$name}; } } - return $attribute_class->new($self->name, %args); + return $attribute_class->new($self->name, $args); } sub clone_parent { # DEPRECATED diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index a37a963..d95e4be 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -207,13 +207,13 @@ sub new_object; sub clone_object { my $class = shift; my $object = shift; - my %params = (@_ == 1) ? %{$_[0]} : @_; + my $args = $object->Mouse::Object::BUILDARGS(@_); (blessed($object) && $object->isa($class->name)) || $class->throw_error("You must pass an instance of the metaclass (" . $class->name . "), not ($object)"); my $cloned = bless { %$object }, ref $object; - $class->_initialize_object($cloned, \%params); + $class->_initialize_object($cloned, $args); return $cloned; } diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index 38b88a5..18745d5 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -50,7 +50,9 @@ sub has_override_method_modifier{ } sub add_attribute{ - my($self, $attr_name, $spec) = @_; + my $self = shift; + my $attr_name = shift; + my $spec = (@_ == 1 ? $_[0] : {@_}); my $existing = $self->{attributes}{$attr_name}; if($existing && $existing != $spec){