NAME

Flux::Format - interface for symmetric two-way formatting of any storage.

VERSION

version 1.03

SYNOPSIS

$json_storage = $json_format->wrap($storage);
$json_storage->write({ a => "b" });
$in = $json_storage->in("client1");
$data = $in->read(); # data is decoded again

DESCRIPTION

There's a common need to store complex data into storages which can only store strings.

Simple Flux::Mapper is not enough, because storage should both serialize and deserialize data in the same way. Flux::Format provides the common interface for objects which can decorate Flux::Storage objects into storages which can both write data through a serializing mapper and create reading streams which deserialize that data on reads.

Usual method to create new formatters is to apply this role and implement encoder and decoder methods.

METHODS

encoder()

This method should return a mapper which will be applied to any item written into wrapped storage.

Mapper is expected to support Flux::Mapper interface and to transform data in 1-to-1 fashion.

decoder()

This method should return a mapper which will be applied to any item read from an input stream created from a wrapped storage.

Mapper is expected to support Flux::Mapper interface to transform data in 1-to-1 fashion.

wrap($storage)

Construct a formatted storage. Returns a new storage object.

Resulting object will transform all writes using encoder and generate input streams which are pre-decoded by decoder.

Unlike encoder and decoder, this method is provided by this role.

AUTHOR

Vyacheslav Matyukhin <me@berekuk.ru>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Yandex LLC.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.