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
     1 package CGI::Session::Serialize::yaml;
     2 
     3 use strict;
     4 use CGI::Session::ErrorHandler;
     5 
     6 $CGI::Session::Serialize::yaml::VERSION = '4.20';
     7 @CGI::Session::Serialize::yaml::ISA     = ( "CGI::Session::ErrorHandler" );
     8 our $Flavour;
     9 
    10 unless($Flavour) {
    11     my $package = (grep { eval("use $_ (); 1;") } qw(YAML::Syck YAML))[0]
    12         or die "Either YAML::Syck or YAML are required to use ", __PACKAGE__;
    13     $Flavour = $package;
    14 }
    15 
    16 sub freeze {
    17     my ($self, $data) = @_;
    18     return $Flavour->can('Dump')->($data);
    19 }
    20 
    21 
    22 sub thaw {
    23     my ($self, $string) = @_;
    24     return ($Flavour->can('Load')->($string))[0];
    25 }
    26 
    27 1;
    28 
    29 __END__;
    30 
    31 =pod
    32 
    33 =head1 NAME
    34 
    35 CGI::Session::Serialize::yaml - serializer for CGI::Session
    36 
    37 =head1 DESCRIPTION
    38 
    39 This library can be used by CGI::Session to serialize session data. It uses
    40 L<YAML|YAML>, or the faster C implementation, L<YAML::Syck|YAML::Syck>
    41 if it is available. YAML serializers exist not just for Perl but also other
    42 dynamic languages, such as PHP, Python, and Ruby, so storing session data
    43 in this format makes it easy to share session data across different languages.
    44 
    45 YAML is made to be friendly for humans to parse as well as other computer
    46 languages. It creates a format that is easier to read than the default
    47 serializer.
    48 
    49 =head1 METHODS
    50 
    51 =over 4
    52 
    53 =item freeze($class, \%hash)
    54 
    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()">
    56 
    57 =item thaw($class, $string)
    58 
    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()">
    60 
    61 =back
    62 
    63 =head1 SEE ALSO
    64 
    65 L<CGI::Session>, L<YAML>, L<YAML::Syck>.
    66 
    67 =cut