From: Jesse Luehrs Date: Mon, 4 Apr 2011 02:49:57 +0000 (-0500) Subject: these version checks already happen in the exporter X-Git-Tag: 0.12~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e5d1b64215dcded06a34e7c389958c79f33c3906;p=gitmo%2FMooseX-UndefTolerant.git these version checks already happen in the exporter --- diff --git a/lib/MooseX/UndefTolerant/Class.pm b/lib/MooseX/UndefTolerant/Class.pm index c8bd25c..d8484b9 100644 --- a/lib/MooseX/UndefTolerant/Class.pm +++ b/lib/MooseX/UndefTolerant/Class.pm @@ -1,24 +1,22 @@ package MooseX::UndefTolerant::Class; use Moose::Role; -if ( $Moose::VERSION >= 1.9900 ) { - around('_inline_init_attr_from_constructor', sub { - my $orig = shift; - my $self = shift; - my ($attr, $idx) = @_; +around _inline_init_attr_from_constructor => sub { + my $orig = shift; + my $self = shift; + my ($attr, $idx) = @_; - my @source = $self->$orig(@_); + my @source = $self->$orig(@_); - my $init_arg = $attr->init_arg; + my $init_arg = $attr->init_arg; - return - "if ( exists \$params->{$init_arg} && defined \$params->{$init_arg} ) {", - @source, - '} else {', - "delete \$params->{$init_arg};", - '}'; - }); -} + return + "if ( exists \$params->{$init_arg} && defined \$params->{$init_arg} ) {", + @source, + '} else {', + "delete \$params->{$init_arg};", + '}'; +}; no Moose::Role; diff --git a/lib/MooseX/UndefTolerant/Constructor.pm b/lib/MooseX/UndefTolerant/Constructor.pm index 18f3307..9f4046c 100644 --- a/lib/MooseX/UndefTolerant/Constructor.pm +++ b/lib/MooseX/UndefTolerant/Constructor.pm @@ -1,35 +1,33 @@ package MooseX::UndefTolerant::Constructor; use Moose::Role; -if ( $Moose::VERSION < 1.9900 ) { - around('_generate_slot_initializer', sub { - my $orig = shift; - my $self = shift; +around _generate_slot_initializer => sub { + my $orig = shift; + my $self = shift; - # note the key in the params may not match the attr name. - my $key_name = $self->_attributes->[$_[0]]->init_arg; + # note the key in the params may not match the attr name. + my $key_name = $self->_attributes->[$_[0]]->init_arg; - # insert a line of code at the start of the initializer, - # clearing the param if it's undefined. + # insert a line of code at the start of the initializer, + # clearing the param if it's undefined. - if (defined $key_name) + if (defined $key_name) + { + # leave the value unscathed if the attribute's type constraint can + # handle undef (or doesn't have one, which implicitly means it can) + my $type_constraint = $self->_attributes->[$_[0]]->type_constraint; + if ($type_constraint and not $type_constraint->check(undef)) { - # leave the value unscathed if the attribute's type constraint can - # handle undef (or doesn't have one, which implicitly means it can) - my $type_constraint = $self->_attributes->[$_[0]]->type_constraint; - if ($type_constraint and not $type_constraint->check(undef)) - { - my $tolerant_code = - qq# delete \$params->{'$key_name'} unless # . - qq# exists \$params->{'$key_name'} && defined \$params->{'$key_name'};\n#; + my $tolerant_code = + qq# delete \$params->{'$key_name'} unless # . + qq# exists \$params->{'$key_name'} && defined \$params->{'$key_name'};\n#; - return $tolerant_code . $self->$orig(@_); - } + return $tolerant_code . $self->$orig(@_); } + } - return $self->$orig(@_); - }); -} + return $self->$orig(@_); +}; no Moose::Role; 1;