# $_[2] is the hashref of options passed to the constructor. If our
# parameter passed in was undef, pop it off the args...
- pop unless (exists($_[2]->{$ia}) && defined($_[2]->{$ia}));
+ pop unless (defined $ia && exists($_[2]->{$ia}) && defined($_[2]->{$ia}));
# Invoke the real init, as the above line cleared the unef
$self->$orig(@_)
my $self = shift;
my $attr = $self->_attributes->[$_[0]]->init_arg;
- my $tolerant_code =
- qq# delete \$params->{'$attr'} unless # .
- qq# exists \$params->{'$attr'} && defined \$params->{'$attr'};\n#;
+ # insert a line of code at the start of the initializer,
+ # clearing the param if it's undefined.
- return $tolerant_code . $self->$orig(@_);
+ if (defined $attr) {
+ my $tolerant_code =
+ qq# delete \$params->{'$attr'} unless # .
+ qq# exists \$params->{'$attr'} && defined \$params->{'$attr'};\n#;
+
+ return $tolerant_code . $self->$orig(@_);
+ }
+ else {
+ return $self->$orig(@_);
+ }
});
no Moose::Role;