Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: storable.pm+CODE refs

by darobin (Monk)
on Mar 28, 2001 at 00:22 UTC ( #67621=note: print w/ replies, xml ) Need Help??


in reply to storable.pm+CODE refs

I've been thinking about this for a while... I think that it ought to be possible using B::Deparse.

According to the doc:

use B::Deparse; $deparse = B::Deparse->new("-p", "-sC"); $body = $deparse->coderef2text(\&func); eval "sub func $body"; # the inverse operation

So it should be possible to store the coderef as text along with something to indicate that it's a coderef (and it's name, if it has one). On thaw it would simply eval it.

Note that you can probably already do this without touching Storable. IIRC, before freeze()/thaw()ing Storable will try to call STORABLE_{freeze,thaw} in your namespace. You can use that as a filter mechanism.

-- darobin


Comment on Re: storable.pm+CODE refs
Download Code
(tye)Re2: storable.pm+CODE refs
by tye (Cardinal) on Mar 28, 2001 at 02:33 UTC

    Deparse isn't perfect (I recall examples of code that it doesn't deparse correctly) and there is still the issue of how to recreate a closure.

            - tye (but my friends call me "Tye")

      Yes I know, obvioulsy if the solution was perfect someone would have done it already :)

      However it can imho be a good place to look at given a certain level of simplicity, and may be a good place to watch for future updates on that front.

      -- darobin

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://67621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-10-26 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (151 votes), past polls