From: Chris Prather Date: Sun, 9 Oct 2011 20:12:46 +0000 (-0400) Subject: Rework the `_process_options` stuff from before to use a `_process_clone_options`. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34fda380728b5e31aa7220448e6757f961a7c4df;p=gitmo%2FMoose.git Rework the `_process_options` stuff from before to use a `_process_clone_options`. `_process_clone_options` is called during clone, and is passed the clone options as well as the original options before handing them over to `new` for re-creating the instance. This commit also reverts commit ec46933637117a964d12b7efac5501aa38e96c74. --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index f7b843b..2055094 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -79,7 +79,10 @@ sub _inline_throw_error { sub new { my ($class, $name, %options) = @_; - $class->_process_options($name, \%options); + $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS + + delete $options{__hack_no_process_options}; + my %attrs = ( map { $_ => 1 } grep { defined } @@ -207,8 +210,8 @@ sub clone_and_inherit_options { my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options; (scalar @found_illegal_options == 0) || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options); - - + + # NOTE: # this doesn't apply to Class::MOP::Attributes, # so we can ignore it for them. @@ -221,7 +224,6 @@ sub clone_and_inherit_options { $options{traits} = \@all_traits if @all_traits; } - $self->clone(%options); } @@ -236,11 +238,15 @@ sub clone { push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; } - my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params ); + my %init_params = ( map { $_->init_arg => $_->get_value($self) } @init ); + + $self->_process_clone_options($self->name, \%params, \%init_params); - my $name = delete $new_params{name}; + my %new_params = ( %init_params, %params ); - my $clone = $class->new($name, %new_params); + my $name = delete $new_params{name}; + + my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 ); foreach my $attr ( @non_init ) { $attr->set_value($clone, $attr->get_value($self)); @@ -249,12 +255,19 @@ sub clone { return $clone; } +sub _process_clone_options { + my ( $class, $name, $options, $parent_options ) = @_; + $class->_process_isa_option( $name, $options, $parent_options ); + $class->_process_does_option( $name, $options, $parent_options ); + $class->_process_lazy_build_option( $name, $options, $parent_options ); +} + sub _process_options { my ( $class, $name, $options ) = @_; + $class->_process_is_option( $name, $options ); $class->_process_isa_option( $name, $options ); $class->_process_does_option( $name, $options ); - $class->_process_is_option( $name, $options ); $class->_process_coerce_option( $name, $options ); $class->_process_trigger_option( $name, $options ); $class->_process_auto_deref_option( $name, $options ); @@ -263,7 +276,6 @@ sub _process_options { $class->_process_required_option( $name, $options ); } - sub _process_is_option { my ( $class, $name, $options ) = @_;