X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FParams%2FValidate.pm;h=5153916e5c013481a257ae74a383b95cfd6a8628;hb=954fa4ca925acc785459347bf501488e63b0d06b;hp=25fb20a9d492717b1eef1375f830a6bc8606121d;hpb=962b09000a3422042ce1761b7aabc2bd6795ed7a;p=gitmo%2FMooseX-Params-Validate.git diff --git a/lib/MooseX/Params/Validate.pm b/lib/MooseX/Params/Validate.pm index 25fb20a..5153916 100644 --- a/lib/MooseX/Params/Validate.pm +++ b/lib/MooseX/Params/Validate.pm @@ -5,7 +5,7 @@ use warnings; use Carp 'confess'; use Devel::Caller 'caller_cv'; -use Scalar::Util 'blessed', 'refaddr'; +use Scalar::Util 'blessed', 'refaddr', 'reftype'; use Moose::Util::TypeConstraints qw( find_type_constraint class_type role_type ); use Params::Validate (); @@ -48,7 +48,10 @@ sub validated_hash { my $instance; $instance = shift @$args if blessed $args->[0]; - my %args = @$args; + my %args + = @$args == 1 + && ref $args->[0] + && reftype( $args->[0] ) eq 'HASH' ? %{ $args->[0] } : @$args; $args{$_} = $spec{$_}{constraint}->coerce( $args{$_} ) for grep { $spec{$_}{coerce} && exists $args{$_} } keys %spec; @@ -98,7 +101,10 @@ sub validated_list { my $instance; $instance = shift @$args if blessed $args->[0]; - my %args = @$args; + my %args + = @$args == 1 + && ref $args->[0] + && reftype( $args->[0] ) eq 'HASH' ? %{ $args->[0] } : @$args; $args{$_} = $spec{$_}{constraint}->coerce( $args{$_} ) for grep { $spec{$_}{coerce} && exists $args{$_} } keys %spec; @@ -148,7 +154,10 @@ sub pos_validated_list { if $should_cache; } - my @args = @{$args}; + my @args + = @$args == 1 + && ref $args->[0] + && reftype( $args->[0] ) eq 'ARRAY' ? @{ $args->[0] } : @$args; $args[$_] = $pv_spec[$_]{constraint}->coerce( $args[$_] ) for grep { $pv_spec[$_] && $pv_spec[$_]{coerce} } 0 .. $#args;