Subject: | inconsistent behaviour regarding coderefs and blessed coderefs with $YAML::LoadCode = 0 |
perl -MB::Deparse -MYAML -le'$YAML::LoadCode = 1;
$c = YAML::Load(<<EOY);
--- !!perl/code |
{
print "foo"
}
EOY
print B::Deparse->new->coderef2text($c); print ref $c'
the above code yields the following output:
{
use warnings;
use strict 'refs';
print 'foo';
}
CODE
This is perfectly fine and exactly what I'd expect.
if you change the yaml to represent a blessed code reference it also
does exactly what I'd like it to:
--- !!perl/code:Some::Class |
{
print 'foo'
}
will turn into
{
use warnings;
use strict 'refs';
print 'foo';
}
Some::Class
Now we're turning $YAML::LoadCode off and give it the same YAML as in
the first example. Load() will return the following code, which
basically is 'sub { }':
{
package YAML::Type::code;
use warnings;
use strict 'refs';
}
CODE
Everything is fine so far. However, the next snippet, which tries to
load a blessed code reference with LoadCode turned off behaves different
to what one would expect given the above three examples:
perl -MB::Deparse -MYAML -le'$YAML::LoadCode = 0;
$c = YAML::Load(<<EOY);
--- !!perl/code:Some::Class |
{
print "foo"
}
EOY
print B::Deparse->new->coderef2text($c); print ref $c'
outputs:
{
package YAML::Type::code;
use warnings;
use strict 'refs';
}
CODE
so I still get an empty sub { }, but YAML doesn't bless it into
Some::Class for me like I want it to.