Subject: | validation compilation fails with Moose enum type |
If a Moose enum type is used as a validation type, compiling fails. Example script with error attached.
Subject: | vc-enum.pl |
use strict;
use warnings;
use Moose::Util::TypeConstraints qw(enum);
use Params::CheckCompiler qw(validation_for);
my $check = validation_for(
params => {
format => { type => enum [qw(RSS Atom)] },
},
);
$check->(format => 'Atom');
__END__
Failed to compile source: Global symbol "%enums0" requires explicit package name (did you forget to declare "my %enums0"?) at (eval 92) line 56.
source:
sub { my %args;
if ( @_ % 2 == 0 ) {
%args = @_;
}
elsif ( @_ == 1 ) {
if ( ref $_[0] ) {
if ( Scalar::Util::blessed( $_[0] ) ) {
if ( overload::Overloaded( $_[0] )
&& defined overload::Method( $_[0], '%{}' ) ) {
%args = %{ $_[0] };
}
else {
Params::CheckCompiler::Exception::BadArguments->throw(
message =>
'Expected a hash or hash reference but got a single object argument'
);
}
}
elsif ( Scalar::Util::reftype( $_[0] ) eq 'HASH' ) {
%args = %{ $_[0] };
}
else {
Params::CheckCompiler::Exception::BadArguments->throw(
message =>
'Expected a hash or hash reference but got a single '
. ( Scalar::Util::reftype( $_[0] ) )
. ' reference argument',
);
}
}
else {
Params::CheckCompiler::Exception::BadArguments->throw(
message =>
'Expected a hash or hash reference but got a single non-reference argument',
);
}
}
else {
Params::CheckCompiler::Exception::BadArguments->throw(
message =>
'Expected a hash or hash reference but got an odd number of arguments',
);
}
exists $args{"format"}
or Params::CheckCompiler::Exception::Named::Required->throw(
message => "format" . ' is a required parameter',
parameter => "format",
);
if ( !( do { defined($args{"format"}) && !ref($args{"format"}) && $enums0{$args{"format"}} } ) ) {
my $type = $types{"format"};
my $msg = $type->get_message($args{"format"});
die
Params::CheckCompiler::Exception::ValidationFailedForMooseTypeConstraint
->new(
message => $msg,
parameter => 'The ' . "format" . ' parameter',
value => $args{"format"},
type => $type,
);
}
my @extra = grep { ! $known{$_} } keys %args;
if ( @extra ) {
my $u = join ', ', sort @extra;
Params::CheckCompiler::Exception::Named::Extra->throw(
message => "found extra parameters: [$u]",
parameters => \@extra,
);
}
return %args; }; at /Users/gknop/perl5/libs/5.024000-darwin-2level/lib/perl5/Params/CheckCompiler/Compiler.pm line 52.