in reply to Re^2: Hooks like Storable for Dumper?
in thread Hooks like Storable for Dumper?
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 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hooks like Storable for Dumper?
by xdg (Monsignor) on Jan 03, 2006 at 18:02 UTC | |
by demerphq (Chancellor) on Jan 04, 2006 at 18:28 UTC | |
by demerphq (Chancellor) on Jan 03, 2006 at 18:17 UTC | |
by xdg (Monsignor) on Jan 03, 2006 at 18:49 UTC | |
by demerphq (Chancellor) on Jan 03, 2006 at 19:20 UTC | |
by xdg (Monsignor) on Jan 03, 2006 at 20:13 UTC |