[Moose-commits] r7955 - in MooseX-Params-Validate/trunk:
lib/MooseX/Params t
autarch at code2.0beta.co.uk
autarch at code2.0beta.co.uk
Tue Jul 7 17:52:28 GMT 2009
Author: autarch
Date: 2009-07-07 10:52:28 -0700 (Tue, 07 Jul 2009)
New Revision: 7955
Modified:
MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
MooseX-Params-Validate/trunk/t/005_coercion.t
Log:
do not try to coerce optional keys which are not provided
Modified: MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
===================================================================
--- MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-06-30 19:10:11 UTC (rev 7954)
+++ MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-07-07 17:52:28 UTC (rev 7955)
@@ -98,7 +98,7 @@
my %args = @$args;
$args{$_} = $spec{$_}{constraint}->coerce( $args{$_} )
- for grep { $spec{$_}{coerce} } keys %spec;
+ for grep { $spec{$_}{coerce} && exists $args{$_} } keys %spec;
%args = Params::Validate::validate_with(
params => \%args,
Modified: MooseX-Params-Validate/trunk/t/005_coercion.t
===================================================================
--- MooseX-Params-Validate/trunk/t/005_coercion.t 2009-06-30 19:10:11 UTC (rev 7954)
+++ MooseX-Params-Validate/trunk/t/005_coercion.t 2009-07-07 17:52:28 UTC (rev 7955)
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More tests => 10;
use Test::Exception;
{
@@ -37,6 +37,18 @@
);
[ $size1, $size2, $number ];
}
+
+
+ sub quux {
+ my $self = shift;
+ my ( $size1, $size2, $number ) = validated_list(
+ \@_,
+ size1 => { isa => 'Size', coerce => 1, optional => 1 },
+ size2 => { isa => 'Size', coerce => 0, optional => 1 },
+ number => { isa => 'Num', coerce => 1, optional => 1 },
+ );
+ [ $size1, $size2, $number ];
+ }
}
my $foo = Foo->new;
@@ -81,3 +93,9 @@
throws_ok { $foo->baz( size1 => 30, size2 => 10, number => 'something' ) }
qr/\QThe 'number' parameter/,
'... the number param cannot be coerced';
+
+is_deeply(
+ $foo->quux( size2 => 4 ),
+ [ undef, 4, undef ],
+ '... does not try to coerce keys which are not provided'
+);
More information about the Moose-commits
mailing list