Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I've just started using Storable heavily for the first time, to implement server-abstracted storable SQL queries. By heavily I mean I need to play a lot of games with STORABLE_freeze/thaw hooks to let some fairly complex internal structures store correctly.

Now unfortunately STORABLE_thaw, rather than just giving you the class name to create an object of, "helpfully" creates an empty (and of course invalid) "object", which it expects you to fill and correct so that it becomes a valid object.

It also runs in void context, and returns via the passed argument, which isn't very Perlish at all.

Unfortunately, this "helpfulness" makes STORABLE_thaw completely useless for things like Singletons or classes with pools of objects, since you can't correct the link to refer to the Singleton (you are just left with an empty, invalid and broken object).

There are a number of bugs in rt.cpan.org relating to this problem, and I've taken it on myself to resolve the problem, as it is hurting me badly. I've defined the new behaviour I think STORABLE_thaw should have as

1. STORABLE_thaw called in scalar rather than void context

2. If and only if STORABLE_thaw returns a _different_ object from the empty one passed in, that also isa() in the same package, use THAT object in the thawed version instead.


This change is functionally back-compatible, but will this break anything? Using File::Find::Rule::PPI to find every STORABLE_thaw subroutine in a minicpan checkout, I found that 2/3rds of them do either "return self;" or "return;" for safety sake and will thus act sanely, and the rest don't appear to be able to race easily (I've filed rt.cpan.org bugs against them detailing the one line change just in case).

After that long intro, my question is... "Is there anything else I can do to ensure a clean changeover to the new behaviour, assuming I can convince the Storable maintainers to accept the patch."

Update
See http://rt.cpan.org/NoAuth/Bug.html?id=4901 for ongoing progress of the proposal to change STORABLE_thaw

In reply to Safely altering the behaviour of heavily used modules by adamk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (5)
    As of 2020-06-03 22:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?



      Results (29 votes). Check out past polls.

      Notices?