Group
Extension

Matches 10

MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Format/JSON.pm ( view source; MetaCPAN )

package MooseX::Storage::Format::JSON;
use Moose::Role;

no warnings 'once';

use JSON::Any;
use utf8 ();

our $VERSION   = '0.32';
our $AUTHORITY = 'cpan:STEVAN';

requires 'pack';
requires 'unpack'
::encode($json) if utf8::is_utf8($json);
    $class->unpack( JSON::Any->new->jsonToObj($json), @args );
}

sub freeze {
    my ( $self, @args ) = @_;
    my $json = JSON::Any->new->objToJson( $self->p
json) if !utf8::is_utf8($json) and utf8::valid($json); # if it's valid utf8 mark it as such
    return $json;
}

no Moose::Role;

1;

__END__

=pod

=head1 NAME

MooseX::Storage::Format::JSON - A JSON
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Meta/Attribute/Trait/DoNotSerialize.pm ( view source; MetaCPAN )
ad1 SYNOPSIS

  package Point;
  use Moose;
  use MooseX::Storage;
  
  with Storage('format' => 'JSON', 'io' => 'File');
  
  has 'x' => (is => 'rw', isa => 'Int');
  has 'y' => (is => 'rw', isa => '
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Deferred.pm ( view source; MetaCPAN )
ase JSON)

  # pack the class into a JSON string
  $p->freeze({ format => 'JSON' }); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 }

  # pack the class into a JSON string using parameterized JSONpm r
> [ JSONpm => { json_opts => { pretty => 1 } } ] });

  # unpack the JSON string into a class
  my $p2 = Point->thaw(
      '{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }',
      { format => 'JSON' }
ally use them (see the
SYNOPSIS for more info)

=head1 SUPPORTED FORMATS

=over 4

=item I<JSON>

=item I<JSONpm>

=item I<YAML>

=item I<Storable>

=back

=head1 SUPPORTED I/O

=over 4

=item I<File>
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Util.pm ( view source; MetaCPAN )
e_json {
    my ($class, $json) = @_;

    eval { require JSON::Any; JSON::Any->import };
    confess "Could not load JSON module because : $@" if $@;

    utf8::encode($json) if utf8::is_utf8($json);


    my $data = eval { JSON::Any->jsonToObj($json) };
    if ($@) {
        confess "There was an error when attempting to peek at JSON: $@";
    }

    return $data;
}

sub _inflate_yaml {
    my ($

unfreeze/unpack it.

The C<$data> can be either a perl HASH ref or some kind of serialized
data (JSON, YAML, etc.).

The C<%options> are as follows:

=over 4

=item I<format>

If this is left blank, 
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Engine.pm ( view source; MetaCPAN )
perly numify the numbers
    # before and after them being futzed with, because some of
    # the JSON engines are stupid/annoying/frustrating
    'Int'      => { expand => sub { $_[0] + 0 }, collapse
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/IO/AtomicFile.pm ( view source; MetaCPAN )
head1 SYNOPSIS

  package Point;
  use Moose;
  use MooseX::Storage;

  with Storage('format' => 'JSON', 'io' => 'AtomicFile');

  has 'x' => (is => 'rw', isa => 'Int');
  has 'y' => (is => 'rw', isa 
methods to load/store a class
  ## on the file system

  $p->store('my_point.json');

  my $p2 = Point->load('my_point.json');

=head1 METHODS

=over 4

=item B<load ($filename)>

=item B<store ($file
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Meta/Attribute/DoNotSerialize.pm ( view source; MetaCPAN )
ad1 SYNOPSIS

  package Point;
  use Moose;
  use MooseX::Storage;
  
  with Storage('format' => 'JSON', 'io' => 'File');
  
  has 'x' => (is => 'rw', isa => 'Int');
  has 'y' => (is => 'rw', isa => '
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/Format/YAML.pm ( view source; MetaCPAN )
 YAML string
  $p->freeze();

  # ----
  # __CLASS__: "Point"
  # x: 10
  # y: 10

  # unpack the JSON string into a class
  my $p2 = Point->thaw(<<YAML);
  ----
  __CLASS__: "Point"
  x: 10
  y: 10
 
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage/IO/File.pm ( view source; MetaCPAN )
head1 SYNOPSIS

  package Point;
  use Moose;
  use MooseX::Storage;

  with Storage('format' => 'JSON', 'io' => 'File');

  has 'x' => (is => 'rw', isa => 'Int');
  has 'y' => (is => 'rw', isa => 'In
methods to load/store a class
  ## on the file system

  $p->store('my_point.json');

  my $p2 = Point->load('my_point.json');

=head1 METHODS

=over 4

=item B<load ($filename)>

=item B<store ($file
MooseX-Storage ( B/BO/BOBTFISH/MooseX-Storage-0.32.tar.gz, BOBTFISH, 2012; MetaCPAN )
MooseX-Storage/lib/MooseX/Storage.pm ( view source; MetaCPAN )
Point;
  use Moose;
  use MooseX::Storage;

  our $VERSION = '0.01';

  with Storage('format' => 'JSON', 'io' => 'File');

  has 'x' => (is => 'rw', isa => 'Int');
  has 'y' => (is => 'rw', isa => 'In
zation format
  ## (in this case JSON)

  # pack the class into a JSON string
  $p->freeze(); # { "__CLASS__" : "Point-0.01", "x" : 10, "y" : 10 }

  # unpack the JSON string into a class
  my $p2 = P
methods to load/store a class
  ## on the file system

  $p->store('my_point.json');

  my $p2 = Point->load('my_point.json');

=head1 DESCRIPTION

MooseX::Storage is a serialization framework for Moo

Powered by Groonga
Maintained by Kenichi Ishigaki <ishigaki@cpan.org>. If you find anything, submit it on GitHub.