1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
## no critic (Moose::RequireCleanNamespace, Modules::ProhibitMultiplePackages, Moose::RequireMakeImmutable)
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();
|