Skip Menu |

This queue is for tickets about the YAML-Tiny CPAN distribution.

Report information
The Basics
Id: 65260
Status: open
Priority: 0/
Queue: YAML-Tiny

People
Owner: Nobody in particular
Requestors: CHORNY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: stringification
I'd like to have possibility to stringify an object when writing YAML, in my case created by version.pm. It can be implemented as an a parameter for write/write_string methods. -- Alexandr Ciornii, http://chorny.net
Subject: Re: [rt.cpan.org #65260] stringification
Date: Mon, 31 Jan 2011 21:33:39 +1100
To: bug-YAML-Tiny [...] rt.cpan.org
From: Adam Kennedy <adamkennedybackup [...] gmail.com>
How do you propose to distinguish between things that should be stringified, and those that are an error? Adam K On 31 January 2011 04:02, Alexandr Ciornii via RT <bug-YAML-Tiny@rt.cpan.org> wrote: Show quoted text
> Sun Jan 30 12:02:33 2011: Request 65260 was acted upon. > Transaction: Ticket created by CHORNY >       Queue: YAML-Tiny >     Subject: stringification >   Broken in: (no value) >    Severity: Wishlist >       Owner: Nobody >  Requestors: CHORNY@cpan.org >      Status: new >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=65260 > > > > I'd like to have possibility to stringify an object when writing YAML, > in my case created by version.pm. It can be implemented as an a > parameter for write/write_string methods. > > -- > Alexandr Ciornii, http://chorny.net > >
On Mon Jan 31 05:33:48 2011, adam@ali.as wrote: Show quoted text
> How do you propose to distinguish between things that should be > stringified, and those that are an error?
For ex. stringify => ['version']. Or just stringify all objects, in many cases it would be enough. In my case of writing META.yml/MYMETA.yml in EU::MM, I expect only version.pm objects. -- Alexandr Ciornii, http://chorny.net
I think it would be reasonable to serialize objects as a string if they overload stringification. I can see this useful for version objects, file path objects, URI objects, datetime objects, exception objects (??). One possibility might be to emulate JSON and check if the object has a TO_YAML method. Then users could do the { local *UNIVERSAL::TO_YAML = sub { "$_[0]" }; DumpFile(...) } trick if they want every object stringified, or could implement something more nuanced for their own needs. That keeps the logic out of YAML::Tiny and avoids an "all or nothing" solution like YAML.pm offers with the global "$YAML::Stringify" variable. It would be a 2 or 3 line change, so pretty trivial to implement.