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 ();
},
};
-our $VERSION = '0.14';
-our $AUTHORITY = 'cpan:STEVAN';
-
my %CACHED_SPECS;
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;
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;
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;
1;
+# ABSTRACT: an extension of Params::Validate using Moose's types
+
__END__
=pod
-=head1 NAME
-
-MooseX::Params::Validate - an extension of Params::Validate for using Moose's types
-
=head1 SYNOPSIS
package Foo;
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
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<undef>.
+The values in C<@_> can either be a set of name-value pairs or a single hash
+reference.
+
Like C<validated_hash>, if it spots an object instance as the first
parameter of C<@_>, it will handle it appropriately, returning it as
the first argument.
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.
+
If a parameter is marked as optional and is not present, it will
simply not be returned.
=back
-=head1 BUGS
-
-All complex software has bugs lurking in it, and this module is no
-exception. If you find a bug please either email me, or add the bug to
-cpan-RT.
-
-=head1 AUTHORS
-
-Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
+=head1 MAINTAINER
Dave Rolsky E<lt>autarch@urth.orgE<gt>
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2007-2009 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
+=head1 BUGS
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+Please submit bugs to the CPAN RT system at
+http://rt.cpan.org/NoAuth/ReportBug.html?Queue=moosex-params-validate or via
+email at bug-moosex-params-validate@rt.cpan.org.
=cut