10 'Test::Deep::JSON' => 0, # skip all if not installed
17 use_ok('MooseX::Storage');
20 diag('Using implementation: ', YAML::Any->implementation);
27 with 'MooseX::Storage::Deferred';
29 has 'number' => ( is => 'ro', isa => 'Int' );
30 has 'string' => ( is => 'ro', isa => 'Str' );
31 has 'float' => ( is => 'ro', isa => 'Num' );
32 has 'array' => ( is => 'ro', isa => 'ArrayRef' );
33 has 'hash' => ( is => 'ro', isa => 'HashRef' );
34 has 'object' => ( is => 'ro', isa => 'Object' );
43 hash => { map { $_ => undef } ( 1 .. 10 ) },
44 object => Foo->new( number => 2 ),
46 isa_ok( $foo, 'Foo' );
48 my $json = $foo->freeze({ 'format' => 'JSON' });
57 hash => { map { $_ => undef } ( 1 .. 10 ) },
64 '... got the right JSON'
70 '{"array":[1,2,3,4,5,6,7,8,9,10],"hash":{"6":null,"3":null,"7":null,"9":null,"2":null,"8":null,"1":null,"4":null,"10":null,"5":null},"float":10.5,"object":{"number":2,"__CLASS__":"Foo"},"number":10,"__CLASS__":"Foo","string":"foo"}',
71 { 'format' => 'JSON' }
73 isa_ok( $foo, 'Foo' );
75 is( $foo->number, 10, '... got the right number' );
76 is( $foo->string, 'foo', '... got the right string' );
77 is( $foo->float, 10.5, '... got the right float' );
78 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
81 { map { $_ => undef } ( 1 .. 10 ) },
82 '... got the right hash'
85 isa_ok( $foo->object, 'Foo' );
86 is( $foo->object->number, 2,
87 '... got the right number (in the embedded object)' );
96 hash => { map { $_ => undef } ( 1 .. 10 ) },
97 object => Foo->new( number => 2 ),
99 isa_ok( $foo, 'Foo' );
101 my $stored = $foo->freeze({ 'format' => 'Storable' });
103 my $struct = Storable::thaw($stored);
107 '__CLASS__' => 'Foo',
111 'array' => [ 1 .. 10],
112 'hash' => { map { $_ => undef } 1 .. 10 },
114 '__CLASS__' => 'Foo',
118 '... got the data struct we expected'
123 my $stored = Storable::nfreeze({
124 '__CLASS__' => 'Foo',
128 'array' => [ 1 .. 10],
129 'hash' => { map { $_ => undef } 1 .. 10 },
131 '__CLASS__' => 'Foo',
136 my $foo = Foo->thaw($stored, { 'format' => 'Storable' });
137 isa_ok( $foo, 'Foo' );
139 is( $foo->number, 10, '... got the right number' );
140 is( $foo->string, 'foo', '... got the right string' );
141 is( $foo->float, 10.5, '... got the right float' );
142 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
145 { map { $_ => undef } ( 1 .. 10 ) },
146 '... got the right hash'
149 isa_ok( $foo->object, 'Foo' );
150 is( $foo->object->number, 2,
151 '... got the right number (in the embedded object)' );
159 array => [ 1 .. 10 ],
160 hash => { map { $_ => undef } ( 1 .. 10 ) },
161 object => Foo->new( number => 2 ),
163 isa_ok( $foo, 'Foo' );
165 my $yaml = $foo->freeze({ 'format' => 'YAML' });
167 my $bar = Foo->thaw( $yaml, { 'format' => 'YAML' } );
168 isa_ok( $bar, 'Foo' );
170 is( $bar->number, 10, '... got the right number' );
171 is( $bar->string, 'foo', '... got the right string' );
172 is( $bar->float, 10.5, '... got the right float' );
173 cmp_deeply( $bar->array, [ 1 .. 10 ], '... got the right array' );
176 { map { $_ => undef } ( 1 .. 10 ) },
177 '... got the right hash'
180 isa_ok( $bar->object, 'Foo' );
181 is( $bar->object->number, 2,
182 '... got the right number (in the embedded object)' );