File Coverage

blib/lib/DBI/Gofer/Serializer/Storable.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 31 34 91.1


line stmt bran cond sub pod time code
1             package DBI::Gofer::Serializer::Storable;
2              
3 56     56   324 use strict;
  56         123  
  56         3214  
4 56     56   260 use warnings;
  56         102  
  56         1431  
5              
6 56     56   291 use base qw(DBI::Gofer::Serializer::Base);
  56         157  
  56         14616  
7              
8             # $Id: Storable.pm 15585 2013-03-22 20:31:22Z Tim $
9             #
10             # Copyright (c) 2007, Tim Bunce, Ireland
11             #
12             # You may distribute under the terms of either the GNU General Public
13             # License or the Artistic License, as specified in the Perl README file.
14              
15             =head1 NAME
16              
17             DBI::Gofer::Serializer::Storable - Gofer serialization using Storable
18              
19             =head1 SYNOPSIS
20              
21             $serializer = DBI::Gofer::Serializer::Storable->new();
22              
23             $string = $serializer->serialize( $data );
24             ($string, $deserializer_class) = $serializer->serialize( $data );
25              
26             $data = $serializer->deserialize( $string );
27              
28             =head1 DESCRIPTION
29              
30             Uses Storable::nfreeze() to serialize and Storable::thaw() to deserialize.
31              
32             The serialize() method sets local $Storable::forgive_me = 1; so it doesn't
33             croak if it encounters any data types that can't be serialized, such as code refs.
34              
35             See also L.
36              
37             =cut
38              
39 56     56   14051 use Storable qw(nfreeze thaw);
  56         91160  
  56         4200  
40              
41             our $VERSION = "0.015586";
42              
43 56     56   360 use base qw(DBI::Gofer::Serializer::Base);
  56         107  
  56         5938  
44              
45              
46             sub serialize {
47 13689     13689 0 19526 my $self = shift;
48 13689         21087 local $Storable::forgive_me = 1; # for CODE refs etc
49 13689         19676 local $Storable::canonical = 1; # for go_cache
50 13689         32707 my $frozen = nfreeze(shift);
51 13689 50       970456 return $frozen unless wantarray;
52 13689         49513 return ($frozen, $self->{deserializer_class});
53             }
54              
55             sub deserialize {
56 13675     13675 0 20348 my $self = shift;
57 13675         32177 return thaw(shift);
58             }
59              
60             1;