10 'Test::JSON' => 0.01, # 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' });
50 is_valid_json($json, '.. this is valid JSON');
54 '{"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"}',
55 '... got the right JSON'
61 '{"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"}',
62 { 'format' => 'JSON' }
64 isa_ok( $foo, 'Foo' );
66 is( $foo->number, 10, '... got the right number' );
67 is( $foo->string, 'foo', '... got the right string' );
68 is( $foo->float, 10.5, '... got the right float' );
69 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
72 { map { $_ => undef } ( 1 .. 10 ) },
73 '... got the right hash'
76 isa_ok( $foo->object, 'Foo' );
77 is( $foo->object->number, 2,
78 '... got the right number (in the embedded object)' );
87 hash => { map { $_ => undef } ( 1 .. 10 ) },
88 object => Foo->new( number => 2 ),
90 isa_ok( $foo, 'Foo' );
92 my $stored = $foo->freeze({ 'format' => 'Storable' });
94 my $struct = Storable::thaw($stored);
102 'array' => [ 1 .. 10],
103 'hash' => { map { $_ => undef } 1 .. 10 },
105 '__CLASS__' => 'Foo',
109 '... got the data struct we expected'
114 my $stored = Storable::nfreeze({
115 '__CLASS__' => 'Foo',
119 'array' => [ 1 .. 10],
120 'hash' => { map { $_ => undef } 1 .. 10 },
122 '__CLASS__' => 'Foo',
127 my $foo = Foo->thaw($stored, { 'format' => 'Storable' });
128 isa_ok( $foo, 'Foo' );
130 is( $foo->number, 10, '... got the right number' );
131 is( $foo->string, 'foo', '... got the right string' );
132 is( $foo->float, 10.5, '... got the right float' );
133 cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
136 { map { $_ => undef } ( 1 .. 10 ) },
137 '... got the right hash'
140 isa_ok( $foo->object, 'Foo' );
141 is( $foo->object->number, 2,
142 '... got the right number (in the embedded object)' );
150 array => [ 1 .. 10 ],
151 hash => { map { $_ => undef } ( 1 .. 10 ) },
152 object => Foo->new( number => 2 ),
154 isa_ok( $foo, 'Foo' );
156 my $yaml = $foo->freeze({ 'format' => 'YAML' });
158 my $bar = Foo->thaw( $yaml, { 'format' => 'YAML' } );
159 isa_ok( $bar, 'Foo' );
161 is( $bar->number, 10, '... got the right number' );
162 is( $bar->string, 'foo', '... got the right string' );
163 is( $bar->float, 10.5, '... got the right float' );
164 cmp_deeply( $bar->array, [ 1 .. 10 ], '... got the right array' );
167 { map { $_ => undef } ( 1 .. 10 ) },
168 '... got the right hash'
171 isa_ok( $bar->object, 'Foo' );
172 is( $bar->object->number, 2,
173 '... got the right number (in the embedded object)' );