11 'Test::JSON' => 0.01, # skip all if not installed
18 use_ok('MooseX::Storage');
21 diag('Using implementation: ', YAML::Any->implementation);
28 with 'MooseX::Storage::Deferred';
30 has 'number' => ( is => 'ro', isa => 'Int' );
31 has 'string' => ( is => 'ro', isa => 'Str' );
32 has 'float' => ( is => 'ro', isa => 'Num' );
33 has 'array' => ( is => 'ro', isa => 'ArrayRef' );
34 has 'hash' => ( is => 'ro', isa => 'HashRef' );
35 has 'object' => ( is => 'ro', isa => 'Object' );
44 hash => { map { $_ => undef } ( 1 .. 10 ) },
45 object => Foo->new( number => 2 ),
47 isa_ok( $foo, 'Foo' );
49 my $json = $foo->freeze({ 'format' => 'JSON' });
51 is_valid_json($json, '.. this is valid JSON');
55 '{"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"}',
56 '... got the right JSON'
62 '{"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"}',
63 { 'format' => 'JSON' }
65 isa_ok( $foo, 'Foo' );
67 is( $foo->number, 10, '... got the right number' );
68 is( $foo->string, 'foo', '... got the right string' );
69 is( $foo->float, 10.5, '... got the right float' );
70 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
73 { map { $_ => undef } ( 1 .. 10 ) },
74 '... got the right hash'
77 isa_ok( $foo->object, 'Foo' );
78 is( $foo->object->number, 2,
79 '... got the right number (in the embedded object)' );
88 hash => { map { $_ => undef } ( 1 .. 10 ) },
89 object => Foo->new( number => 2 ),
91 isa_ok( $foo, 'Foo' );
93 my $stored = $foo->freeze({ 'format' => 'Storable' });
95 my $struct = Storable::thaw($stored);
103 'array' => [ 1 .. 10],
104 'hash' => { map { $_ => undef } 1 .. 10 },
106 '__CLASS__' => 'Foo',
110 '... got the data struct we expected'
115 my $stored = Storable::nfreeze({
116 '__CLASS__' => 'Foo',
120 'array' => [ 1 .. 10],
121 'hash' => { map { $_ => undef } 1 .. 10 },
123 '__CLASS__' => 'Foo',
128 my $foo = Foo->thaw($stored, { 'format' => 'Storable' });
129 isa_ok( $foo, 'Foo' );
131 is( $foo->number, 10, '... got the right number' );
132 is( $foo->string, 'foo', '... got the right string' );
133 is( $foo->float, 10.5, '... got the right float' );
134 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
137 { map { $_ => undef } ( 1 .. 10 ) },
138 '... got the right hash'
141 isa_ok( $foo->object, 'Foo' );
142 is( $foo->object->number, 2,
143 '... got the right number (in the embedded object)' );
151 array => [ 1 .. 10 ],
152 hash => { map { $_ => undef } ( 1 .. 10 ) },
153 object => Foo->new( number => 2 ),
155 isa_ok( $foo, 'Foo' );
157 my $yaml = $foo->freeze({ 'format' => 'YAML' });
159 my $bar = Foo->thaw( $yaml, { 'format' => 'YAML' } );
160 isa_ok( $bar, 'Foo' );
162 is( $bar->number, 10, '... got the right number' );
163 is( $bar->string, 'foo', '... got the right string' );
164 is( $bar->float, 10.5, '... got the right float' );
165 is_deeply( $bar->array, [ 1 .. 10 ], '... got the right array' );
168 { map { $_ => undef } ( 1 .. 10 ) },
169 '... got the right hash'
172 isa_ok( $bar->object, 'Foo' );
173 is( $bar->object->number, 2,
174 '... got the right number (in the embedded object)' );