From: Dave Rolsky Date: Sat, 21 Mar 2009 14:54:51 +0000 (-0500) Subject: Refactored to make _generate_triggers a lot less nesty. Also tidied X-Git-Tag: 0.72_01~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=708b4070b62a7aa92a4cfe9c5c2dee1b6d78a350;p=gitmo%2FMoose.git Refactored to make _generate_triggers a lot less nesty. Also tidied the method. --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 66eff82..627b641 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -229,27 +229,33 @@ sub _generate_BUILDALL { sub _generate_triggers { my $self = shift; my @trigger_calls; - foreach my $i (0 .. $#{ $self->attributes }) { + foreach my $i ( 0 .. $#{ $self->attributes } ) { my $attr = $self->attributes->[$i]; - if ($attr->can('has_trigger') && $attr->has_trigger) { - if (defined(my $init_arg = $attr->init_arg)) { - push @trigger_calls => ( - '(exists $params->{\'' . $init_arg . '\'}) && do {' . "\n " - . '$attrs->[' . $i . ']->trigger->(' - . '$instance, ' - . $self->meta_instance->inline_get_slot_value( - '$instance', - $attr->name, - ) - . ', ' - . '$attrs->[' . $i . ']' - . ');' - ."\n}" - ); - } - } + + next unless $attr->can('has_trigger') && $attr->has_trigger; + + my $init_arg = $attr->init_arg; + + next unless defined $init_arg; + + push @trigger_calls => '(exists $params->{\'' + . $init_arg + . '\'}) && do {' + . "\n " + . '$attrs->[' + . $i + . ']->trigger->(' + . '$instance, ' + . $self->meta_instance->inline_get_slot_value( + '$instance', + $attr->name, + ) + . ', ' + . '$attrs->[' + . $i . ']' . ');' . "\n}"; } - return join ";\n" => @trigger_calls; + + return join ";\n" => @trigger_calls; } sub _generate_slot_initializer {