Jifty::DBI::Filter::Storable - Encodes arbitrary data using Storable


Jifty-DBI documentation Contained in the Jifty-DBI distribution.

Index


Code Index:

NAME

Top

Jifty::DBI::Filter::Storable - Encodes arbitrary data using Storable

DESCRIPTION

Top

This filter allows you to store arbitrary Perl data structures in a column of type 'blob', using Storable to serialize them.

encode

If value is defined, then encodes it using nfreeze in Storable. Does nothing if value is not defined.

decode

If value is defined, then decodes it using thaw in Storable, otherwise does nothing.

SEE ALSO

Top

Jifty::DBI::Filter, Storable


Jifty-DBI documentation Contained in the Jifty-DBI distribution.
package Jifty::DBI::Filter::Storable;

use warnings;
use strict;

use base qw|Jifty::DBI::Filter|;
use Storable ();

sub encode {
    my $self = shift;

    my $value_ref = $self->value_ref;
    return unless defined $$value_ref;

    $Storable::Deparse = 1;
    $$value_ref = Storable::nfreeze($value_ref);
}

sub decode {
    my $self = shift;

    my $value_ref = $self->value_ref;
    return unless defined $$value_ref;

    # Storable doesn't take Unicode strings.
    Encode::_utf8_off($$value_ref);

    local $@;
    $Storable::Eval = 1;
    $$value_ref = eval { ${ Storable::thaw($$value_ref) } };
}

1;