Subject: | compilation error for function signatures with Moose enum TypeConstraints |
~$ perl -e '{ package My::Shapes; BEGIN { use Moose::Util::TypeConstraints qw( enum ); enum 'ColorEnum' => [ qw( white black brown ) ]; } use strict; use warnings; use Moose; use Kavorka qw( fun ); fun print_color(ColorEnum :$color!) { print "$color\n"; } has "color" => ( is=> "ro", isa=> "ColorEnum" ); }'
Global symbol "%enums0" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
vs
sburton@d01:~/kavorka-test$ perl -e '{ package My::Shapes; BEGIN { use Moose::Util::TypeConstraints qw( enum ); enum 'ColorEnum' => [ qw( white black brown ) ]; } use strict; use warnings; use Moose; use Kavorka qw( fun ); fun print_color(Str :$color!) { print "$color\n"; } has "color" => ( is=> "ro", isa=> "ColorEnum" ); }'
the issue seems to be that the inline_environment that is necessary to initialize %enums0 is not drawn into the code being inlined in Type::Tiny
{
'Type::Tiny->inlined' => '( do { defined($color) && !ref($color) && $enums0{$color} } )'
}
at p5-type-tiny/lib/Type/Tiny.pm line 868.
Type::Tiny::inline_assert(Type::Tiny=HASH(0x442ee30), "\$color") called at /usr/local/share/perl/5.20.2/Kavorka/Parameter.pm line 612
Kavorka::Parameter::_injection_type_check(Kavorka::Parameter=HASH(0x4207ea0), "\$color") called at /usr/local/share/perl/5.20.2/Kavorka/Parameter.pm line 379
Kavorka::Parameter::_injection_conditional_type_check(Kavorka::Parameter=HASH(0x4207ea0), Kavorka::Signature=HASH(0x3366b30), "exists(\$_{\"color\"})", "\$color") called at /usr/local/share/perl/5.20.2/Kavorka/Parameter.pm line 349
Kavorka::Parameter::injection(Kavorka::Parameter=HASH(0x4207ea0), Kavorka::Signature=HASH(0x3366b30)) called at /usr/local/share/perl/5.20.2/Kavorka/Signature.pm line 346
Kavorka::Signature::_injection_named_params(Kavorka::Signature=HASH(0x3366b30)) called at /usr/local/share/perl/5.20.2/Kavorka/Signature.pm line 202
Kavorka::Signature::injection(Kavorka::Signature=HASH(0x3366b30)) called at /usr/local/share/perl/5.20.2/Kavorka/Sub.pm line 96
Kavorka::Sub::inject_prelude(Kavorka::Sub::Fun=HASH(0x31ea148)) called at /usr/local/share/perl/5.20.2/Kavorka/Sub.pm line 369
Kavorka::Sub::parse_body(Kavorka::Sub::Fun=HASH(0x31ea148)) called at /usr/local/share/perl/5.20.2/Kavorka/Sub.pm line 154
Kavorka::Sub::parse("Kavorka::Sub::Fun", "keyword", "fun") called at /usr/local/share/perl/5.20.2/Kavorka.pm line 187
Kavorka::parse_fun("fun") called at -e line 1
i hope i have provided enough context and detail. if not, let me know.
TIA