From: Dave Rolsky Date: Sat, 29 Jan 2011 17:36:23 +0000 (-0600) Subject: Cannot accept an arrayref to pos_validated_list, since this can be confused with... X-Git-Tag: v0.16~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ddc128beb3cc265ce4be4854b4431e2246f788ee;p=gitmo%2FMooseX-Params-Validate.git Cannot accept an arrayref to pos_validated_list, since this can be confused with a single argument that is an arrayref --- diff --git a/lib/MooseX/Params/Validate.pm b/lib/MooseX/Params/Validate.pm index 410779a..e05c0b7 100644 --- a/lib/MooseX/Params/Validate.pm +++ b/lib/MooseX/Params/Validate.pm @@ -154,10 +154,7 @@ sub pos_validated_list { if $should_cache; } - my @args - = @$args == 1 - && ref $args->[0] - && reftype( $args->[0] ) eq 'ARRAY' ? @{ $args->[0] } : @$args; + my @args = @$args; $args[$_] = $pv_spec[$_]{constraint}->coerce( $args[$_] ) for grep { $pv_spec[$_] && $pv_spec[$_]{coerce} } 0 .. $#args; @@ -388,8 +385,9 @@ Unlike the other functions, this function I find C<$self> in the argument list. Make sure to shift it off yourself before doing validation. -The values in C<@_> can either be a list of values or a single array -reference. +The values in C<@_> must be a list of values. You cannot pass the values as an +array reference, because this cannot be distinguished from passing one value +which is itself an array reference. If a parameter is marked as optional and is not present, it will simply not be returned. diff --git a/t/012_ref_as_first_param.t b/t/012_ref_as_first_param.t index e934395..95c76c0 100644 --- a/t/012_ref_as_first_param.t +++ b/t/012_ref_as_first_param.t @@ -28,16 +28,6 @@ use Test::Fatal; return \%p; } - - sub baz { - my ( $x, $y ) = pos_validated_list( - \@_, - { isa => 'Any' }, - { isa => 'Any' }, - ); - - return { x => $x, y => $y }; - } } is_deeply( @@ -64,16 +54,4 @@ is_deeply( 'validated_hash accepts a hash reference' ); -is_deeply( - baz( 42, 84 ), - { x => 42, y => 84 }, - 'pos_validated_list accepts a plain array' -); - -is_deeply( - baz( [42, 84] ), - { x => 42, y => 84 }, - 'pos_validated_list accepts a array reference' -); - done_testing();