6 use Test::More tests => 33;
12 $ENV{JSON_ANY_ORDER} = qw(JSON);
13 use_ok('MooseX::Storage');
22 with 'MooseX::Storage::Deferred';
24 has 'number' => ( is => 'ro', isa => 'Int' );
25 has 'string' => ( is => 'ro', isa => 'Str' );
26 has 'float' => ( is => 'ro', isa => 'Num' );
27 has 'array' => ( is => 'ro', isa => 'ArrayRef' );
28 has 'hash' => ( is => 'ro', isa => 'HashRef' );
29 has 'object' => ( is => 'ro', isa => 'Object' );
38 hash => { map { $_ => undef } ( 1 .. 10 ) },
39 object => Foo->new( number => 2 ),
41 isa_ok( $foo, 'Foo' );
43 my $json = $foo->freeze({ 'format' => 'JSON' });
45 is_valid_json($json, '.. this is valid JSON');
49 '{"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"}',
50 '... got the right JSON'
56 '{"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"}',
57 { 'format' => 'JSON' }
59 isa_ok( $foo, 'Foo' );
61 is( $foo->number, 10, '... got the right number' );
62 is( $foo->string, 'foo', '... got the right string' );
63 is( $foo->float, 10.5, '... got the right float' );
64 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
67 { map { $_ => undef } ( 1 .. 10 ) },
68 '... got the right hash'
71 isa_ok( $foo->object, 'Foo' );
72 is( $foo->object->number, 2,
73 '... got the right number (in the embedded object)' );
82 hash => { map { $_ => undef } ( 1 .. 10 ) },
83 object => Foo->new( number => 2 ),
85 isa_ok( $foo, 'Foo' );
87 my $stored = $foo->freeze({ 'format' => 'Storable' });
89 my $struct = Storable::thaw($stored);
97 'array' => [ 1 .. 10],
98 'hash' => { map { $_ => undef } 1 .. 10 },
100 '__CLASS__' => 'Foo',
104 '... got the data struct we expected'
109 my $stored = Storable::nfreeze({
110 '__CLASS__' => 'Foo',
114 'array' => [ 1 .. 10],
115 'hash' => { map { $_ => undef } 1 .. 10 },
117 '__CLASS__' => 'Foo',
122 my $foo = Foo->thaw($stored, { 'format' => 'Storable' });
123 isa_ok( $foo, 'Foo' );
125 is( $foo->number, 10, '... got the right number' );
126 is( $foo->string, 'foo', '... got the right string' );
127 is( $foo->float, 10.5, '... got the right float' );
128 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
131 { map { $_ => undef } ( 1 .. 10 ) },
132 '... got the right hash'
135 isa_ok( $foo->object, 'Foo' );
136 is( $foo->object->number, 2,
137 '... got the right number (in the embedded object)' );
145 array => [ 1 .. 10 ],
146 hash => { map { $_ => undef } ( 1 .. 10 ) },
147 object => Foo->new( number => 2 ),
149 isa_ok( $foo, 'Foo' );
151 my $yaml = $foo->freeze({ 'format' => 'YAML' });
153 yaml_string_ok( $yaml, '... we got valid YAML out of it' );
188 '... got the same YAML'
225 }, { 'format' => 'YAML' }
227 isa_ok( $foo, 'Foo' );
229 is( $foo->number, 10, '... got the right number' );
230 is( $foo->string, 'foo', '... got the right string' );
231 is( $foo->float, 10.5, '... got the right float' );
232 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
235 { map { $_ => undef } ( 1 .. 10 ) },
236 '... got the right hash'
239 isa_ok( $foo->object, 'Foo' );
240 is( $foo->object->number, 2,
241 '... got the right number (in the embedded object)' );