Loading L<MooseX::Attribute::Deflator::Moose>
will cause HashRefs and ArrayRefs to be encoded as JSON strings. However, you can simply overwrite
those deflators (and inflators) to deflate to somethin
C<benchmark.pl> tests three ways of deflating the value of a HashRef attribute
to a json encoded string (using L<JSON>).
my $obj = MyBenchmark->new( hashref => { foo => 'bar' } );
my $attr =
ate($obj);
Using the deflate attribute method, supplied by this module.
=item accessor
JSON::encode_json($obj->hashref);
If the attribute comes with an accessor, you can use this
method, to defl
eX::Attribute::Deflator;
use JSON;
if($ENV{HARNESS_ACTIVE}) {
deflate [qw(ArrayRef HashRef)], via { JSON->new->utf8->canonical->encode($_) },
inline_as {'JSON->new->utf8->canonical->encod
ef)], via { JSON->new->utf8->canonical->decode($_) },
inline_as {'JSON->new->utf8->canonical->decode($value)'};
} else {
deflate [qw(ArrayRef HashRef)], via { JSON::encode_json($_) },
inline_as {'JSON::encode_json($value)'};
inflate [qw(ArrayRef HashRef)], via { JSON::decode_json($_) },
inline_as {'JSON::decode_json($value)'};
}
deflate 'ScalarRef', via {$$_}, inl
Loading L<MooseX::Attribute::Deflator::Moose>
will cause HashRefs and ArrayRefs to be encoded as JSON strings. However, you can simply overwrite
those deflators (and inflators) to deflate to somethin
C<benchmark.pl> tests three ways of deflating the value of a HashRef attribute
to a json encoded string (using L<JSON>).
my $obj = MyBenchmark->new( hashref => { foo => 'bar' } );
my $attr =
ate($obj);
Using the deflate attribute method, supplied by this module.
=item accessor
JSON::encode_json($obj->hashref);
If the attribute comes with an accessor, you can use this
method, to defl
ware, licensed under:
#
# The (three-clause) BSD License
#
package MyBenchmark;
use Moose;
use JSON;
use DateTime;
use MooseX::Attribute::Deflator::Moose;
use MooseX::Attribute::Deflator;
has has
flator'],
default => sub { { foo => 'bar' } }
);
package main;
use strict;
use warnings;
use JSON;
use Benchmark qw(:all);
my $obj = MyBenchmark->new;
my $attr = $obj->meta->get_attribute('hash
> sub {
$attr->deflate($obj);
},
get_value => sub {
JSON::encode_json( $attr->get_value( $obj, 'hashref' ) );
},
accessor => sub {
m