MooseX::Role::JSONObject::Meta::Trait - rename a JSONObject attribute
package foo; use Moose; use MooseX::Role::JSONObject::Meta::Trait; with 'MooseX::Role::JSONObject'; has ipv4_address => ( is => 'rw', isa => 'Str', traits => ['JSONAttribute'], json_attr => 'IPv4 Address', ); ... my %data = ('IPv4 Address' => '127.0.0.1'); my $o = foo->from_json(\%data); say $o->ipv4_address;
The MooseX::Role::JSONObject::Meta::Trait trait enhances the MooseX::Role::JSONObject role by allowing an attribute to be stored or retrieved from a hash element with a different name. This may be useful when parsing or outputting data with key names containing whitespace or other characters not well suited for use in a Moose attribute name.
MooseX::Role::JSONObject::Meta::Trait
The trait may also be accessed by its JSONAttribute alias.
JSONAttribute
The MooseX::Role::JSONObject::Meta::Trait trait provides a single property:
json_attr
Specify the name of the hash key that this attribute should be stored to or retrieved from.
MooseX::Role::JSONObject
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.
Peter Pentchev <roam@ringlet.net>
To install MooseX::Role::JSONObject, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Role::JSONObject
CPAN shell
perl -MCPAN -e shell install MooseX::Role::JSONObject
For more information on module installation, please visit the detailed CPAN module installation guide.