I have a set of objects that I am using Storable with to thaw and pass over a network to be unthawed and used. Occasionally, one of these objects will contain a cached database handle that gets serialized with the rest of the data. When this is subsequently thawed and eventually destroyed on the remote end, I get all sorts of nasty DBI errors about how the RV is not "magic" and does not refer to a valid database handle. The database handle will not be used on the remote end (naturally).

My thought then was to take advantage of the Storable hooks, and simply write one for DBI::db that passed back a string "Lost DBI ref $ref" along the same lines that setting $Storable::forgive_me allows a simple "lost data" string to appear in place of file handles or other un-storable data. This is how I approached it:

sub DBI::db::STORABLE_freeze { my ($self, $cloning) = @_; return if $cloning; return "Lost DBI ref $self"; }
When executing with this subroutine in place, however, I get this error message:
Unexpected object type (4) in store_hook() at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_freeze.al) line 234, at script-name.pl line 58
Both this error message and store_hook() itself appear to be in the .so for Storable, not in any of the Perl code, so short of downloading the source (which is my next logical step, after this), it's difficult to see what it's talking about. The documentation only mentions that hooks need to return a "serialized version" of the object being passed. I have also tried returning other things:
return freeze("string"); # probably 'cause it's not a ref my $$msg = "string"; return freeze($msg); # still no-go
I'm guessing the "serialized version" needs to be a little more "serialized" than this, but how do I need to go about doing this?

In reply to Avoiding DBI handles with Storable by Fastolfe

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, details, 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, summary, 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.