MooseX-Params-Validate-0.18/0000775000175000017500000000000012075565774015510 5ustar autarchautarchMooseX-Params-Validate-0.18/MANIFEST0000644000175000017500000000100012075565774016626 0ustar autarchautarchChanges INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/MooseX/Params/Validate.pm t/000_load.t t/001_basic.t t/002_basic_list.t t/003_nocache_flag.t t/004_custom_cache_key.t t/005_coercion.t t/006_not_moose.t t/007_deprecated.t t/008_positional.t t/009_wrapped.t t/010_overloaded.t t/011_allow_extra.t t/012_ref_as_first_param.t t/release-eol.t t/release-no-tabs.t t/release-pod-coverage.t t/release-pod-linkcheck.t t/release-pod-no404s.t t/release-pod-spell.t t/release-pod-syntax.t MooseX-Params-Validate-0.18/t/0000775000175000017500000000000012075565774015753 5ustar autarchautarchMooseX-Params-Validate-0.18/t/005_coercion.t0000644000175000017500000001053512075565774020327 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; # 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; use Moose::Util::TypeConstraints; use MooseX::Params::Validate; subtype 'Size' => as 'Int' => where { $_ >= 0 }; coerce 'Size' => from 'ArrayRef' => via { scalar @{$_} }; sub bar { my $self = shift; my %params = validated_hash( \@_, size1 => { isa => 'Size', coerce => 1 }, size2 => { isa => 'Size', coerce => 0 }, number => { isa => 'Num', coerce => 1 }, ); [ $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( \@_, size1 => { isa => 'Size', coerce => 1 }, size2 => { isa => 'Size', coerce => 0 }, number => { isa => 'Num', coerce => 1 }, ); [ $size1, $size2, $number ]; } sub quux { my $self = shift; my ( $size1, $size2, $number ) = validated_list( \@_, 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 ]; } } my $foo = Foo->new; isa_ok( $foo, 'Foo' ); is_deeply( $foo->bar( size1 => 10, size2 => 20, number => 30 ), [ 10, 20, 30 ], 'got the return value right without coercions' ); is_deeply( $foo->bar( size1 => [ 1, 2, 3 ], size2 => 20, number => 30 ), [ 3, 20, 30 ], 'got the return value right with coercions for size1' ); like( exception { $foo->bar( size1 => 30, size2 => [ 1, 2, 3 ], number => 30 ) } , qr/\QThe 'size2' parameter/, '... the size2 param cannot be coerced' ); like( exception { $foo->bar( size1 => 30, size2 => 10, number => 'something' ) } , qr/\QThe 'number' parameter/, '... the number param cannot be coerced because there is no coercion defined for Num' ); is_deeply( $foo->baz( size1 => 10, size2 => 20, number => 30 ), [ 10, 20, 30 ], 'got the return value right without coercions' ); is_deeply( $foo->baz( size1 => [ 1, 2, 3 ], size2 => 20, number => 30 ), [ 3, 20, 30 ], 'got the return value right with coercions for size1' ); like( exception { $foo->baz( size1 => 30, size2 => [ 1, 2, 3 ], number => 30 ) } , qr/\QThe 'size2' parameter/, '... the size2 param cannot be coerced' ); like( exception { $foo->baz( size1 => 30, size2 => 10, number => 'something' ) } , qr/\QThe 'number' parameter/, '... 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 ], '... 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' ); like( exception { $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' ); done_testing(); MooseX-Params-Validate-0.18/t/release-pod-spell.t0000644000175000017500000000135612075565774021460 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval "use Test::Spelling"; plan skip_all => "Test::Spelling required for testing POD coverage" if $@; my @stopwords; for () { chomp; push @stopwords, $_ unless /\A (?: \# | \s* \z)/msx; # skip comments, whitespace } add_stopwords(@stopwords); set_spell_cmd('aspell list -l en'); # This prevents a weird segfault from the aspell command - see # https://bugs.launchpad.net/ubuntu/+source/aspell/+bug/71322 local $ENV{LC_ALL} = 'C'; all_pod_files_spelling_ok(); __DATA__ Rolsky Stevan coercions cpan isa param subname MooseX-Params-Validate-0.18/t/003_nocache_flag.t0000644000175000017500000000166012075565774021114 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; { package Foo; use Moose; use MooseX::Params::Validate; sub bar { my ( $self, $args, $params ) = @_; $params->{MX_PARAMS_VALIDATE_NO_CACHE}++; return validated_hash( $args, %$params ); } } my $foo = Foo->new; isa_ok( $foo, 'Foo' ); is( exception { $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } ); }, undef, '... successfully applied the parameter validation' ); is( exception { $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } ); }, undef, '... successfully applied the parameter validation (look mah no cache)' ); is( exception { $foo->bar( [ baz => { one => 1 } ], { baz => { isa => 'HashRef' } } ); }, undef, '... successfully applied the parameter validation (look mah no cache) (just checkin)' ); done_testing(); MooseX-Params-Validate-0.18/t/007_deprecated.t0000644000175000017500000000043112075565774020622 0ustar autarchautarchuse strict; use warnings; use Test::More; { package Foo; use Moose; use MooseX::Params::Validate qw( :deprecated ); } ok( Foo->can('validate'), ':deprecated tag exports validate' ); ok( Foo->can('validatep'), ':deprecated tag exports validatep' ); done_testing(); MooseX-Params-Validate-0.18/t/009_wrapped.t0000644000175000017500000000243312075565774020172 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; { package Foo; use Moose; use MooseX::Params::Validate; sub foo { my $self = shift; my %params = validated_hash( \@_, foo => { isa => 'Str' }, ); return $params{foo}; } around 'foo' => sub { my $orig = shift; my $self = shift; my %p = @_; my @args = ( bar => delete $p{bar} ); my %params = validated_hash( \@args, bar => { isa => 'Str' }, ); $params{bar}, $self->$orig(%p); }; around 'foo' => sub { my $orig = shift; my $self = shift; my %p = @_; my @args = ( quux => delete $p{quux} ); my %params = validated_hash( \@args, quux => { isa => 'Str' }, ); $params{quux}, $self->$orig(%p); }; } { my $foo = Foo->new; is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ], [ 3, 2, 1 ], 'multiple around wrappers can safely be cached' ); is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ], [ 3, 2, 1 ], 'multiple around wrappers can safely be cached (2nd time)' ); } done_testing(); MooseX-Params-Validate-0.18/t/008_positional.t0000644000175000017500000001170312075565774020710 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; { package Roles::Blah; use Moose::Role; use MooseX::Params::Validate; requires 'bar'; requires 'baz'; sub foo { my ( $self, %params ) = validated_hash( \@_, bar => { isa => 'Str', default => 'Moose' }, ); return "Horray for $params{bar}!"; } package Foo; use Moose; use Moose::Util::TypeConstraints; use MooseX::Params::Validate; with 'Roles::Blah'; sub bar { my $self = shift; return [ pos_validated_list( \@_, { isa => 'Foo' }, { isa => 'ArrayRef | HashRef', optional => 1 }, { isa => 'ArrayRef[Int]', optional => 1 }, ) ]; } sub baz { my $self = shift; return [ pos_validated_list( \@_, { isa => subtype( 'Object' => where { $_->isa('Foo') } ), optional => 1 }, { does => 'Roles::Blah', optional => 1 }, { does => role_type('Roles::Blah'), optional => 1 }, ) ]; } } my $foo = Foo->new; isa_ok( $foo, 'Foo' ); is( $foo->baz($foo)->[0], $foo, '... first param must be a Foo instance' ); like( exception { $foo->baz(10) }, qr/\QParameter #1 ("10")/, '... the first param in &baz must be a Foo instance' ); like( exception { $foo->baz('foo') }, qr/\QParameter #1 ("foo")/, '... the first param in &baz must be a Foo instance' ); like( exception { $foo->baz( [] ) }, qr/\QParameter #1/, '... the first param in &baz must be a Foo instance' ); is( $foo->baz( $foo, $foo )->[1], $foo, '... second param must do Roles::Blah' ); like( exception { $foo->baz( $foo, 10 ) }, qr/\QParameter #2 ("10")/, '... the second param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( $foo, 'foo' ) }, qr/\QParameter #2 ("foo")/, '... the second param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( $foo, [] ) }, qr/\QParameter #2/, '... the second param in &baz must be do Roles::Blah' ); is( $foo->baz( $foo, $foo, $foo )->[2], $foo, '... third param must do Roles::Blah' ); like( exception { $foo->baz( $foo, $foo, 10 ) }, qr/\QParameter #3 ("10")/, '... the third param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( $foo, $foo, "foo" ) }, qr/\QParameter #3 ("foo")/, '... the third param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( $foo, $foo, [] ) }, qr/\QParameter #3/, '... the third param in &baz must be do Roles::Blah' ); like( exception { $foo->bar }, qr/\Q0 parameters were passed/, '... bar has a required params' ); like( exception { $foo->bar(10) }, qr/\QParameter #1 ("10")/, '... the first param in &bar must be a Foo instance' ); like( exception { $foo->bar('foo') }, qr/\QParameter #1 ("foo")/, '... the first param in &bar must be a Foo instance' ); like( exception { $foo->bar( [] ) }, qr/\QParameter #1/, '... the first param in &bar must be a Foo instance' ); like( exception { $foo->bar() }, qr/\Q0 parameters were passed/, '... bar has a required first param' ); is_deeply( $foo->bar($foo), [$foo], '... the first param in &bar got a Foo instance' ); is_deeply( $foo->bar( $foo, [] ), [ $foo, [] ], '... the first and second param in &bar got correct args' ); is_deeply( $foo->bar( $foo, {} ), [ $foo, {} ], '... the first param and baz param in &bar got correct args' ); like( exception { $foo->bar( $foo, undef ) }, qr/\QParameter #2 (undef)/, '... second param requires a ArrayRef | HashRef' ); like( exception { $foo->bar( $foo, 10 ) }, qr/\QParameter #2 ("10")/, '... second param requires a ArrayRef | HashRef' ); like( exception { $foo->bar( $foo, 'Foo' ) }, qr/\QParameter #2 ("Foo")/, '... second param requires a ArrayRef | HashRef' ); like( exception { $foo->bar( $foo, \( my $var ) ) }, qr/\QParameter #2/, '... second param requires a ArrayRef | HashRef' ); is_deeply( $foo->bar( $foo, {}, [ 1, 2, 3 ] ), [ $foo, {}, [ 1, 2, 3 ] ], '... the first param in &bar got a Foo instance' ); like( exception { $foo->bar( $foo, {}, undef ) }, qr/\QParameter #3 (undef)/, '... third param a ArrayRef[Int]' ); like( exception { $foo->bar( $foo, {}, 10 ) }, qr/\QParameter #3 ("10")/, '... third param a ArrayRef[Int]' ); like( exception { $foo->bar( $foo, {}, 'Foo' ) }, qr/\QParameter #3 ("Foo")/, '... third param a ArrayRef[Int]' ); like( exception { $foo->bar( $foo, {}, \( my $var ) ) }, qr/\QParameter #3/, '... third param a ArrayRef[Int]' ); like( exception { $foo->bar( $foo, {}, [qw/one two three/] ) }, qr/\QParameter #3/, '... third param a ArrayRef[Int]' ); done_testing(); MooseX-Params-Validate-0.18/t/006_not_moose.t0000644000175000017500000000051712075565774020530 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; eval <<'EOF'; { package Foo; use MooseX::Params::Validate; } EOF is( $@, '', 'loading MX::Params::Validate in a non-Moose class does not blow up' ); ok( Foo->can('validated_hash'), 'validated_hash() sub was added to Foo package' ); done_testing(); MooseX-Params-Validate-0.18/t/release-no-tabs.t0000644000175000017500000000045012075565774021116 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::NoTabs'; plan skip_all => 'Test::NoTabs required' if $@; all_perl_files_ok(); MooseX-Params-Validate-0.18/t/002_basic_list.t0000644000175000017500000001072312075565774020636 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; { package Roles::Blah; use Moose::Role; requires 'foo'; requires 'bar'; requires 'baz'; package Foo; use Moose; use Moose::Util::TypeConstraints; use MooseX::Params::Validate; with 'Roles::Blah'; sub foo { my ( $self, $bar ) = validated_list( \@_, bar => { isa => 'Str', default => 'Moose' }, ); return "Horray for $bar!"; } sub bar { my $self = shift; my ( $foo, $baz ) = validated_list( \@_, foo => { isa => 'Foo' }, baz => { isa => 'ArrayRef | HashRef', optional => 1 }, ); [ $foo, $baz ]; } sub baz { my $self = shift; my ( $foo, $bar, $boo ) = validated_list( \@_, foo => { isa => subtype( 'Object' => where { $_->isa('Foo') } ), optional => 1 }, bar => { does => 'Roles::Blah', optional => 1 }, boo => { does => role_type('Roles::Blah'), optional => 1 }, ); return $foo || $bar || $boo; } } my $foo = Foo->new; isa_ok( $foo, 'Foo' ); is( $foo->foo, 'Horray for Moose!', '... got the right return value' ); is( $foo->foo( bar => 'Rolsky' ), 'Horray for Rolsky!', '... got the right return value' ); is( $foo->baz( foo => $foo ), $foo, '... foo param must be a Foo instance' ); like( exception { $foo->baz( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/, '... the foo param in &baz must be a Foo instance' ); like( exception { $foo->baz( foo => "foo" ) }, qr/\QThe 'foo' parameter ("foo")/, '... the foo param in &baz must be a Foo instance' ); like( exception { $foo->baz( foo => [] ) }, qr/\QThe 'foo' parameter/, '... the foo param in &baz must be a Foo instance' ); is( $foo->baz( bar => $foo ), $foo, '... bar param must do Roles::Blah' ); like( exception { $foo->baz( bar => 10 ) }, qr/\QThe 'bar' parameter ("10")/, '... the bar param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( bar => "foo" ) }, qr/\QThe 'bar' parameter ("foo")/, '... the bar param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( bar => [] ) }, qr/\QThe 'bar' parameter/, '... the bar param in &baz must be do Roles::Blah' ); is( $foo->baz( boo => $foo ), $foo, '... boo param must do Roles::Blah' ); like( exception { $foo->baz( boo => 10 ) }, qr/\QThe 'boo' parameter ("10")/, '... the boo param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( boo => "foo" ) }, qr/\QThe 'boo' parameter ("foo")/, '... the boo param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( boo => [] ) }, qr/\QThe 'boo' parameter/, '... the boo param in &baz must be do Roles::Blah' ); like( exception { $foo->bar }, qr/\QMandatory parameter 'foo'/, '... bar has a required param' ); like( exception { $foo->bar( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/, '... the foo param in &bar must be a Foo instance' ); like( exception { $foo->bar( foo => "foo" ) }, qr/\QThe 'foo' parameter ("foo")/, '... the foo param in &bar must be a Foo instance' ); like( exception { $foo->bar( foo => [] ) }, qr/\QThe 'foo' parameter/, '... the foo param in &bar must be a Foo instance' ); like( exception { $foo->bar( baz => [] ) }, qr/\QMandatory parameter 'foo'/ ); is_deeply( $foo->bar( foo => $foo ), [ $foo, undef ], '... the foo param in &bar got a Foo instance' ); is_deeply( $foo->bar( foo => $foo, baz => [] ), [ $foo, [] ], '... the foo param and baz param in &bar got a correct args' ); is_deeply( $foo->bar( foo => $foo, baz => {} ), [ $foo, {} ], '... the foo param and baz param in &bar got a correct args' ); like( exception { $foo->bar( foo => $foo, baz => undef ) }, qr/\QThe 'baz' parameter (undef)/, '... baz requires a ArrayRef | HashRef' ); like( exception { $foo->bar( foo => $foo, baz => 10 ) }, qr/\QThe 'baz' parameter ("10")/, '... baz requires a ArrayRef | HashRef' ); like( exception { $foo->bar( foo => $foo, baz => 'Foo' ) }, qr/\QThe 'baz' parameter ("Foo")/, '... baz requires a ArrayRef | HashRef' ); like( exception { $foo->bar( foo => $foo, baz => \( my $var ) ) }, qr/\QThe 'baz' parameter/, '... baz requires a ArrayRef | HashRef' ); done_testing(); MooseX-Params-Validate-0.18/t/010_overloaded.t0000644000175000017500000000175312075565774020650 0ustar autarchautarchuse Test::More; use strict; use warnings; { package Foo; use Moose; use MooseX::Params::Validate; use overload ( qw{""} => 'to_string', ); has 'id' => ( is => 'ro', isa => 'Str', default => '1.10.100', ); sub to_string { my ( $self, %args ) = validated_hash( \@_, padded => { isa => 'Bool', optional => 1, default => 0, }, ); # 1.10.100 => 0001.0010.0100 my $id = $args{padded} ? join( '.', map { sprintf( "%04d", $_ ) } split( /\./, $self->id ) ) : $self->id; return $id; } } isa_ok( my $foo = Foo->new(), 'Foo', 'new' ); is( $foo->id, '1.10.100', 'id' ); is( $foo->to_string, '1.10.100', 'to_string' ); is( $foo->to_string( padded => 1 ), '0001.0010.0100', 'to_string( padded => 1 )' ); done_testing(); MooseX-Params-Validate-0.18/t/012_ref_as_first_param.t0000644000175000017500000000170612075565774022352 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; { use MooseX::Params::Validate; sub foo { my ( $x, $y ) = validated_list( \@_, x => { isa => 'Any' }, y => { isa => 'Any' }, ); return { x => $x, y => $y }; } sub bar { my %p = validated_hash( \@_, x => { isa => 'Any' }, y => { isa => 'Any' }, ); return \%p; } } is_deeply( foo( x => 42, y => 84 ), { x => 42, y => 84 }, 'validated_list accepts a plain hash' ); is_deeply( foo( { x => 42, y => 84 } ), { x => 42, y => 84 }, 'validated_list accepts a hash reference' ); is_deeply( bar( x => 42, y => 84 ), { x => 42, y => 84 }, 'validated_hash accepts a plain hash' ); is_deeply( bar( { x => 42, y => 84 } ), { x => 42, y => 84 }, 'validated_hash accepts a hash reference' ); done_testing(); MooseX-Params-Validate-0.18/t/000_load.t0000644000175000017500000000030012075565774017425 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; BEGIN { # this module doesn't export to main package Testing; ::use_ok('MooseX::Params::Validate'); } done_testing(); MooseX-Params-Validate-0.18/t/release-pod-linkcheck.t0000644000175000017500000000077512075565774022300 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; foreach my $env_skip ( qw( SKIP_POD_LINKCHECK ) ){ plan skip_all => "\$ENV{$env_skip} is set, skipping" if $ENV{$env_skip}; } eval "use Test::Pod::LinkCheck"; if ( $@ ) { plan skip_all => 'Test::Pod::LinkCheck required for testing POD'; } else { Test::Pod::LinkCheck->new->all_pod_ok; } MooseX-Params-Validate-0.18/t/release-eol.t0000644000175000017500000000047612075565774020342 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::EOL'; plan skip_all => 'Test::EOL required' if $@; all_perl_files_ok({ trailing_whitespace => 1 }); MooseX-Params-Validate-0.18/t/release-pod-syntax.t0000644000175000017500000000045012075565774021661 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); MooseX-Params-Validate-0.18/t/release-pod-no404s.t0000644000175000017500000000076512075565774021373 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; foreach my $env_skip ( qw( SKIP_POD_NO404S AUTOMATED_TESTING ) ){ plan skip_all => "\$ENV{$env_skip} is set, skipping" if $ENV{$env_skip}; } eval "use Test::Pod::No404s"; if ( $@ ) { plan skip_all => 'Test::Pod::No404s required for testing POD'; } else { all_pod_files_ok(); } MooseX-Params-Validate-0.18/t/004_custom_cache_key.t0000644000175000017500000000265112075565774022032 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; use Scalar::Util; { package Foo; use Moose; use MooseX::Params::Validate; sub bar { my ( $self, $args, $params ) = @_; $params->{MX_PARAMS_VALIDATE_CACHE_KEY} = Scalar::Util::refaddr($self); return validated_hash( $args, %$params ); } } my $foo = Foo->new; isa_ok( $foo, 'Foo' ); is( exception { $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } ); }, undef, '... successfully applied the parameter validation' ); like( exception { $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } ); }, qr/\QThe 'baz' parameter/, '... successfully re-used the parameter validation for this instance' ); my $foo2 = Foo->new; isa_ok( $foo2, 'Foo' ); is( exception { $foo2->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } ); }, undef, '... successfully applied the parameter validation' ); like( exception { $foo2->bar( [ baz => 1 ], { baz => { isa => 'Int' } } ); }, qr/\QThe 'baz' parameter/, '... successfully re-used the parameter validation for this instance' ); is( exception { $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } ); }, undef, '... successfully applied the parameter validation (just checking)' ); done_testing(); MooseX-Params-Validate-0.18/t/release-pod-coverage.t0000644000175000017500000000063512075565774022133 0ustar autarchautarch#!/usr/bin/perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; 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( { trustme => [ qr/^(?:validatep?|import)$/ ] } ); MooseX-Params-Validate-0.18/t/011_allow_extra.t0000644000175000017500000000203612075565774021041 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Fatal; use MooseX::Params::Validate qw( validated_hash ); { sub foo { my %params = validated_hash( \@_, x => { isa => 'Int' }, y => { isa => 'Int' }, ); \%params; } sub bar { my %params = validated_hash( \@_, x => { isa => 'Int' }, y => { isa => 'Int' }, MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1, ); \%params; } } is_deeply( bar( x => 42, y => 1 ), { x => 42, y => 1 }, 'bar returns expected values with no extra params' ); is_deeply( bar( x => 42, y => 1, z => 'whatever' ), { x => 42, y => 1, z => 'whatever' }, 'bar returns expected values with extra params' ); like( exception { foo( x => 42, y => 1, z => 'whatever' ) }, qr/The following parameter .+ listed in the validation options: z/, 'foo rejects extra params' ); done_testing(); MooseX-Params-Validate-0.18/t/001_basic.t0000644000175000017500000001435312075565774017605 0ustar autarchautarch#!/usr/bin/perl use strict; use warnings; use Test::More 0.88; use Test::Fatal; { package Roles::Blah; use Moose::Role; use MooseX::Params::Validate; requires 'bar'; requires 'baz'; sub foo { my ( $self, %params ) = validated_hash( \@_, bar => { isa => 'Str', default => 'Moose' }, ); return "Horray for $params{bar}!"; } package Foo; use Moose; use Moose::Util::TypeConstraints; use MooseX::Params::Validate; with 'Roles::Blah'; sub bar { my $self = shift; my %params = validated_hash( \@_, foo => { isa => 'Foo' }, baz => { isa => 'ArrayRef | HashRef', optional => 1 }, gorch => { isa => 'ArrayRef[Int]', optional => 1 }, ); [ $params{foo}, $params{baz}, $params{gorch} ]; } sub baz { my $self = shift; my %params = validated_hash( \@_, foo => { isa => subtype( 'Object' => where { $_->isa('Foo') } ), optional => 1 }, bar => { does => 'Roles::Blah', optional => 1 }, boo => { does => role_type('Roles::Blah'), optional => 1 }, ); return $params{foo} || $params{bar} || $params{boo}; } sub quux { my $self = shift; my %params = validated_hash( \@_, foo => { isa => 'ArrayRef', callbacks => { 'some random callback' => sub { !ref( $_[0] ) || @{ $_[0] } <= 2 }, }, }, ); return $params{foo}; } } my $foo = Foo->new; isa_ok( $foo, 'Foo' ); is( $foo->foo, 'Horray for Moose!', '... got the right return value' ); is( $foo->foo( bar => 'Rolsky' ), 'Horray for Rolsky!', '... got the right return value' ); is( $foo->baz( foo => $foo ), $foo, '... foo param must be a Foo instance' ); like( exception { $foo->baz( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/, '... the foo param in &baz must be a Foo instance' ); like( exception { $foo->baz( foo => "foo" ) }, qr/\QThe 'foo' parameter ("foo")/, '... the foo param in &baz must be a Foo instance' ); like( exception { $foo->baz( foo => [] ) }, qr/\QThe 'foo' parameter/, '... the foo param in &baz must be a Foo instance' ); is( $foo->baz( bar => $foo ), $foo, '... bar param must do Roles::Blah' ); like( exception { $foo->baz( bar => 10 ) }, qr/\QThe 'bar' parameter ("10")/, '... the bar param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( bar => "foo" ) }, qr/\QThe 'bar' parameter ("foo")/, '... the bar param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( bar => [] ) }, qr/\QThe 'bar' parameter/, '... the bar param in &baz must be do Roles::Blah' ); is( $foo->baz( boo => $foo ), $foo, '... boo param must do Roles::Blah' ); like( exception { $foo->baz( boo => 10 ) }, qr/\QThe 'boo' parameter ("10")/, '... the boo param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( boo => "foo" ) }, qr/\QThe 'boo' parameter ("foo")/, '... the boo param in &baz must be do Roles::Blah' ); like( exception { $foo->baz( boo => [] ) }, qr/\QThe 'boo' parameter/, '... the boo param in &baz must be do Roles::Blah' ); like( exception { $foo->bar }, qr/\QMandatory parameter 'foo'/, '... bar has a required param' ); like( exception { $foo->bar( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/, '... the foo param in &bar must be a Foo instance' ); like( exception { $foo->bar( foo => "foo" ) }, qr/\QThe 'foo' parameter ("foo")/, '... the foo param in &bar must be a Foo instance' ); like( exception { $foo->bar( foo => [] ) }, qr/\QThe 'foo' parameter/, '... the foo param in &bar must be a Foo instance' ); like( exception { $foo->bar( baz => [] ) }, qr/\QMandatory parameter 'foo'/ ); is_deeply( $foo->bar( foo => $foo ), [ $foo, undef, undef ], '... the foo param in &bar got a Foo instance' ); is_deeply( $foo->bar( foo => $foo, baz => [] ), [ $foo, [], undef ], '... the foo param and baz param in &bar got a correct args' ); is_deeply( $foo->bar( foo => $foo, baz => {} ), [ $foo, {}, undef ], '... the foo param and baz param in &bar got a correct args' ); like( exception { $foo->bar( foo => $foo, baz => undef ) }, qr/\QThe 'baz' parameter (undef)/, '... baz requires a ArrayRef | HashRef' ); like( exception { $foo->bar( foo => $foo, baz => 10 ) }, qr/\QThe 'baz' parameter ("10")/, '... baz requires a ArrayRef | HashRef' ); like( exception { $foo->bar( foo => $foo, baz => 'Foo' ) }, qr/\QThe 'baz' parameter ("Foo")/, '... baz requires a ArrayRef | HashRef' ); like( exception { $foo->bar( foo => $foo, baz => \( my $var ) ) }, qr/\QThe 'baz' parameter/, '... baz requires a ArrayRef | HashRef' ); is_deeply( $foo->bar( foo => $foo, gorch => [ 1, 2, 3 ] ), [ $foo, undef, [ 1, 2, 3 ] ], '... the foo param in &bar got a Foo instance' ); like( exception { $foo->bar( foo => $foo, gorch => undef ) }, qr/\QThe 'gorch' parameter (undef)/, '... gorch requires a ArrayRef[Int]' ); like( exception { $foo->bar( foo => $foo, gorch => 10 ) }, qr/\QThe 'gorch' parameter ("10")/, '... gorch requires a ArrayRef[Int]' ); like( exception { $foo->bar( foo => $foo, gorch => 'Foo' ) }, qr/\QThe 'gorch' parameter ("Foo")/, '... gorch requires a ArrayRef[Int]' ); like( exception { $foo->bar( foo => $foo, gorch => \( my $var ) ) }, qr/\QThe 'gorch' parameter/, '... gorch requires a ArrayRef[Int]' ); like( exception { $foo->bar( foo => $foo, gorch => [qw/one two three/] ) }, qr/\QThe 'gorch' parameter/, '... gorch requires a ArrayRef[Int]' ); like( exception { $foo->quux( foo => '123456790' ) }, qr/\QThe 'foo' parameter\E.+\Qchecking type constraint/, '... foo parameter must be an ArrayRef' ); like( exception { $foo->quux( foo => [ 1, 2, 3, 4 ] ) }, qr/\QThe 'foo' parameter\E.+\Qsome random callback/, '... foo parameter additional callback requires that arrayref be 0-2 elements' ); done_testing(); MooseX-Params-Validate-0.18/lib/0000775000175000017500000000000012075565774016256 5ustar autarchautarchMooseX-Params-Validate-0.18/lib/MooseX/0000775000175000017500000000000012075565774017470 5ustar autarchautarchMooseX-Params-Validate-0.18/lib/MooseX/Params/0000775000175000017500000000000012075565774020713 5ustar autarchautarchMooseX-Params-Validate-0.18/lib/MooseX/Params/Validate.pm0000644000175000017500000003310112075565774022776 0ustar autarchautarchpackage MooseX::Params::Validate; { $MooseX::Params::Validate::VERSION = '0.18'; } BEGIN { $MooseX::Params::Validate::AUTHORITY = 'cpan:STEVAN'; } use strict; use warnings; use Carp 'confess'; use Devel::Caller 'caller_cv'; use Scalar::Util 'blessed', 'refaddr', 'reftype'; use Moose 0.58 (); use Moose::Util::TypeConstraints qw( find_type_constraint class_type role_type ); use Params::Validate 0.88 (); use Sub::Exporter -setup => { exports => [ qw( validated_hash validated_list pos_validated_list validate validatep ) ], groups => { default => [qw( validated_hash validated_list pos_validated_list )], deprecated => [qw( validate validatep )], }, }; my %CACHED_SPECS; sub validated_hash { my ( $args, %spec ) = @_; my $cache_key = _cache_key( \%spec ); my $allow_extra = delete $spec{MX_PARAMS_VALIDATE_ALLOW_EXTRA}; if ( exists $CACHED_SPECS{$cache_key} ) { ( ref $CACHED_SPECS{$cache_key} eq 'HASH' ) || confess "I was expecting a HASH-ref in the cached $cache_key parameter" . " spec, you are doing something funky, stop it!"; %spec = %{ $CACHED_SPECS{$cache_key} }; } else { my $should_cache = delete $spec{MX_PARAMS_VALIDATE_NO_CACHE} ? 0 : 1; $spec{$_} = _convert_to_param_validate_spec( $spec{$_} ) foreach keys %spec; $CACHED_SPECS{$cache_key} = \%spec if $should_cache; } my $instance; $instance = shift @$args if blessed $args->[0]; 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; %args = Params::Validate::validate_with( params => \%args, spec => \%spec, allow_extra => $allow_extra, called => _caller_name(), ); return ( ( defined $instance ? $instance : () ), %args ); } *validate = \&validated_hash; sub validated_list { my ( $args, @spec ) = @_; my %spec = @spec; my $cache_key = _cache_key( \%spec ); my $allow_extra = delete $spec{MX_PARAMS_VALIDATE_ALLOW_EXTRA}; my @ordered_spec; if ( exists $CACHED_SPECS{$cache_key} ) { ( ref $CACHED_SPECS{$cache_key} eq 'ARRAY' ) || confess "I was expecting a ARRAY-ref in the cached $cache_key parameter" . " spec, you are doing something funky, stop it!"; %spec = %{ $CACHED_SPECS{$cache_key}->[0] }; @ordered_spec = @{ $CACHED_SPECS{$cache_key}->[1] }; } else { my $should_cache = delete $spec{MX_PARAMS_VALIDATE_NO_CACHE} ? 0 : 1; @ordered_spec = grep { exists $spec{$_} } @spec; $spec{$_} = _convert_to_param_validate_spec( $spec{$_} ) foreach keys %spec; $CACHED_SPECS{$cache_key} = [ \%spec, \@ordered_spec ] if $should_cache; } my $instance; $instance = shift @$args if blessed $args->[0]; 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; %args = Params::Validate::validate_with( params => \%args, spec => \%spec, allow_extra => $allow_extra, called => _caller_name(), ); return ( ( defined $instance ? $instance : () ), @args{@ordered_spec} ); } *validatep = \&validated_list; sub pos_validated_list { my $args = shift; my @spec; push @spec, shift while ref $_[0]; my %extra = @_; my $cache_key = _cache_key( \%extra ); my $allow_extra = delete $extra{MX_PARAMS_VALIDATE_ALLOW_EXTRA}; my @pv_spec; if ( exists $CACHED_SPECS{$cache_key} ) { ( ref $CACHED_SPECS{$cache_key} eq 'ARRAY' ) || confess "I was expecting an ARRAY-ref in the cached $cache_key parameter" . " spec, you are doing something funky, stop it!"; @pv_spec = @{ $CACHED_SPECS{$cache_key} }; } else { my $should_cache = exists $extra{MX_PARAMS_VALIDATE_NO_CACHE} ? 0 : 1; # prepare the parameters ... @pv_spec = map { _convert_to_param_validate_spec($_) } @spec; $CACHED_SPECS{$cache_key} = \@pv_spec if $should_cache; } my @args = @$args; $args[$_] = $pv_spec[$_]{constraint}->coerce( $args[$_] ) for grep { $pv_spec[$_] && $pv_spec[$_]{coerce} } 0 .. $#args; @args = Params::Validate::validate_with( params => \@args, spec => \@pv_spec, allow_extra => $allow_extra, called => _caller_name(), ); return @args; } sub _cache_key { my $spec = shift; if ( exists $spec->{MX_PARAMS_VALIDATE_CACHE_KEY} ) { return delete $spec->{MX_PARAMS_VALIDATE_CACHE_KEY}; } else { return refaddr( caller_cv(2) ); } } sub _convert_to_param_validate_spec { my ($spec) = @_; my %pv_spec; $pv_spec{optional} = $spec->{optional} if exists $spec->{optional}; $pv_spec{default} = $spec->{default} if exists $spec->{default}; $pv_spec{coerce} = $spec->{coerce} if exists $spec->{coerce}; my $constraint; if ( defined $spec->{isa} ) { $constraint = _is_tc( $spec->{isa} ) || Moose::Util::TypeConstraints::find_or_parse_type_constraint( $spec->{isa} ) || class_type( $spec->{isa} ); } elsif ( defined $spec->{does} ) { $constraint = _is_tc( $spec->{isa} ) || find_type_constraint( $spec->{does} ) || role_type( $spec->{does} ); } $pv_spec{callbacks} = $spec->{callbacks} if exists $spec->{callbacks}; if ($constraint) { $pv_spec{constraint} = $constraint; $pv_spec{callbacks} { 'checking type constraint for ' . $constraint->name } = sub { $constraint->check( $_[0] ) }; } delete $pv_spec{coerce} unless $pv_spec{constraint} && $pv_spec{constraint}->has_coercion; return \%pv_spec; } sub _is_tc { my $maybe_tc = shift; return $maybe_tc if defined $maybe_tc && blessed $maybe_tc && $maybe_tc->isa('Moose::Meta::TypeConstraint'); } sub _caller_name { my $depth = shift || 0; return ( caller( 2 + $depth ) )[3]; } 1; # ABSTRACT: an extension of Params::Validate using Moose's types __END__ =pod =head1 NAME MooseX::Params::Validate - an extension of Params::Validate using Moose's types =head1 VERSION version 0.18 =head1 SYNOPSIS package Foo; use Moose; use MooseX::Params::Validate; sub foo { my ( $self, %params ) = validated_hash( \@_, bar => { isa => 'Str', default => 'Moose' }, ); return "Hooray for $params{bar}!"; } sub bar { my $self = shift; my ( $foo, $baz, $gorch ) = validated_list( \@_, foo => { isa => 'Foo' }, baz => { isa => 'ArrayRef | HashRef', optional => 1 }, gorch => { isa => 'ArrayRef[Int]', optional => 1 } ); [ $foo, $baz, $gorch ]; } =head1 DESCRIPTION This module fills a gap in Moose by adding method parameter validation to Moose. This is just one of many developing options, it should not be considered the "official" one by any means though. You might also want to explore C and C. =head1 CAVEATS It is not possible to introspect the method parameter specs; they are created as needed when the method is called and cached for subsequent calls. =head1 EXPORTS =over 4 =item B This behaves similarly to the standard Params::Validate C function and returns the captured values in a HASH. The one exception 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 =item I The C option can be either; class name, Moose type constraint name or an anon Moose type constraint. =item I The C option can be either; role name or an anon Moose type constraint. =item I This is the default value to be used if the value is not supplied. =item I As with Params::Validate, all options are considered required unless otherwise specified. This option is passed directly to Params::Validate. =item I If this is true and the parameter has a type constraint which has coercions, then the coercion will be called for this parameter. If the type does have coercions, then this parameter is ignored. =back This function is also available under its old name, C. =item B 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 ) = validated_list( \@_, foo => { isa => 'Foo' }, bar => { isa => 'Bar' }, ); $foo->baz($bar); } 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. This function is also available under its old name, C. =item B This function validates a list of positional parameters. Each C<$spec> should validate one of the parameters in the list: sub foo { my $self = shift; my ( $foo, $bar ) = pos_validated_list( \@_, { isa => 'Foo' }, { isa => 'Bar' }, ); ... } 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. If you want to pass in any of the cache control parameters described below, simply pass them after the list of parameter validation specs: sub foo { my $self = shift; my ( $foo, $bar ) = pos_validated_list( \@_, { isa => 'Foo' }, { isa => 'Bar' }, MX_PARAMS_VALIDATE_NO_CACHE => 1, ); ... } =back =head1 ALLOWING EXTRA PARAMETERS By default, any parameters not mentioned in the parameter spec cause this module to throw an error. However, you can have have this module simply ignore them by setting C to a true value when calling a validation subroutine. When calling C or C the extra parameters are simply returned in the hash or list as appropriate. However, when you call C the extra parameters will not be returned at all. You can get them by looking at the original value of C<@_>. =head1 EXPORTS By default, this module exports the C, C, and C. If you would prefer to import the now deprecated functions C and C instead, you can use the C<:deprecated> tag to import them. =head1 IMPORTANT NOTE ON CACHING When a validation subroutine is called the first time, the parameter spec is prepared and cached to avoid unnecessary regeneration. It uses the fully qualified name of the subroutine (package + subname) as the cache key. In 99.999% of the use cases for this module, that will be the right thing to do. However, I have (ab)used this module occasionally to handle dynamic sets of parameters. In this special use case you can do a couple things to better control the caching behavior. =over 4 =item * Passing in the C flag in the parameter spec this will prevent the parameter spec from being cached. sub foo { my ( $self, %params ) = validated_hash( \@_, foo => { isa => 'Foo' }, MX_PARAMS_VALIDATE_NO_CACHE => 1, ); } =item * Passing in C with a value to be used as the cache key will bypass the normal cache key generation. sub foo { my ( $self, %params ) = validated_hash( \@_, foo => { isa => 'Foo' }, MX_PARAMS_VALIDATE_CACHE_KEY => 'foo-42', ); } =back =head1 MAINTAINER Dave Rolsky Eautarch@urth.orgE =head1 BUGS 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. =head1 AUTHORS =over 4 =item * Stevan Little =item * Dave Rolsky =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Stevan Little . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut MooseX-Params-Validate-0.18/README0000644000175000017500000000055112075565774016367 0ustar autarchautarch This archive contains the distribution MooseX-Params-Validate, version 0.18: an extension of Params::Validate using Moose's types This software is copyright (c) 2013 by Stevan Little . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. MooseX-Params-Validate-0.18/LICENSE0000644000175000017500000004402112075565774016514 0ustar autarchautarchThis software is copyright (c) 2013 by Stevan Little . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Stevan Little . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Stevan Little . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MooseX-Params-Validate-0.18/META.yml0000644000175000017500000000161012075565774016755 0ustar autarchautarch--- abstract: "an extension of Params::Validate using Moose's types" author: - 'Stevan Little ' - 'Dave Rolsky ' build_requires: Moose::Role: 0 Test::Fatal: 0 Test::More: 0.88 overload: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300028, CPAN::Meta::Converter version 2.120921' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-Params-Validate requires: Carp: 0 Devel::Caller: 0 Moose: 0.58 Moose::Util::TypeConstraints: 0 Params::Validate: 0.88 Scalar::Util: 0 Sub::Exporter: 0 strict: 0 warnings: 0 resources: bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX::Params::Validate repository: git://git.moose.perl.org/MooseX-Params-Validate.git version: 0.18 x_authority: cpan:STEVAN MooseX-Params-Validate-0.18/Makefile.PL0000644000175000017500000000254612075565774017467 0ustar autarchautarch use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "an extension of Params::Validate using Moose's types", "AUTHOR" => "Stevan Little , Dave Rolsky ", "BUILD_REQUIRES" => { "Moose::Role" => 0, "Test::Fatal" => 0, "Test::More" => "0.88", "overload" => 0 }, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "MooseX-Params-Validate", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "MooseX::Params::Validate", "PREREQ_PM" => { "Carp" => 0, "Devel::Caller" => 0, "Moose" => "0.58", "Moose::Util::TypeConstraints" => 0, "Params::Validate" => "0.88", "Scalar::Util" => 0, "Sub::Exporter" => 0, "strict" => 0, "warnings" => 0 }, "VERSION" => "0.18", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); MooseX-Params-Validate-0.18/Changes0000644000175000017500000000652612075565774017012 0ustar autarchautarch0.18 2013-01-16 - Fix broken prereq specification in 0.17. Reported by Justin Hunter. 0.17 2013-01-16 - Fix tests that broke with new hash randomization in 5.17.6. (Dagfinn Ilmari Mannsåker) 0.16 2011-01-29 - The validated_list and validated_hash functions now accept the values to be validated as both a hash and a hash reference. 0.15 2010-11-29 - Add MX_PARAMS_VALIDATE_ALLOW_EXTRA which allows extra parameters in validation calls (like allow_extra for Params::Validate). - Converted to Test::Fatal. 0.14 2010-03-18 - The validated_hash method failed when called on in an overloaded stringify method. Patch by Ian Sillitoe. RT #52565. 0.13 2009-11-29 - 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 2009-07-07 - Using the subroutine name as a cache key for validation specs broke in the face of method modifiers, which all appear to have the same name. Now we use Devel::Caller to get the CV of the caller and use its refaddr as the key, which will be unique in all cases. Bug report by Jos Boumans. RT #46730. 0.11 2009-07-07 - The validation functions tried to coerce optional keys which weren't present in the incoming parameters, leading to weird errors. Based on a patch from Jos Boumans. RT #46344. - Allow other callbacks to be specified. Previously these were silently thrown out. But we'd recommend just defining types that encapsulate everything in the callback instead. Based on a patch from Jos Boumans. RT #47647. 0.10 2009-06-30 - Shut up deprecation warnings from the tests. Reported by John Goulah. 0.09 2009-02-01 - The subroutine name being reported in error messages was screwy. 0.08 2009-02-01 - Renamed validate to validated_hash and validatep to validated_list. The old function names are still available under the ":deprecated" import tag. - Added a new pos_validated_list which can validate position parameters. - Errors now reflect the subroutine that called the validation function, rather than coming form inside the validation function itself. 0.07 2008-09-21 - No code changes, just fixing missing prereqs (Dave Rolsky) 0.06 2008-09-20 - Fixes to work with Moose 0.58 (Dave Rolsky) - Switched to using Module::Install (Dave Rolsky) 0.05 2008-03-07 - This package would cause a fatal error if loaded by a non-Moose class (Dave Rolsky) - added tests for this (Dave Rolsky) - Added support for coercions (Dave Rolsky) 0.04 2008-01-08 - upped the Moose dependency and added support for the new improved Moose type constraints - added tests for this - adding caching of the prepared parameter specs, this results in approx. 3x speedup using rough benchmarks. - added special caching handlers see the IMPORTANT NOTE ON CACHING section of the POD for more details - added tests for this 0.03 2007-06-08 - added support for using this within role methods too. 0.02 2007-04-25 - added validatep, which returns the captured args as positional instead of as hash - added docs and tests 0.01 2007-04-18 - trying to fill a gap, we will see ... MooseX-Params-Validate-0.18/META.json0000644000175000017500000000340312075565774017127 0ustar autarchautarch{ "abstract" : "an extension of Params::Validate using Moose's types", "author" : [ "Stevan Little ", "Dave Rolsky " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300028, CPAN::Meta::Converter version 2.120921", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-Params-Validate", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Carp" : "0", "Devel::Caller" : "0", "Moose" : "0.58", "Moose::Util::TypeConstraints" : "0", "Params::Validate" : "0.88", "Scalar::Util" : "0", "Sub::Exporter" : "0", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Moose::Role" : "0", "Test::Fatal" : "0", "Test::More" : "0.88", "overload" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-datetime@rt.cpan.org", "web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX::Params::Validate" }, "repository" : { "type" : "git", "url" : "git://git.moose.perl.org/MooseX-Params-Validate.git", "web" : "http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/MooseX-Params-Validate.git" } }, "version" : "0.18", "x_authority" : "cpan:STEVAN" } MooseX-Params-Validate-0.18/INSTALL0000644000175000017500000000200412075565774016533 0ustar autarchautarch This is the Perl distribution MooseX-Params-Validate. Installing MooseX-Params-Validate is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm MooseX::Params::Validate If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S MooseX::Params::Validate ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan MooseX::Params::Validate ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation MooseX-Params-Validate documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc MooseX::Params::Validate MooseX-Params-Validate-0.18/dist.ini0000644000175000017500000000160512075565774017154 0ustar autarchautarchname = MooseX-Params-Validate author = Stevan Little author = Dave Rolsky license = Perl_5 copyright_holder = Stevan Little copyright_year = 2013 version = 0.18 [Authority] authority = cpan:STEVAN [NextRelease] format = %-4v %{yyyy-MM-dd}d [@Basic] [InstallGuide] [MetaJSON] [MetaResources] bugtracker.web = http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX::Params::Validate bugtracker.mailto = bug-datetime@rt.cpan.org repository.url = git://git.moose.perl.org/MooseX-Params-Validate.git repository.web = http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/MooseX-Params-Validate.git repository.type = git [SurgicalPodWeaver] [PkgVersion] [EOLTests] [NoTabsTests] [PodSyntaxTests] [Test::Pod::LinkCheck] [Test::Pod::No404s] [AutoPrereqs] skip = ^Roles::Blah$ [CheckPrereqsIndexed] [@Git]