releasing/cbrtools/perl/MLDBM/Serializer/Storable.pm
changeset 607 378360dbbdba
parent 602 3145852acc89
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 # Copyright (c) 1995-98 Gurusamy Sarathy.  All rights reserved.
       
     2 #
       
     3 # Copyright (c) 1998 Raphael Manfredi.
       
     4 #
       
     5 # This program is free software; you can redistribute it and/or
       
     6 # modify it under the same terms as Perl itself.
       
     7 
       
     8 package MLDBM::Serializer::Storable;
       
     9 BEGIN { @MLDBM::Serializer::Storable::ISA = qw(MLDBM::Serializer) }
       
    10 
       
    11 use Storable;
       
    12 
       
    13 sub new {
       
    14     my $self = shift->SUPER::new();
       
    15     $self->DumpMeth(shift);
       
    16     # Storable doesn't honor other attributes
       
    17     $self;
       
    18 }
       
    19 
       
    20 #
       
    21 # Serialize a reference to supplied value
       
    22 #
       
    23 sub serialize {
       
    24     my $self = shift;
       
    25     my $dumpmeth = $self->{'_dumpsub_'};
       
    26     &$dumpmeth(\$_[0]);
       
    27 }
       
    28 
       
    29 #
       
    30 # Deserialize and de-reference
       
    31 #
       
    32 sub deserialize {
       
    33     my $obj = Storable::thaw($_[1]);		# Does not care whether portable
       
    34     defined($obj) ? $$obj : undef;
       
    35 }
       
    36 
       
    37 #
       
    38 # Change dump method when portability is requested
       
    39 #
       
    40 sub DumpMeth {
       
    41     my $self = shift;
       
    42     $self->{'_dumpsub_'} = 
       
    43       ($_[0] && $_[0] eq 'portable' ? \&Storable::nfreeze : \&Storable::freeze);
       
    44     $self->_attrib('dumpmeth', @_);
       
    45 }
       
    46 
       
    47 1;
       
    48 __END__
       
    49 
       
    50 =head1 AUTHORS
       
    51 
       
    52 Gurusamy Sarathy <F<gsar@umich.edu>>.
       
    53 
       
    54 Support for multiple serializing packages by
       
    55 Raphael Manfredi <F<Raphael_Manfredi@grenoble.hp.com>>.
       
    56 
       
    57 Copyright (c) 1995-98 Gurusamy Sarathy.  All rights reserved.
       
    58 
       
    59 Copyright (c) 1998 Raphael Manfredi.
       
    60 
       
    61 This program is free software; you can redistribute it and/or
       
    62 modify it under the same terms as Perl itself.
       
    63 
       
    64 =cut