X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FParams%2FValidate.pm;h=c2f691b2bf28739d924fae0e3a34326e1ca18b63;hb=refs%2Ftags%2Fv0.16;hp=5153916e5c013481a257ae74a383b95cfd6a8628;hpb=954fa4ca925acc785459347bf501488e63b0d06b;p=gitmo%2FMooseX-Params-Validate.git diff --git a/lib/MooseX/Params/Validate.pm b/lib/MooseX/Params/Validate.pm index 5153916..c2f691b 100644 --- a/lib/MooseX/Params/Validate.pm +++ b/lib/MooseX/Params/Validate.pm @@ -48,7 +48,7 @@ sub validated_hash { my $instance; $instance = shift @$args if blessed $args->[0]; - my %args + my %args = @$args == 1 && ref $args->[0] && reftype( $args->[0] ) eq 'HASH' ? %{ $args->[0] } : @$args; @@ -101,7 +101,7 @@ sub validated_list { my $instance; $instance = shift @$args if blessed $args->[0]; - my %args + my %args = @$args == 1 && ref $args->[0] && reftype( $args->[0] ) eq 'HASH' ? %{ $args->[0] } : @$args; @@ -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; @@ -303,6 +300,9 @@ is where if it spots an instance in the C<@_>, then it will handle it appropriately (unlike Params::Validate which forces you to shift you C<$self> first). +The values in C<@_> can either be a set of name-value pairs or a single hash +reference. + The C<%parameter_spec> accepts the following options: =over 4 @@ -356,6 +356,9 @@ We capture the order in which you defined the parameters and then return them as a list in the same order. If a param is marked optional and not included, then it will be set to C. +The values in C<@_> can either be a set of name-value pairs or a single hash +reference. + Like C, if it spots an object instance as the first parameter of C<@_>, it will handle it appropriately, returning it as the first argument. @@ -382,6 +385,10 @@ 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<@_> 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.