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   358 use strict;
  56         111  
  56         1510  
4 56     56   280 use warnings;
  56         115  
  56         1427  
5              
6 56     56   272 use base qw(DBI::Gofer::Serializer::Base);
  56         131  
  56         22160  
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   19780 use Storable qw(nfreeze thaw);
  56         102312  
  56         4467  
40              
41             our $VERSION = "0.015586";
42              
43 56     56   397 use base qw(DBI::Gofer::Serializer::Base);
  56         120  
  56         6576  
44              
45              
46             sub serialize {
47 13689     13689 0 22486 my $self = shift;
48 13689         26788 local $Storable::forgive_me = 1; # for CODE refs etc
49 13689         24534 local $Storable::canonical = 1; # for go_cache
50 13689         41313 my $frozen = nfreeze(shift);
51 13689 50       1171378 return $frozen unless wantarray;
52 13689         58061 return ($frozen, $self->{deserializer_class});
53             }
54              
55             sub deserialize {
56 13675     13675 0 22062 my $self = shift;
57 13675         41775 return thaw(shift);
58             }
59              
60             1;