The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MooseX::Role::JSONObject::Meta::Trait - rename a JSONObject attribute

SYNOPSIS

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;

DESCRIPTION

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.

The trait may also be accessed by its JSONAttribute alias.

PROPERTIES

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.

SEE ALSO

MooseX::Role::JSONObject

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>