Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the YAML CPAN distribution.

Report information
The Basics
Id: 29114
Status: resolved
Priority: 0/
Queue: YAML

People
Owner: ingy [...] cpan.org
Requestors: rafl [...] debian.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.65
Fixed in: (no value)



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.
Attached is a one-line patch to resolve this issue.
--- .perl/share/perl5/YAML/Types.pm 2007-09-02 22:06:39.580599432 +0200 +++ Types.pm 2007-09-02 22:06:46.576575003 +0200 @@ -157,6 +157,7 @@ } } else { + return CORE::bless sub {}, $class if $class; return sub {}; } }
applied rafl's patch for 0.66