MooseX::Role::JSONObject;
use v5.012;
use strict;
use warnings;
use version; our $VERSION = version->declare("v0.1.0");
use Moose::Role;
use Method::Signatures;
use MooseX::Role::JSONObject::Util;
method to_json()
{
return MooseX::Role::JSONObject::Util::meta_to_json(
$self, $self->meta);
}
method from_json($class:, HashRef $data)
{
my $cls = ref $class || $class;
my $meta = Class::M
return MooseX::Role::JSONObject::Util::meta_from_json(
$data, $meta);
}
1;
__END__
=encoding utf-8
=head1 NAME
MooseX::Role::JSONObject - create/store an object in a JSON-like hash
=head1 SY
seX::Role::JSONObject::Meta::Trait;
use v5.012;
use strict;
use warnings;
use version; our $VERSION = version->declare("v0.1.0");
use Moose::Role;
Moose::Util::meta_attribute_alias('JSONAttribute'
s => 'rw',
isa => 'Str',
predicate => 'has_json_attr',
);
1;
__END__
=encoding utf-8
=head1 NAME
MooseX::Role::JSONObject::Meta::Trait - rename a JSONObject attribute
=head1 SYNOPSIS
packa
oseX::Role::JSONObject::Meta::Trait;
with 'MooseX::Role::JSONObject';
has ipv4_address => (
is => 'rw',
isa => 'Str',
traits => ['JSONAttribute'],
json_attr => 'I
#!/usr/bin/perl
package MooseX::Role::JSONObject::Util;
use v5.012;
use strict;
use warnings;
use version; our $VERSION = version->declare("v0.1.0");
use List::Util qw/pairfirst/;
use Method::Sign
tribute $attr)
{
if (!$attr->has_type_constraint) {
if (!defined $val) {
die "MooseX::Role::JSONObject::SKIP\n";
} elsif (ref $val eq 'ARRAY') {
return ('array', '*');
} elsif (ref $val e
, '*');
}
return ['*'];
}
if (!defined $val && !$attr->is_required) {
die "MooseX::Role::JSONObject::SKIP\n";
}
my $type = $attr->type_constraint;
my @res;
again:
my @handlers = (
'Obje