The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Role::JSONObject::Util - helper functions for MooseX::Role::JSONObject

DESCRIPTION

The MooseX::Role::JSONObject::Util module provides several utility functions for the MooseX::Role::JSONObject role.

Please note that these functions are only meant for internal use by MooseX::Role::JSONObject and, as such, any and all of them may change without prior notice.

  • identify_type()

    Examine a Moose::Meta::Attribute object and return a list of strings describing recursively the attribute's type, e.g. ['maybe', 'hash', 'num'] for a Maybe[HashRef[Int]] attribute or ['hash', 'array', 'obj', 'Some::Class'] for a HashRef[ArrayRef[Some::Class]] attribute.

    Note that all types descending from Num are represented as 'num'.

  • get_value()

    Given an attribute and a function to recurse into objects, parse the attribute's type using identify_type() and process the given type's value appropriately. This function is used by both the meta_to_json() and meta_from_json() functions (see below) with different functions passed as $objfunc.

  • get_value_type()

    Do the actual work of get_value() after the attribute's type has been examined by identify_type().

  • meta_to_json()

    Build a Perl hash suitable for a JSON representation of an object (or a value) of the given Moose::Meta::Class type. Uses get_value(), passing a reference to itself as the function to process complex objects.

  • meta_from_json()

    Build a Moose object (or a simple type's value) of the given Moose::Meta::Class type, initializing it and its attributes recursively with the values supplied in the given Perl hash. Uses get_value(), passing a reference to itself as the function to process complex objects.

LICENSE

Copyright (C) 2015 Peter Pentchev <roam@ringlet.net>

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

AUTHOR

Peter Pentchev <roam@ringlet.net>