Regarding the equivelent to Storable, just use the Freeze()/Thaw() method (as per Data::Dumper) to register the method. Im reluctant to hard code the method names as I dont think it scales well.

use DDS; sub Popsicle::Freeze { my ($self)=@_; $_[0]=bless \do{my $x=join "-",@$self},ref $self; } sub Popsicle::Thaw { my ($self)=@_; $_[0]=bless [ map {split /-/,$_ } $$self ],ref $self; } my $ig=bless ["A".."C"],"Popsicle"; my %h=(One=>1,Two=>2,Three=>$ig); # "fix" statement thaw... Dump->Names('first') ->FreezeClass('Popsicle'=>'Freeze') ->ThawClass('Popsicle'=>'Thaw') ->Data( \%h )->Out; print "\n"; # inline thaw.... Dump->Names('second') ->FreezeClass('Popsicle'=>'Freeze') ->ThawClass('Popsicle'=>'->Thaw') ->Data( \%h )->Out; print "\n"; # clear the hooks for Popsicle Dump->Names('third') ->FreezeClass('Popsicle'=>'') ->ThawClass('Popsicle'=>'') ->Data( \%h )->Out; print "\n"; # Using FreezeThaw to make it a bit easier... Dump->Names('fourth') ->FreezeThaw('Popsicle'=>'Freeze','->Thaw') ->Data( \%h )->Out; print "\n"; # Using generic hooks and not class specific ones Dump->Names('fifth') ->Freeze('Freeze') ->Thaw('->Thaw') ->Data( \%h )->Out; print "\n"; __END__ $first = { One => 1, Three => bless( \do { my $v = 'A-B-C' }, 'Popsicle' ), Two => 2 }; $first->{Three}->Thaw(); $second = { One => 1, Three => bless( \do { my $v = 'A-B-C' }, 'Popsicle' )->Tha +w(), Two => 2 }; $third = { One => 1, Three => bless( [ 'A', 'B', 'C' ], 'Popsicle' ), Two => 2 }; $fourth = { One => 1, Three => bless( \do { my $v = 'A-B-C' }, 'Popsicle' )->Tha +w(), Two => 2 }; $fifth = { One => 1, Three => bless( \do { my $v = 'A-B-C' }, 'Popsicle' )->Thaw +(), Two => 2 };
---
$world=~s/war/peace/g


In reply to Re^3: Hooks like Storable for Dumper? by demerphq
in thread Hooks like Storable for Dumper? by xdg

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.