From: Yuval Kogman Date: Thu, 24 Apr 2008 19:33:52 +0000 (+0000) Subject: more refactoring of _process_attribute X-Git-Tag: 0_55~212 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7e59b8039f4a2bd4fc88fd43c46ccfe70936847a;p=gitmo%2FMoose.git more refactoring of _process_attribute --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index c5730ae..975ee8e 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -310,33 +310,46 @@ sub _apply_all_roles { sub _process_attribute { my ( $self, $name, @args ) = @_; - my %options = ((scalar @args == 1 && ref($args[0]) eq 'HASH') ? %{$args[0]} : @args); + + @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH'; if ($name =~ /^\+(.*)/) { - return $self->_process_inherited_attribute($1, %options); + return $self->_process_inherited_attribute($1, @args); } else { - my $attr_metaclass_name = $options{metaclass} - ? Moose::Util::resolve_metaclass_alias( Attribute => $options{metaclass} ) - : $self->attribute_metaclass; - - if (my $traits = $options{traits}) { - my @traits = map { - Moose::Util::resolve_metatrait_alias( Attribute => $_ ) - or - $_ - } @$traits; - - my $class = Moose::Meta::Class->create_anon_class( - superclasses => [ $attr_metaclass_name ], - roles => [ @traits ], - cache => 1, - ); - - $attr_metaclass_name = $class->name; - } - - return $attr_metaclass_name->new($name, %options); + return $self->_process_new_attribute($name, @args); + } +} + +sub _process_new_attribute { + my ( $self, $name, @args ) = @_; + $self->_resolve_attribute_metaclass(@args)->new($name, @args); +} + +sub _resolve_attribute_metaclass { + my ( $self, %options ) = @_; + + my $attr_metaclass_name = $options{metaclass} + ? Moose::Util::resolve_metaclass_alias( Attribute => $options{metaclass} ) + : $self->attribute_metaclass; + + if (my $traits = $options{traits}) { + my @traits = map { + Moose::Util::resolve_metatrait_alias( Attribute => $_ ) + or + $_ + } @$traits; + + my $class = Moose::Meta::Class->create_anon_class( + superclasses => [ $attr_metaclass_name ], + roles => [ @traits ], + cache => 1, + ); + + return $class->name; + } + else { + return $attr_metaclass_name; } }