KiokuDB::Backend::Serialize::Storable - L<Storable> based serialization of


KiokuDB documentation Contained in the KiokuDB distribution.

Index


Code Index:

NAME

Top

KiokuDB::Backend::Serialize::Storable - Storable based serialization of KiokuDB::Entry objects.

SYNOPSIS

Top

    package MyBackend;

    with qw(KiokuDB::Backend::Serialize::Storable;

DESCRIPTION

Top

This role provides Storable based serialization of KiokuDB::Entry objects for a backend, with streaming capabilities.

KiokuDB::Backend::Serialize::Delegate is preferred to using this directly.

METHODS

Top

serialize $entry

Uses nstore in Storable

deserialize $blob

Uses thaw in Storable

serialize_to_stream $fh, $entry

Uses nstore_fd in Storable.

deserialize_from_stream $fh

Uses fd_retrieve in Storable.


KiokuDB documentation Contained in the KiokuDB distribution.

#!/usr/bin/perl

package KiokuDB::Backend::Serialize::Storable;
use Moose::Role;

use Storable qw(nfreeze thaw nstore_fd fd_retrieve);

use namespace::clean -except => 'meta';

with qw(
    KiokuDB::Backend::Serialize
    KiokuDB::Backend::Role::UnicodeSafe
    KiokuDB::Backend::Role::BinarySafe
    KiokuDB::Backend::TypeMap::Default::Storable
);

sub serialize {
    my ( $self, $entry ) = @_;

    return nfreeze($entry);
}

sub deserialize {
    my ( $self, $blob ) = @_;

    return thaw($blob);
}

sub serialize_to_stream {
    my ( $self, $fh, $entry ) = @_;
    nstore_fd($entry, $fh);
}

sub deserialize_from_stream {
    my ( $self, $fh ) = @_;

    if ( $fh->eof ) {
        return;
    } else {
        return fd_retrieve($fh);
    }
}

__PACKAGE__

__END__