NAME

File::Serialize::Serializer - Role for defining File::Serialize serializers

VERSION

version 1.5.1

SYNOPSIS

package File::Serialize::Serializer::MySerializer;

use Module::Runtime qw/ use_module /;

use Moo;

with 'File::Serialize::Serializer';

sub extensions { 'mys' }

sub init { use_module('SomeThing') }

sub serialize { ...}
sub deserialize { ...}

1;

DESCRIPTION

This role is used to define serializers for File::Serialize.

As all the serializer plugins are typically loaded to figure out which one should be used to serialize/deserialize a specific file, it's important that the modules on which the serializer depends are not just used, but are rather marked for import via the required_modules and init functions.

Required methods

A serializer should implement the following class methods:

extensions

Required. Must return a list of all extensions that this serializer can deal with.

The first extension of the list will be considered the canonical extension.

required_modules

Returns the list of modules that this serializer needs to operate.

If not provided, the required module will be extracted from the package name. I.e., the serializer File::Serialize::Serializer::YAML::Tiny will assume that it requires YAML::Tiny.

serialize( $data, $options )

Required. Returns the serialized $data.

deserialize

Required. Returns the deserialized $data.

groom_options( $options )

Takes in the generic serializer options and groom them for this specific one.

groom_serialize_options( $options )

Groom the options for this specific serializer. If not provided, groom_options is used.

groom_deserialize_options( $options )

Groom the options for this specific serializer. If not provided, groom_options is used.

Provided methods

The role provides the following attributes / methods:

precedence

Returns the serializer's precedence, used to determine which one of the available serializer for a format to use. Default to 100. A value of 0 means "don't use".

AUTHOR

Yanick Champoux <yanick@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021, 2019, 2017, 2016, 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.