DESCRIPTION

Getting objects into an ideal format for passing representations in and out of applications can be a real pain. Object::Serializer is a fast and simple pure-perl framework-agnostic type-less none-opinionated light-weight primitive general purpose object serializer which tries to help make object serialization easier. This module is useful in situations when you have blessed objects you wish to produce hash representations from which you can store directly or convert to JSON, YAML, or XML. This module does not currently support deserialization.

METHODS

serialize

The serialize method expects an object and returns a serialized (hashified) version of that object.

serialization_strategy_for

The serialization_strategy_for method expects a reftype and a sub-routine. This method registers a custom serialization strategy which will be used during the collapsing of the reference type specified.

CLASS->serialization_strategy_for(
REFTYPE => sub { ... }
);

EXTENSION

Object::Serializer can be used as a serializer independently, however, it is primarily designed to be used as a base class for your classes or roles. By default, Object::Serializer doesn't do anything special for you in the way of serialization, in-fact, it is little more than a wrapper around Data::Dumper. Additionally, you can hook into the serialization process by defining your serialization strategy using your own custom serialization routines which will be executed whenever a specific reference type is encountered. The following syntax is what you might use to register your own custom serialization strategy. This example registers a custom serializer that is executed globally whenever a DateTime object is found.

Additionally, you can register a serialization strategy to be used only when invoked by a specific class. The following syntax is what you might use to register a serialization strategy to be executed only for a specific class: