| 1 | ############################################################################# | ||
| 2 | # | ||
| 3 | # Apache::Session::Serialize::DBMS::Storable | ||
| 4 | # Serializes session objects using Storable and object-per-key support added | ||
| 5 | # for Apache::Session::DBMS module | ||
| 6 | # | ||
| 7 | # Copyright(c) 2005 Asemantics S.r.l. | ||
| 8 | # Alberto Reggiori (alberto@asemantics.com) | ||
| 9 | # Distribute under a BSD license (see LICENSE file in main dir) | ||
| 10 | # | ||
| 11 | ############################################################################ | ||
| 12 | |||
| 13 | package Apache::Session::Serialize::DBMS::Storable; | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use vars qw($VERSION); | ||
| 17 | use Storable qw(nfreeze thaw); | ||
| 18 | |||
| 19 | $VERSION = '0.1'; | ||
| 20 | |||
| 21 | sub serialize { | ||
| 22 | my $session = shift; | ||
| 23 | |||
| 24 | if( $session->{isObjectPerKey} ) { | ||
| 25 | my $data = shift; | ||
| 26 | |||
| 27 | nfreeze( ref($data) ? $data : \$data ); | ||
| 28 | } else { | ||
| 29 | $session->{serialized} = nfreeze $session->{data}; | ||
| 30 | }; | ||
| 31 | }; | ||
| 32 | |||
| 33 | sub unserialize { | ||
| 34 | my $session = shift; | ||
| 35 | |||
| 36 | if( $session->{isObjectPerKey} ) { | ||
| 37 | my $oldvalue = thaw(shift); | ||
| 38 | |||
| 39 | ref($oldvalue)=~ /SCALAR/ ? ${$oldvalue} : $oldvalue; | ||
| 40 | } else { | ||
| 41 | $session->{data} = thaw $session->{serialized}; | ||
| 42 | }; | ||
| 43 | }; | ||
| 44 | |||
| 45 | 1; | ||
| 46 | |||
| 47 | =pod | ||
| 48 | |||
| 49 | =head1 NAME | ||
| 50 | |||
| 51 | Apache::Session::Serialize::DBMS::Storable - Use Storable to zip up persistent data | ||
| 52 | |||
| 53 | =head1 SYNOPSIS | ||
| 54 | |||
| 55 | use Apache::Session::Serialize::DBMS::Storable; | ||
| 56 | |||
| 57 | $zipped = Apache::Session::Serialize::DBMS::Storable::serialize($ref); | ||
| 58 | $ref = Apache::Session::Serialize::DBMS::Storable::unserialize($zipped); | ||
| 59 | |||
| 60 | =head1 DESCRIPTION | ||
| 61 | |||
| 62 | This module fulfills the serialization interface of Apache::Session. | ||
| 63 | It serializes the data in the session object by use of Storable's | ||
| 64 | C<nfreeze()> and C<thaw()> functions. The result is a binary object ready | ||
| 65 | for storage. | ||
| 66 | |||
| 67 | =head1 AUTHOR | ||
| 68 | |||
| 69 | This module was written by Alberto Reggiori <alberto@asemantics.com> | ||
| 70 | |||
| 71 | =head1 SEE ALSO | ||
| 72 | |||
| 73 | L<Apache::Session::DBMS> |