File: Base64.pm

package info (click to toggle)
libapache-session-perl 1.94-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 1,514; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#############################################################################
#
# Apache::Session::Serialize::Base64
# Serializes session objects using Storable and MIME::Base64
# Copyright(c) 2000 Jeffrey William Baker (jwbaker@acm.org)
# Distribute under the Perl License
#
############################################################################

package Apache::Session::Serialize::Base64;

use strict;
use vars qw($VERSION);
use MIME::Base64;
use Storable qw(nfreeze thaw);

$VERSION = '1.01';

sub serialize {
    my $session = shift;
    
    $session->{serialized} = encode_base64(nfreeze($session->{data}));
}

sub unserialize {
    my $session = shift;
    
    my $data = thaw(decode_base64($session->{serialized}));
    die "Session could not be unserialized" unless defined $data;
    #Storable can return undef or die for different errors
    $session->{data} = $data;
}

1;

=pod

=head1 NAME

Apache::Session::Serialize::Base64 - Use Storable and MIME::Base64
to zip up persistent data

=head1 SYNOPSIS

 use Apache::Session::Serialize::Base64;

 $zipped = Apache::Session::Serialize::Base64::serialize($ref);
 $ref = Apache::Session::Serialize::Base64::unserialize($zipped);

=head1 DESCRIPTION

This module fulfills the serialization interface of Apache::Session.
It serializes the data in the session object by use of Storable's
C<nfreeze()> and C<thaw()> functions, and MIME::Base64's C<encode_bas64>
and C<decode_base64>.  The serialized data is ASCII text, suitable for
storage in backing stores that don't handle binary data gracefully, such
as Postgres.

=head1 AUTHOR

This module was written by Jeffrey William Baker <jwbaker@acm.org>.

=head1 SEE ALSO

L<Apache::Session::Serialize::Storable>, L<Apache::Session>