Session/Serialize/Base64.pm

filter: Statementstmt 100% 20 / 20 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 90.0% 27 / 30 CC 2 SCAR 2.6
CC
2
Cov
95%
unserialize
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Session/Serialize/UUEncode.pm ↑ Summary Session/Lock/Null.pm »
1 #############################################################################
2 #
3 # Apache::Session::Serialize::Base64
4 # Serializes session objects using Storable and MIME::Base64
5 # Copyright(c) 2000 Jeffrey William Baker (jwbaker@acm.org)
6 # Distribute under the Perl License
7 #
8 ############################################################################
9
10 package Apache::Session::Serialize::Base64;
11
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Storable qw(nfreeze thaw);
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 1 $VERSION = '1.01';
18
19 1 ▶sub serialize {
Subroutine serialize: called CC=1 SCAR=0.0
Pod undocumented
20 1 my $session = shift;
21
22 1 $session->{serialized} = encode_base64(nfreeze($session->{data}));
23 }
24
25 1 ▶sub unserialize {
Subroutine unserialize: called CC=2 SCAR=7.0
Pod undocumented
26 1 my $session = shift;
27
28 1 my $data = thaw(decode_base64($session->{serialized}));
29 1 ▶ die "Session could not be unserialized" unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 1 1
30 #Storable can return undef or die for different errors
31 1 $session->{data} = $data;
32 }
33
34 1 1;
35
36 =pod
37
38 =head1 NAME
39
40 Apache::Session::Serialize::Base64 - Use Storable and MIME::Base64
41 to zip up persistent data
42
43 =head1 SYNOPSIS
44
45 use Apache::Session::Serialize::Base64;
46
47 $zipped = Apache::Session::Serialize::Base64::serialize($ref);
48 $ref = Apache::Session::Serialize::Base64::unserialize($zipped);
49
50 =head1 DESCRIPTION
51
52 This module fulfills the serialization interface of Apache::Session.
53 It serializes the data in the session object by use of Storable's
54 C<nfreeze()> and C<thaw()> functions, and MIME::Base64's C<encode_bas64>
55 and C<decode_base64>. The serialized data is ASCII text, suitable for
56 storage in backing stores that don't handle binary data gracefully, such
57 as Postgres.
58
59 =head1 AUTHOR
60
61 This module was written by Jeffrey William Baker <jwbaker@acm.org>.
62
63 =head1 SEE ALSO
64
65 L<Apache::Session::Serialize::Storable>, L<Apache::Session>
« Session/Serialize/UUEncode.pm ↑ Summary Session/Lock/Null.pm »