[Moose-commits] r7975 - in MooseX-Params-Validate/trunk: . lib/MooseX/Params t

autarch at code2.0beta.co.uk autarch at code2.0beta.co.uk
Sun Nov 29 16:41:44 GMT 2009


Author: autarch
Date: 2009-11-29 08:41:44 -0800 (Sun, 29 Nov 2009)
New Revision: 7975

Modified:
   MooseX-Params-Validate/trunk/ChangeLog
   MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
   MooseX-Params-Validate/trunk/t/005_coercion.t
Log:
do not try to coerce positional params which weren't provided in the args list

Modified: MooseX-Params-Validate/trunk/ChangeLog
===================================================================
--- MooseX-Params-Validate/trunk/ChangeLog	2009-11-29 16:35:38 UTC (rev 7974)
+++ MooseX-Params-Validate/trunk/ChangeLog	2009-11-29 16:41:44 UTC (rev 7975)
@@ -1,8 +1,10 @@
 Revision history for Perl extension MooseX-Params-Validate
 
     - Fix so that validated_hash does not try to coerce optional
-      parameters which are not present from Ian Sillitoe
+      parameters which are not present. Patch by Ian Sillitoe.
 
+    - Same fix for pos_validated_list. (Dave Rolsky)
+
 0.12 Tue. Jul. 7, 2009
     - Using the subroutine name as a cache key for validation specs
       broke in the face of method modifiers, which all appear to have

Modified: MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
===================================================================
--- MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm	2009-11-29 16:35:38 UTC (rev 7974)
+++ MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm	2009-11-29 16:41:44 UTC (rev 7975)
@@ -146,7 +146,7 @@
     my @args = @{$args};
 
     $args[$_] = $pv_spec[$_]{constraint}->coerce( $args[$_] )
-        for grep { $pv_spec[$_]{coerce} } 0 .. $#pv_spec;
+        for grep { $pv_spec[$_] && $pv_spec[$_]{coerce} } 0 .. $#args;
 
     @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-11-29 16:35:38 UTC (rev 7974)
+++ MooseX-Params-Validate/trunk/t/005_coercion.t	2009-11-29 16:41:44 UTC (rev 7975)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 11;
+use Test::More tests => 15;
 use Test::Exception;
 
 # Note that setting coerce => 1 for the Num type tests that we don't try to do
@@ -64,6 +64,17 @@
         );
         [ $size1, $size2, $number ];
     }
+
+    sub ran_out {
+        my $self = shift;
+        my ( $size1, $size2, $number ) = pos_validated_list(
+            \@_,
+            { isa => 'Size', coerce => 1, optional => 1 },
+            { isa => 'Size', coerce => 0, optional => 1 },
+            { isa => 'Num',  coerce => 1, optional => 1 },
+        );
+        [ $size1, $size2, $number ];
+    }
 }
 
 my $foo = Foo->new;
@@ -120,3 +131,26 @@
     [ undef, 4, undef ],
     '... validated_list does not try to coerce keys which are not provided'
 );
+
+is_deeply(
+    $foo->ran_out( 1, 2, 3 ),
+    [ 1, 2, 3 ],
+    'got the return value right without coercions'
+);
+
+is_deeply(
+    $foo->ran_out( [1], 2, 3 ),
+    [ 1, 2, 3 ],
+    'got the return value right with coercion for the first param'
+);
+
+throws_ok { $foo->ran_out( [ 1, 2 ], [ 1, 2 ] ) }
+qr/\QParameter #2/,
+    '... did not attempt to coerce the second parameter';
+
+
+is_deeply(
+    $foo->ran_out(),
+    [ undef, undef, undef ],
+    'did not try to coerce non-existent parameters'
+);




More information about the Moose-commits mailing list