r47931 - in /branches/upstream/libmoosex-params-validate-perl/current: ChangeLog META.yml Makefile.PL lib/MooseX/Params/Validate.pm t/005_coercion.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Mon Nov 30 02:36:51 UTC 2009
Author: jawnsy-guest
Date: Mon Nov 30 02:36:37 2009
New Revision: 47931
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=47931
Log:
[svn-upgrade] Integrating new upstream version, libmoosex-params-validate-perl (0.13)
Modified:
branches/upstream/libmoosex-params-validate-perl/current/ChangeLog
branches/upstream/libmoosex-params-validate-perl/current/META.yml
branches/upstream/libmoosex-params-validate-perl/current/Makefile.PL
branches/upstream/libmoosex-params-validate-perl/current/lib/MooseX/Params/Validate.pm
branches/upstream/libmoosex-params-validate-perl/current/t/005_coercion.t
Modified: branches/upstream/libmoosex-params-validate-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-params-validate-perl/current/ChangeLog?rev=47931&op=diff
==============================================================================
--- branches/upstream/libmoosex-params-validate-perl/current/ChangeLog (original)
+++ branches/upstream/libmoosex-params-validate-perl/current/ChangeLog Mon Nov 30 02:36:37 2009
@@ -1,4 +1,10 @@
Revision history for Perl extension MooseX-Params-Validate
+
+0.13 Sun., Nov. 29, 2009
+ - Fix so that validated_hash does not try to coerce optional
+ parameters which are not present. Patch by Ian Sillitoe.
+
+ - Same fix for pos_validated_list. (Dave Rolsky)
0.12 Tue. Jul. 7, 2009
- Using the subroutine name as a cache key for validation specs
Modified: branches/upstream/libmoosex-params-validate-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-params-validate-perl/current/META.yml?rev=47931&op=diff
==============================================================================
--- branches/upstream/libmoosex-params-validate-perl/current/META.yml (original)
+++ branches/upstream/libmoosex-params-validate-perl/current/META.yml Mon Nov 30 02:36:37 2009
@@ -28,4 +28,5 @@
Sub::Exporter: 0
resources:
license: http://dev.perl.org/licenses/
-version: 0.12
+ repository: http://code2.0beta.co.uk/moose/svn/MooseX-Params-Validate
+version: 0.13
Modified: branches/upstream/libmoosex-params-validate-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-params-validate-perl/current/Makefile.PL?rev=47931&op=diff
==============================================================================
--- branches/upstream/libmoosex-params-validate-perl/current/Makefile.PL (original)
+++ branches/upstream/libmoosex-params-validate-perl/current/Makefile.PL Mon Nov 30 02:36:37 2009
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use inc::Module::Install;
+use inc::Module::Install 0.91;
name 'MooseX-Params-Validate';
all_from 'lib/MooseX/Params/Validate.pm';
@@ -18,4 +18,6 @@
license 'Perl';
+resources repository => 'http://code2.0beta.co.uk/moose/svn/MooseX-Params-Validate';
+
WriteAll();
Modified: branches/upstream/libmoosex-params-validate-perl/current/lib/MooseX/Params/Validate.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-params-validate-perl/current/lib/MooseX/Params/Validate.pm?rev=47931&op=diff
==============================================================================
--- branches/upstream/libmoosex-params-validate-perl/current/lib/MooseX/Params/Validate.pm (original)
+++ branches/upstream/libmoosex-params-validate-perl/current/lib/MooseX/Params/Validate.pm Mon Nov 30 02:36:37 2009
@@ -19,7 +19,7 @@
},
};
-our $VERSION = '0.12';
+our $VERSION = '0.13';
our $AUTHORITY = 'cpan:STEVAN';
my %CACHED_SPECS;
@@ -52,7 +52,7 @@
my %args = @$args;
$args{$_} = $spec{$_}{constraint}->coerce( $args{$_} )
- for grep { $spec{$_}{coerce} } keys %spec;
+ for grep { $spec{$_}{coerce} && exists $args{$_} } keys %spec;
%args = Params::Validate::validate_with(
params => \%args,
@@ -146,7 +146,7 @@
my @args = @{$args};
$args[$_] = $pv_spec[$_]{constraint}->coerce( $args[$_] )
- for grep { $pv_spec[$_]{coerce} } 0 .. $#pv_spec;
+ for grep { $pv_spec[$_] && $pv_spec[$_]{coerce} } 0 .. $#args;
@args = Params::Validate::validate_with(
params => \@args,
Modified: branches/upstream/libmoosex-params-validate-perl/current/t/005_coercion.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-params-validate-perl/current/t/005_coercion.t?rev=47931&op=diff
==============================================================================
--- branches/upstream/libmoosex-params-validate-perl/current/t/005_coercion.t (original)
+++ branches/upstream/libmoosex-params-validate-perl/current/t/005_coercion.t Mon Nov 30 02:36:37 2009
@@ -3,9 +3,11 @@
use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More tests => 15;
use Test::Exception;
+# Note that setting coerce => 1 for the Num type tests that we don't try to do
+# coercions for a type which doesn't have any coercions.
{
package Foo;
use Moose;
@@ -27,6 +29,19 @@
[ $params{size1}, $params{size2}, $params{number} ];
}
+ # added to test 'optional' on validated_hash
+ sub baropt {
+ my $self = shift;
+ my %params = validated_hash(
+ \@_,
+ size1 => { isa => 'Size', coerce => 1, optional => 1 },
+ size2 => { isa => 'Size', coerce => 0, optional => 1 },
+ number => { isa => 'Num', coerce => 1, optional => 1 },
+ );
+ [ $params{size1}, $params{size2}, $params{number} ];
+ }
+
+
sub baz {
my $self = shift;
my ( $size1, $size2, $number ) = validated_list(
@@ -46,6 +61,17 @@
size1 => { isa => 'Size', coerce => 1, optional => 1 },
size2 => { isa => 'Size', coerce => 0, optional => 1 },
number => { isa => 'Num', coerce => 1, optional => 1 },
+ );
+ [ $size1, $size2, $number ];
+ }
+
+ sub ran_out {
+ my $self = shift;
+ my ( $size1, $size2, $number ) = pos_validated_list(
+ \@_,
+ { isa => 'Size', coerce => 1, optional => 1 },
+ { isa => 'Size', coerce => 0, optional => 1 },
+ { isa => 'Num', coerce => 1, optional => 1 },
);
[ $size1, $size2, $number ];
}
@@ -72,7 +98,7 @@
throws_ok { $foo->bar( size1 => 30, size2 => 10, number => 'something' ) }
qr/\QThe 'number' parameter/,
- '... the number param cannot be coerced';
+ '... the number param cannot be coerced because there is no coercion defined for Num';
is_deeply(
$foo->baz( size1 => 10, size2 => 20, number => 30 ),
@@ -95,7 +121,36 @@
'... the number param cannot be coerced';
is_deeply(
+ $foo->baropt( size2 => 4 ),
+ [ undef, 4, undef ],
+ '... validated_hash does not try to coerce keys which are not provided'
+);
+
+is_deeply(
$foo->quux( size2 => 4 ),
[ undef, 4, undef ],
- '... does not try to coerce keys which are not provided'
+ '... validated_list does not try to coerce keys which are not provided'
);
+
+is_deeply(
+ $foo->ran_out( 1, 2, 3 ),
+ [ 1, 2, 3 ],
+ 'got the return value right without coercions'
+);
+
+is_deeply(
+ $foo->ran_out( [1], 2, 3 ),
+ [ 1, 2, 3 ],
+ 'got the return value right with coercion for the first param'
+);
+
+throws_ok { $foo->ran_out( [ 1, 2 ], [ 1, 2 ] ) }
+qr/\QParameter #2/,
+ '... did not attempt to coerce the second parameter';
+
+
+is_deeply(
+ $foo->ran_out(),
+ [ undef, undef, undef ],
+ 'did not try to coerce non-existent parameters'
+);
More information about the Pkg-perl-cvs-commits
mailing list