1 2 3 4 5 6 7 8 9 10 11
package Note; use strict; use warnings; use Moose; use MooseX::Storage; with Storage('format' => 'JSON', 'io' => 'File'); has 'message' =>(is=> 'rw', isa =>'Str'); 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use strict; use warnings; use utf8; use feature 'say'; use Note; use Storable; use MooseX::Storage; use Data::Dumper; use JSON; my @container=(); my $obj = Note->new; $obj->{'message'}= "firstmessage"; say $obj->{'message'}; push(@container,$obj); my $obj2 = Note->new; $obj2->{'message'}="secondmessage"; push(@container,$obj2); my @output=(); for my $counter (0 .. $#container){ push(@output,$container[$counter]->pack()); } say "Output packed strings:" ; for my $counter(0 .. $#output){ say $output[$counter]; } store \@output, 'saveNotes'; my @Notes=(); my @fin=@{retrieve('saveNotes')}; @Arr=(); while ((my $key, my $value) = each(@fin)){ push(@Arr,Note->unpack($value)); } say '@Arr ' . :Dumper(@Arr);
Quote$VAR1 = bless({}, 'Note');
$VAR2 = bless({}, 'Note');
Quote$VAR1 = {
'message' => 'firstmessage',
'__CLASS__' => 'Note',
};
$VAR2 = {
'message' => 'secondmessage',
'__CLASS__' => 'Note',
};
store( \@output, 'saveNotes' ) || die "Cannot store \@output in 'saveNotes': $!";
1 2 3 4 5 6 7 8 9 10 11
@fin=retrieve('saveNotes'); say "After reading file:"; my @dumpArr = $fin[0]; @Arr=(); while ((my $key, my $value) = each($dumpArr[0])){ push(@Arr,Note->unpack($value)); } say Dumper(@Arr);
Quote$VAR1 = bless({}, 'Note');
$VAR2 = bless({}, 'Note');
1 2 3 4
my $obj = Note->new; $obj->{'message'}= "firstmessage"; say $obj->{'message'};