Date: | Sun, 17 Apr 2005 19:27:27 +0200 |
From: | Jan Hudec <bulb [...] cpan.org> |
To: | bug-YAML [...] rt.cpan.org |
Subject: | [patch] YAML - make it work with overloaded stringify |
Hello,
I have found a problem, that YAML perl module can't properly serialize
objects with overloaded stringification. It serializes the
stringification instead of the object.
I have tracked this down to the YAML::Node::info sub, which uses regexp
match to find the package, base type and address, which does not work if
stringification is overloaded.
Simple fix to this is using following patch:
--- libyaml-perl-0.38/lib/YAML/Node.pm.org 2005-02-24 17:07:07.000000000 +0100
+++ libyaml-perl-0.38/lib/YAML/Node.pm 2005-04-17 17:51:16.000000000 +0200
@@ -23,7 +23,8 @@
}
sub info {
- ($_[0] =~ qr{^(?:(.*)\=)?([^=]*)\(([^\(]*)\)$}o);
+ require overload;
+ (overload::StrVal($_[0]) =~ qr{^(?:(.*)\=)?([^=]*)\(([^\(]*)\)$}o);
}
sub new {
*** END OF PATCH ***
For modern perls, where Scalar::Util is available, it would be better
(read a bit faster) to use:
(
Scalar::Util::blessed($_[0]),
Scalar::Util::reftype($_[0]),
Scalar::Util::refaddr($_[0]),
)
as it is what overload::StrVal does internally anyway. But
Scalar::Util is not available back to perl 5.005_03, so I expect you
would prefer the first solution.
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@ucw.cz>
Message body not shown because it is not plain text.