[Moose-commits] r7459 - in MooseX-Params-Validate/trunk: .
lib/MooseX/Params t
autarch at code2.0beta.co.uk
autarch at code2.0beta.co.uk
Sat Jan 31 22:48:38 GMT 2009
Author: autarch
Date: 2009-01-31 14:48:38 -0800 (Sat, 31 Jan 2009)
New Revision: 7459
Modified:
MooseX-Params-Validate/trunk/Makefile.PL
MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
MooseX-Params-Validate/trunk/t/001_basic.t
MooseX-Params-Validate/trunk/t/002_basic_positional.t
MooseX-Params-Validate/trunk/t/003_nocache_flag.t
MooseX-Params-Validate/trunk/t/004_custom_cache_key.t
MooseX-Params-Validate/trunk/t/005_coercion.t
MooseX-Params-Validate/trunk/t/006_not_moose.t
MooseX-Params-Validate/trunk/t/pod_coverage.t
Log:
Renamed validate -> validated_hash, validatep -> validated_list
Switched to Sub::Exporter, makes it easier to have a :deprecated tag
to export the old functions.
Updated docs and all the tests. Also added a test that we do export
the deprecated names.
Modified: MooseX-Params-Validate/trunk/Makefile.PL
===================================================================
--- MooseX-Params-Validate/trunk/Makefile.PL 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/Makefile.PL 2009-01-31 22:48:38 UTC (rev 7459)
@@ -10,6 +10,7 @@
requires 'Moose' => '0.58';
requires 'Params::Validate' => '0.88';
requires 'Scalar::Util' => '0';
+requires 'Sub::Exporter' => '0';
build_requires 'Test::More' => '0.62';
build_requires 'Test::Exception' => '0.21';
Modified: MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
===================================================================
--- MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-01-31 22:48:38 UTC (rev 7459)
@@ -6,18 +6,22 @@
use Carp 'confess';
use Scalar::Util 'blessed';
-use Moose::Exporter;
use Moose::Util::TypeConstraints ();
use Params::Validate ();
+use Sub::Exporter -setup => {
+ exports => [qw( validated_hash validated_list validate validatep )],
+ groups => {
+ default => [qw( validated_hash validated_list )],
+ deprecated => [qw( validate validatep )],
+ },
+};
our $VERSION = '0.07';
our $AUTHORITY = 'cpan:STEVAN';
my %CACHED_PARAM_SPECS;
-Moose::Exporter->setup_import_methods( as_is => [qw( validate validatep )] );
-
-sub validate {
+sub validated_hash {
my ( $args, %params ) = @_;
my $cache_key;
@@ -64,7 +68,9 @@
return ( ( $instance ? $instance : () ), %args );
}
-sub validatep {
+*validate = \&validated_hash;
+
+sub validated_list {
my ( $args, @params ) = @_;
my %params = @params;
@@ -121,6 +127,8 @@
);
}
+*validatep = \&validated_list;
+
sub _convert_to_param_validate_spec {
my ($spec) = @_;
my %pv_spec;
@@ -216,7 +224,7 @@
use MooseX::Params::Validate;
sub foo {
- my ( $self, %params ) = validate(
+ my ( $self, %params ) = validated_hash(
\@_,
bar => { isa => 'Str', default => 'Moose' },
);
@@ -225,7 +233,7 @@
sub bar {
my $self = shift;
- my ( $foo, $baz, $gorch ) = validatep(
+ my ( $foo, $baz, $gorch ) = validated_list(
\@_,
foo => { isa => 'Foo' },
baz => { isa => 'ArrayRef | HashRef', optional => 1 },
@@ -253,7 +261,7 @@
=over 4
-=item B<validate (\@_, %parameter_spec)>
+=item B<validated_hash( \@_, %parameter_spec )>
This behaves similar to the standard Params::Validate C<validate>
function and returns the captured values in a HASH. The one exception
@@ -293,16 +301,16 @@
=back
-The plan is to support more options in the future as well.
+This function is also available under its old name, C<validate>.
-=item B<validatep (\@_, %parameter_spec)>
+=item B<validated_list( \@_, %parameter_spec )>
The C<%parameter_spec> accepts the same options as above, but returns
the parameters as positional values instead of a HASH. This is best
explained by example:
sub foo {
- my ( $self, $foo, $bar ) = validatep(
+ my ( $self, $foo, $bar ) = validated_list(
\@_,
foo => { isa => 'Foo' },
bar => { isa => 'Bar' },
@@ -314,8 +322,19 @@
return them as positionals in the same order. If a param is marked
optional and not included, then it will be set to C<undef>.
+This function is also available under its old name, C<validatep>.
+
=back
+=head1 EXPORTS
+
+By default, this module exports the C<validated_hash>,
+C<validated_list>, and C<pos_validated_list>.
+
+If you would prefer to import the now deprecated functions C<validate>
+and C<validatep> instead, you can use the C<:deprecated> tag to import
+them.
+
=head1 IMPORTANT NOTE ON CACHING
When C<validate> or C<validatep> are called the first time, the
@@ -344,14 +363,6 @@
=back
-=head1 METHODS
-
-=over 4
-
-=item B<import>
-
-=back
-
=head1 BUGS
All complex software has bugs lurking in it, and this module is no
Modified: MooseX-Params-Validate/trunk/t/001_basic.t
===================================================================
--- MooseX-Params-Validate/trunk/t/001_basic.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/001_basic.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -15,7 +15,7 @@
requires 'baz';
sub foo {
- my ( $self, %params ) = validate(
+ my ( $self, %params ) = validated_hash(
\@_,
bar => { isa => 'Str', default => 'Moose' },
);
@@ -31,7 +31,7 @@
sub bar {
my $self = shift;
- my %params = validate(
+ my %params = validated_hash(
\@_,
foo => { isa => 'Foo' },
baz => { isa => 'ArrayRef | HashRef', optional => 1 },
@@ -42,7 +42,7 @@
sub baz {
my $self = shift;
- my %params = validate(
+ my %params = validated_hash(
\@_,
foo => {
isa => subtype( 'Object' => where { $_->isa('Foo') } ),
Modified: MooseX-Params-Validate/trunk/t/002_basic_positional.t
===================================================================
--- MooseX-Params-Validate/trunk/t/002_basic_positional.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/002_basic_positional.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -22,7 +22,7 @@
with 'Roles::Blah';
sub foo {
- my ( $self, $bar ) = validatep(
+ my ( $self, $bar ) = validated_list(
\@_,
bar => { isa => 'Str', default => 'Moose' },
);
@@ -31,7 +31,7 @@
sub bar {
my $self = shift;
- my ( $foo, $baz ) = validatep(
+ my ( $foo, $baz ) = validated_list(
\@_,
foo => { isa => 'Foo' },
baz => { isa => 'ArrayRef | HashRef', optional => 1 },
@@ -41,7 +41,7 @@
sub baz {
my $self = shift;
- my ( $foo, $bar, $boo ) = validatep(
+ my ( $foo, $bar, $boo ) = validated_list(
\@_,
foo => {
isa => subtype( 'Object' => where { $_->isa('Foo') } ),
Modified: MooseX-Params-Validate/trunk/t/003_nocache_flag.t
===================================================================
--- MooseX-Params-Validate/trunk/t/003_nocache_flag.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/003_nocache_flag.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -14,7 +14,7 @@
sub bar {
my ( $self, $args, $params ) = @_;
$params->{MX_PARAMS_VALIDATE_NO_CACHE}++;
- return validate( $args, %$params );
+ return validated_hash( $args, %$params );
}
}
Modified: MooseX-Params-Validate/trunk/t/004_custom_cache_key.t
===================================================================
--- MooseX-Params-Validate/trunk/t/004_custom_cache_key.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/004_custom_cache_key.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -16,7 +16,7 @@
my ( $self, $args, $params ) = @_;
$params->{MX_PARAMS_VALIDATE_CACHE_KEY}
= Scalar::Util::refaddr($self);
- return validate( $args, %$params );
+ return validated_hash( $args, %$params );
}
}
Modified: MooseX-Params-Validate/trunk/t/005_coercion.t
===================================================================
--- MooseX-Params-Validate/trunk/t/005_coercion.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/005_coercion.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -18,7 +18,7 @@
sub bar {
my $self = shift;
- my %params = validate(
+ my %params = validated_hash(
\@_,
size1 => { isa => 'Size', coerce => 1 },
size2 => { isa => 'Size', coerce => 0 },
@@ -29,7 +29,7 @@
sub baz {
my $self = shift;
- my ( $size1, $size2, $number ) = validatep(
+ my ( $size1, $size2, $number ) = validated_list(
\@_,
size1 => { isa => 'Size', coerce => 1 },
size2 => { isa => 'Size', coerce => 0 },
Modified: MooseX-Params-Validate/trunk/t/006_not_moose.t
===================================================================
--- MooseX-Params-Validate/trunk/t/006_not_moose.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/006_not_moose.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -17,4 +17,4 @@
$@, '',
'loading MX::Params::Validate in a non-Moose class does not blow up'
);
-ok( Foo->can('validate'), 'validate() sub was added to Foo package' );
+ok( Foo->can('validated_hash'), 'validated_hash() sub was added to Foo package' );
Modified: MooseX-Params-Validate/trunk/t/pod_coverage.t
===================================================================
--- MooseX-Params-Validate/trunk/t/pod_coverage.t 2009-01-31 22:33:41 UTC (rev 7458)
+++ MooseX-Params-Validate/trunk/t/pod_coverage.t 2009-01-31 22:48:38 UTC (rev 7459)
@@ -8,4 +8,4 @@
eval "use Test::Pod::Coverage 1.04";
plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
-all_pod_coverage_ok();
+all_pod_coverage_ok( { trustme => [ qr/^(?:validatep?|import)$/ ] } );
More information about the Moose-commits
mailing list