Me again, according to the docs, pack/unpack DO NOT write to files, or json, they make/break an unblessed perl hash

I concocted the following based on the docs and http://search.cpan.org/dist/MooseX-Storage/MANIFEST

It is freeze/thaw that does the JSON thing in your class (cause Storage format JSON)

Example

#!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); BEGIN { package Note; use strict; use warnings; use Moose; use MooseX::Storage; with Storage('format' => 'JSON', 'io' => 'File'); has 'message' =>(is=> 'rw', isa =>'Str'); no Moose; $INC{'Note.pm'} = __FILE__; # true } sub Main { use strict; use warnings; use Storable qw/ nfreeze thaw /; use Data::Dump qw/ dd /; use Note; my @notes = map { Note->new( message => $_.' '.localtime ) } qw/ R +o Sham Bo /; dd( \@notes ); my $ice = nfreeze( \@notes ); dd( $ice, thaw( $ice ) ); dd( [ map { $_->pack } @notes ] ); dd( [ map { Note->unpack( $_ ) } map { $_->pack } @notes ] ); dd( [ map { $_->freeze } @notes ] ); dd( [ map { Note->thaw( $_ ) } map { $_->freeze } @notes ] ); } __END__ [ bless({ message => "Ro Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Sham Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Bo Wed May 29 00:14:43 2013" }, "Note"), ] ( "\5\t\2\0\0\0\3\4\21\4Note\3\0\0\0\1\n\eRo Wed May 29 00:14:43 2013\ +0\0\0\amessage\4\22\0\3\0\0\0\1\n\35Sham Wed May 29 00:14:43 2013\0\0 +\0\amessage\4\22\0\3\0\0\0\1\n\eBo Wed May 29 00:14:43 2013\0\0\0\ame +ssage", [ bless({ message => "Ro Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Sham Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Bo Wed May 29 00:14:43 2013" }, "Note"), ], ) [ { __CLASS__ => "Note", message => "Ro Wed May 29 00:14:43 2013" }, { __CLASS__ => "Note", message => "Sham Wed May 29 00:14:43 2013" }, { __CLASS__ => "Note", message => "Bo Wed May 29 00:14:43 2013" }, ] [ bless({ message => "Ro Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Sham Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Bo Wed May 29 00:14:43 2013" }, "Note"), ] [ "{\"__CLASS__\":\"Note\",\"message\":\"Ro Wed May 29 00:14:43 2013\" +}", "{\"__CLASS__\":\"Note\",\"message\":\"Sham Wed May 29 00:14:43 2013 +\"}", "{\"__CLASS__\":\"Note\",\"message\":\"Bo Wed May 29 00:14:43 2013\" +}", ] [ bless({ message => "Ro Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Sham Wed May 29 00:14:43 2013" }, "Note"), bless({ message => "Bo Wed May 29 00:14:43 2013" }, "Note"), ]

In reply to Re: Storing an array of Moose objects by Anonymous Monk
in thread Storing an array of Moose objects by demonking

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.