11 eval "use Test::JSON; use Test::YAML::Valid;";
12 plan skip_all => "Test::JSON and Test::YAML::Valid are required for this test" if $@;
14 plan skip_all => "JSON::Any is required for this test" if $@;
16 use_ok('MooseX::Storage');
25 with 'MooseX::Storage::Deferred';
27 has 'number' => ( is => 'ro', isa => 'Int' );
28 has 'string' => ( is => 'ro', isa => 'Str' );
29 has 'float' => ( is => 'ro', isa => 'Num' );
30 has 'array' => ( is => 'ro', isa => 'ArrayRef' );
31 has 'hash' => ( is => 'ro', isa => 'HashRef' );
32 has 'object' => ( is => 'ro', isa => 'Object' );
41 hash => { map { $_ => undef } ( 1 .. 10 ) },
42 object => Foo->new( number => 2 ),
44 isa_ok( $foo, 'Foo' );
46 my $json = $foo->freeze({ 'format' => 'JSON' });
48 is_valid_json($json, '.. this is valid JSON');
52 '{"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"}',
53 '... got the right JSON'
59 '{"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"}',
60 { 'format' => 'JSON' }
62 isa_ok( $foo, 'Foo' );
64 is( $foo->number, 10, '... got the right number' );
65 is( $foo->string, 'foo', '... got the right string' );
66 is( $foo->float, 10.5, '... got the right float' );
67 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
70 { map { $_ => undef } ( 1 .. 10 ) },
71 '... got the right hash'
74 isa_ok( $foo->object, 'Foo' );
75 is( $foo->object->number, 2,
76 '... got the right number (in the embedded object)' );
85 hash => { map { $_ => undef } ( 1 .. 10 ) },
86 object => Foo->new( number => 2 ),
88 isa_ok( $foo, 'Foo' );
90 my $stored = $foo->freeze({ 'format' => 'Storable' });
92 my $struct = Storable::thaw($stored);
100 'array' => [ 1 .. 10],
101 'hash' => { map { $_ => undef } 1 .. 10 },
103 '__CLASS__' => 'Foo',
107 '... got the data struct we expected'
112 my $stored = Storable::nfreeze({
113 '__CLASS__' => 'Foo',
117 'array' => [ 1 .. 10],
118 'hash' => { map { $_ => undef } 1 .. 10 },
120 '__CLASS__' => 'Foo',
125 my $foo = Foo->thaw($stored, { 'format' => 'Storable' });
126 isa_ok( $foo, 'Foo' );
128 is( $foo->number, 10, '... got the right number' );
129 is( $foo->string, 'foo', '... got the right string' );
130 is( $foo->float, 10.5, '... got the right float' );
131 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
134 { map { $_ => undef } ( 1 .. 10 ) },
135 '... got the right hash'
138 isa_ok( $foo->object, 'Foo' );
139 is( $foo->object->number, 2,
140 '... got the right number (in the embedded object)' );
148 array => [ 1 .. 10 ],
149 hash => { map { $_ => undef } ( 1 .. 10 ) },
150 object => Foo->new( number => 2 ),
152 isa_ok( $foo, 'Foo' );
154 my $yaml = $foo->freeze({ 'format' => 'YAML' });
156 yaml_string_ok( $yaml, '... we got valid YAML out of it' );
191 '... got the same YAML'
228 }, { 'format' => 'YAML' }
230 isa_ok( $foo, 'Foo' );
232 is( $foo->number, 10, '... got the right number' );
233 is( $foo->string, 'foo', '... got the right string' );
234 is( $foo->float, 10.5, '... got the right float' );
235 is_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
238 { map { $_ => undef } ( 1 .. 10 ) },
239 '... got the right hash'
242 isa_ok( $foo->object, 'Foo' );
243 is( $foo->object->number, 2,
244 '... got the right number (in the embedded object)' );