Subject: | Inline !!perl/code broken |
The following code, which tries to Load() a serialized coderef fails:
perl -MExtUtils::testlib -MYAML -e'$YAML::LoadCode = 1;
$c = YAML::Load(<<EOY);
--- !!perl/code "{ print q{foo} }"
EOY'
resulting in the following error message:
Illegal character in prototype for main::CODE : 0x83f7bd8 at (eval 33)
line 1.
stack trace:
Illegal character in prototype for main::CODE : 0x83dd4d8 at (eval 33)
line 1
eval 'package main; sub CODE(0x83dd4d8)
;' called at /home/rafl/.perl/share/perl5/YAML/Types.pm line 149
YAML::Type::code::yaml_load('YAML::Type::code',
'CODE(0x83dd4d8)', '', 'YAML::Loader=HASH(0x80bd4d4)') called at
/home/rafl/.perl/share/perl5/YAML/Loader.pm line 281
YAML::Loader::_parse_explicit('YAML::Loader=HASH(0x80bd4d4)',
'CODE(0x83dd4d8)', '!perl/code') called at
/home/rafl/.perl/share/perl5/YAML/Loader.pm line 195
YAML::Loader::_parse_node('YAML::Loader=HASH(0x80bd4d4)') called
at /home/rafl/.perl/share/perl5/YAML/Loader.pm line 100
YAML::Loader::_parse('YAML::Loader=HASH(0x80bd4d4)') called at
/home/rafl/.perl/share/perl5/YAML/Loader.pm line 22
YAML::Loader::load('YAML::Loader=HASH(0x80bd4d4)', '---
!!perl/code "{ print q{foo} }"\x{a}') called at
/home/rafl/.perl/share/perl5/YAML.pm line 33
YAML::Load('--- !!perl/code "{ print q{foo} }"\x{a}') called at
-e line 2
eval "package main; sub CODE(0xaddr);" seems to indicate that you're
trying to turn the string containing the code into a coderef twice. Some
debugging showed that this is indeed the case:
_parse_node calls _parse_inline, which in turn calls _parse_explicit,
which does the first eval and assigns the returned coderef to the
current $node. Later on _parse_node calls _parse_explict again which
then fails as
eval "package main; sub $node" stringifies node, which is a coderef
already, and leads to broken perl code and the above error.
The following form works nevertheless:
-- !!perl/code |
{
print q{foo}
}