Skip Menu |

This queue is for tickets about the Data-Rmap CPAN distribution.

Report information
The Basics
Id: 73550
Status: open
Priority: 0/
Queue: Data-Rmap

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

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



Subject: Support for CODEREF?
I needed to convert all coderefs to a string (e.g. "<CODE>") to safely pass a data structure to JSON encoder, but none of the rmap_* functions seem to have coderef support.
Subject: Re: [rt.cpan.org #73550] Support for CODEREF?
Date: Fri, 30 Dec 2011 12:21:23 +1100
To: bug-Data-Rmap [...] rt.cpan.org
From: bugs [...] bereft.net
Hello Steven, On 29/12/11 19:47, steven haryanto via RT wrote: [..] Show quoted text
> > I needed to convert all coderefs to a string (e.g. "<CODE>") to safely > pass a data structure to JSON encoder, but none of the rmap_* functions > seem to have coderef support. >
I do have a comment from long ago in the code: # Others like CODE, Regex, etc are ignored but I can't see why that would have to be the case... Your use case sounds reasonable. (Urgh, going through my ancient code is horrible) I've added in CODE and rmap_code, but think I have to leave code refs out of ALL for compatibility. I've added your example to: https://github.com/bowman/Data-Rmap # replace CODE with "<CODE>" $ perl -MData::Rmap=:all -E 'say join ":", rmap_code { "<CODE>" } sub{},sub{}' <CODE>:<CODE> So please have a look and test. I'll release it soon. Thanks for your suggestion, Brad Brad
On Thu Dec 29 20:21:46 2011, bugs@bereft.net wrote: Show quoted text
> > Hello Steven, > > On 29/12/11 19:47, steven haryanto via RT wrote: > [..]
> > > > I needed to convert all coderefs to a string (e.g. "<CODE>") to
> safely
> > pass a data structure to JSON encoder, but none of the rmap_*
> functions
> > seem to have coderef support. > >
> > I do have a comment from long ago in the code: > > # Others like CODE, Regex, etc are ignored > > but I can't see why that would have to be the case... > Your use case sounds reasonable. > > (Urgh, going through my ancient code is horrible) > > I've added in CODE and rmap_code, but think I have to leave code refs > out of ALL for compatibility. I've added your example to: > > https://github.com/bowman/Data-Rmap > > # replace CODE with "<CODE>" > $ perl -MData::Rmap=:all -E 'say join ":", rmap_code { "<CODE>" } > sub{},sub{}' > <CODE>:<CODE> > > So please have a look and test. I'll release it soon. > > Thanks for your suggestion, > > Brad > Brad
Hi Brad, Wow, not expecting a prompt reply! Thanks a lot for implementing this. Also, please consider adding an option for rmap_all (or some other new function) to get *all* kinds of data, be it Regexp and others. I actually did once or twice having to search and replace all qr// objects into its stringified form, again for passing to subsystems outside of Perl. The ability to get all weird and Perl-specific objects *is* the important factor here. Regards, Steven
Subject: Re: [rt.cpan.org #73550] Support for CODEREF?
Date: Fri, 30 Dec 2011 14:14:13 +1100
To: bug-Data-Rmap [...] rt.cpan.org
From: bugs [...] bereft.net
On 30/12/11 12:42, steven haryanto via RT wrote: Show quoted text
> > Wow, not expecting a prompt reply! Thanks a lot for implementing this. > > Also, please consider adding an option for rmap_all (or some other new > function) to get *all* kinds of data, be it Regexp and others. I > actually did once or twice having to search and replace all qr// > objects into its stringified form, again for passing to subsystems > outside of Perl. The ability to get all weird and Perl-specific objects > *is* the important factor here.
REGEXP and IO seem to be the only ones left out (looking at Scalar::Util::PP). Does that seem exhaustive to you? VALUE HASH ARRAY SCALAR REF GLOB CODE REGEXP IO Adding flag for REGEXP and IO would probably be ok. ... I poked around and reftype(qr//) eq 'SCALAR' (even though ref(qr//) eq 'Regexp'). So qr// can already be handled. Similarly, IO thingys are only via GLOBs or REFs anyway, I think..? $ perl -Ilib -MData::Rmap=:all -wle \ 'print join " ", rmap_to { ref($_) } (ALL), qr//, \*STDOUT' Regexp GLOB SCALAR perl -Ilib -MDevel::Peek -MData::Rmap=:all \ -wle 'rmap_to { Dump($_{IO}) } ALL, \*STDOUT' # outputs a big complicated thing with IO magic GLOBs have a FORMAT slot, but I don't want to go there... So given that little investigation, I might leave things alone. Thanks for the feedback, Brad
On Thu Dec 29 22:14:41 2011, bugs@bereft.net wrote: Show quoted text
> GLOBs have a FORMAT slot, but I don't want to go there...
In case you ever change your mind, you might want to look at Data::Dump::Streamer, which can dump formats.