Nicholas Perez


Data::Morph::Role::Backend - Provides a role to consume to develop specialized backends


version 1.140400


    package Data::Morph::Backend::Object;
    use Moose;
    use MooseX::Types::Moose(':all');
    use MooseX::Params::Validate;
    use namespace::autoclean;

    sub epilogue { }

    with 'Data::Morph::Role::Backend' =>
        input_type => Object,
        get_val => sub
            my ($obj, $key) = @_;
            return $obj->$key;
        set_val => sub
            my ($obj, $key, $val) = @_;



This module provides a simple composable behavior that backend authors must consume and fill out so that it operates seamlessly within a Data::Morph transformation



    isa: Moose::Meta::TypeConstraint
    required: 1

To properly constrain "store" and "retrieve", a type constraint must be made available. This must match what "new_instance" generates.


    isa: CodeRef, required: 1

This coderef should implement a set accessor to the type configured in "input_type". The coderef will receive the instance, the key, and the value as arguments and be executed in a void context.


    isa: CodeRef, required: 1

This coderef should implement a get accessor to the type configured in "input_type". The coderef will receive the instance and the key as arguments. The return value will then be used by the system.



This method is required for all backends (even if it is a no-op). Once processing is complete this method will be called with the final, populated instance. If additional processing should take place on the instance as a whole rather on individual properties of it, do it here.



    is: ro, isa: CodeRef, required: 1

Each backend should provide a coderef or require one upon construction that is an instance factory. The instances returned must match "input_type". The instance factory will receive the raw input as the only argument to allow for dynamic instance creation.


    is: ro, isa: Moose::Meta::TypeConstraint, default: role parameter

This attribute is provided so that users of the backend can process different types other than the default provided at role consumption



This method access "new_instance" and invokes it with the provided raw input as an argument, returning its return value


    (INSTANCE, Maybe[Str], CodeRef?)

This method is what fetches the value from the instance using "get_val". The optional coderef parameter is what is passed in from the map if it is defined for a read operation. The coderef must be called with the return value from "get_val". And its return value returned.

If an undefined key is given but a coderef is defined, the result from the coderef will be returned


    (INSTANCE, Any, Str, CodeRef?)

This method takes the Defined value and sets it into the instance using the Str key. The optional coderef parameter is what is passed if defined in the map in a write operation. If it is provided, it must be called with the value and its return value ultimately used in the storage operation, "set_val"


Nicholas R. Perez <>


This software is copyright (c) 2011 by Nicholas R. Perez <>.

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