lib/CPAN/lib/CGI/Session/Serialize/yaml.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
package CGI::Session::Serialize::yaml;
colas@0
     2
colas@0
     3
use strict;
colas@0
     4
use CGI::Session::ErrorHandler;
colas@0
     5
colas@0
     6
$CGI::Session::Serialize::yaml::VERSION = '4.20';
colas@0
     7
@CGI::Session::Serialize::yaml::ISA     = ( "CGI::Session::ErrorHandler" );
colas@0
     8
our $Flavour;
colas@0
     9
colas@0
    10
unless($Flavour) {
colas@0
    11
    my $package = (grep { eval("use $_ (); 1;") } qw(YAML::Syck YAML))[0]
colas@0
    12
        or die "Either YAML::Syck or YAML are required to use ", __PACKAGE__;
colas@0
    13
    $Flavour = $package;
colas@0
    14
}
colas@0
    15
colas@0
    16
sub freeze {
colas@0
    17
    my ($self, $data) = @_;
colas@0
    18
    return $Flavour->can('Dump')->($data);
colas@0
    19
}
colas@0
    20
colas@0
    21
colas@0
    22
sub thaw {
colas@0
    23
    my ($self, $string) = @_;
colas@0
    24
    return ($Flavour->can('Load')->($string))[0];
colas@0
    25
}
colas@0
    26
colas@0
    27
1;
colas@0
    28
colas@0
    29
__END__;
colas@0
    30
colas@0
    31
=pod
colas@0
    32
colas@0
    33
=head1 NAME
colas@0
    34
colas@0
    35
CGI::Session::Serialize::yaml - serializer for CGI::Session
colas@0
    36
colas@0
    37
=head1 DESCRIPTION
colas@0
    38
colas@0
    39
This library can be used by CGI::Session to serialize session data. It uses
colas@0
    40
L<YAML|YAML>, or the faster C implementation, L<YAML::Syck|YAML::Syck>
colas@0
    41
if it is available. YAML serializers exist not just for Perl but also other
colas@0
    42
dynamic languages, such as PHP, Python, and Ruby, so storing session data
colas@0
    43
in this format makes it easy to share session data across different languages.
colas@0
    44
colas@0
    45
YAML is made to be friendly for humans to parse as well as other computer
colas@0
    46
languages. It creates a format that is easier to read than the default
colas@0
    47
serializer.
colas@0
    48
colas@0
    49
=head1 METHODS
colas@0
    50
colas@0
    51
=over 4
colas@0
    52
colas@0
    53
=item freeze($class, \%hash)
colas@0
    54
colas@0
    55
Receives two arguments. First is the class name, the second is the data to be serialized. Should return serialized string on success, undef on failure. Error message should be set using C<set_error()|CGI::Session::ErrorHandler/"set_error()">
colas@0
    56
colas@0
    57
=item thaw($class, $string)
colas@0
    58
colas@0
    59
Received two arguments. First is the class name, second is the I<YAML> data string. Should return thawed data structure on success, undef on failure. Error message should be set using C<set_error()|CGI::Session::ErrorHandler/"set_error()">
colas@0
    60
colas@0
    61
=back
colas@0
    62
colas@0
    63
=head1 SEE ALSO
colas@0
    64
colas@0
    65
L<CGI::Session>, L<YAML>, L<YAML::Syck>.
colas@0
    66
colas@0
    67
=cut