NAME

File::Serialize - DWIM file serialization/deserialization

VERSION

version 0.2.0

SYNOPSIS

use File::Serialize { pretty => 1 };

my $data = { foo => 'bar' };

serialize_file '/path/to/file.json' => $data;

...;

$data_copy = deserialize_file '/path/to/file.json';

DESCRIPTION

File::Serialize provides a common, simple interface to file serialization -- you provide the file path, the data to serialized, and the module takes care of the rest. Even the serialization format, unless specified explicitly as part of the options, is detected from the file extension.

IMPORT

File::Serialize imports the two functions serialize_file and deserialize_file into the current namespace. A default set of options can be set for both by passing a hashref as an argument to the 'use' statement.

use File::Serialize { pretty => 1 };

SUPPORTED SERIALIZERS

YAML

JSON

TOML

OPTIONS

File::Serialize recognizes a set of options that, if applicable, will be passed to the serializer.

FUNCTIONS

serialize_file $path, $data, $options

my $data = { foo => 'bar' };

serialize_file '/path/to/file.json' => $data;

deserialize_file $path, $options

my $data = deserialize_file '/path/to/file.json';

ADDING A SERIALIZER

$File::Serialize::serializers{'MySerializer'} = {
    extensions => [ 'myser' ],
    init => 'My::Serializer',
    serialize   => sub { my($data,$options) = @_; ...; },
    deserialize => sub { my($data,$options) = @_; ...; },
    options => sub { my( $raw_options, $serialize ) = @_; ...; },
};

Serializers can be added via the $File::Serialize::serializers hash. The key is the name of the serializer, and the value is an hashref of its configuration parameters, which can be:

AUTHOR

Yanick Champoux yanick@cpan.org endorse

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Yanick Champoux.

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