package Acme::MooseX::JSON;
use 5.008;
use strict;
use warnings;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.002';
use Moose 2.00 ();
use Moose::Exporter;
use Moose::Util::MetaRole;
use Sc
alar::Accessors::LikeHash::JSON ();
my $ACCESSORS = "Scalar::Accessors::LikeHash::JSON";
BEGIN {
package Acme::MooseX::JSON::Trait::Class;
use Moose::Role;
our $AUTHORITY = 'cpan:TOBYINK';
our $
VERSION = '0.002';
};
BEGIN {
package Acme::MooseX::JSON::Trait::Instance;
use Moose::Role;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.002';
override create_instance => sub {
my
package Scalar::Accessors::LikeHash::JSON;
use 5.008;
use strict;
use warnings;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.002';
use JSON;
use Role::Tiny::With;
with 'Scalar::Accessors::
= JSON::->new)->decode($$ref);
}
sub _from_hash
{
my ($ref, $hash) = @_;
$$ref = ($j ||= JSON::->new)->encode($hash);
}
1;
__END__
=head1 NAME
Scalar::Accessors::LikeHash::JSON - access a JSON
calar string in a hash-like manner
=head1 SYNOPSIS
my $object = Scalar::Accessors::LikeHash::JSON->new;
$object->store(some_key => 42) unless $object->exists('some_key');
$object->fetch
$invocant->_empty_structure;
}
1;
__END__
=head1 NAME
Scalar::Accessors::LikeHash - access a JSON/Sereal/etc scalar string in a hash-like manner
=head1 SYNOPSIS
{
package Acme::Storabl
sors::LikeHash::JSON";
$string->store(foo => 42);
Or as class methods passing the scalar reference as an extra first argument:
my $string = "{}";
Scalar::Accessors::LikeHash::JSON->store(\$string
tations, see L<Scalar::Accessors::LikeHash::JSON>
and L<Scalar::Accessors::LikeHash::Sereal>.
For an insane usage of this concept, see L<Acme::MooseX::JSON>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink
ref to tie hash to" unless ref $ref eq 'SCALAR';
$implementation = "Scalar::Accessors::LikeHash::JSON" unless defined $implementation;
Module::Runtime::use_package_optimistically($implementation);
LikeHash> role. If the implementation is omitted, then
defaults to L<Scalar::Accessors::LikeHash::JSON>.
=head1 BUGS
Please report any bugs to
L<http://rt.cpan.org/Dist/Display.html?Queue=Scalar-Acc