CGI::Session::Serialize::yaml - serializer for CGI::Session


CGI-Session-Serialize-yaml documentation Contained in the CGI-Session-Serialize-yaml distribution.

Index


Code Index:

NAME

Top

CGI::Session::Serialize::yaml - serializer for CGI::Session

DESCRIPTION

Top

This library can be used by CGI::Session to serialize session data. It uses YAML, or the faster C implementation, YAML::Syck if it is available. YAML serializers exist not just for Perl but also other dynamic languages, such as PHP, Python, and Ruby, so storing session data in this format makes it easy to share session data across different languages.

YAML is made to be friendly for humans to parse as well as other computer languages. It creates a format that is easier to read than the default serializer.

METHODS

Top

freeze($class, \%hash)

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 set_error()|CGI::Session::ErrorHandler/"set_error()"

thaw($class, $string)

Received two arguments. First is the class name, second is the YAML data string. Should return thawed data structure on success, undef on failure. Error message should be set using set_error()|CGI::Session::ErrorHandler/"set_error()"

SEE ALSO

Top

CGI::Session, YAML, YAML::Syck.


CGI-Session-Serialize-yaml documentation Contained in the CGI-Session-Serialize-yaml distribution.

package CGI::Session::Serialize::yaml;

use strict;
use CGI::Session::ErrorHandler;

$CGI::Session::Serialize::yaml::VERSION = '4.26';
@CGI::Session::Serialize::yaml::ISA     = ( "CGI::Session::ErrorHandler" );
our $Flavour;

unless($Flavour) {
    my $package = (grep { eval("use $_ (); 1;") } qw(YAML::Syck YAML))[0]
        or die "Either YAML::Syck or YAML are required to use ", __PACKAGE__;
    $Flavour = $package;
}

sub freeze {
    my ($self, $data) = @_;
    return $Flavour->can('Dump')->($data);
}


sub thaw {
    my ($self, $string) = @_;
    return ($Flavour->can('Load')->($string))[0];
}

1;

__END__;