Commit | Line | Data |
69b45b7d |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More tests => 5; |
5 | |
6 | BEGIN { |
7 | use_ok('MooseX::Storage'); |
c2dae5d8 |
8 | use_ok('MooseX::Storage::Util'); |
69b45b7d |
9 | } |
10 | |
11 | my $packed = { |
12 | __CLASS__ => 'Foo', |
13 | number => 10, |
14 | string => 'foo', |
15 | float => 10.5, |
16 | array => [ 1 .. 10 ], |
17 | hash => { map { $_ => undef } ( 1 .. 10 ) }, |
c2dae5d8 |
18 | object => { |
19 | __CLASS__ => 'Foo', |
20 | number => 2 |
21 | }, |
69b45b7d |
22 | }; |
23 | |
24 | my $json = '{"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"}'; |
c2dae5d8 |
25 | my $yaml = q{--- |
69b45b7d |
26 | __CLASS__: Foo |
c2dae5d8 |
27 | array: |
69b45b7d |
28 | - 1 |
29 | - 2 |
30 | - 3 |
31 | - 4 |
32 | - 5 |
33 | - 6 |
34 | - 7 |
35 | - 8 |
36 | - 9 |
37 | - 10 |
38 | float: 10.5 |
c2dae5d8 |
39 | hash: |
69b45b7d |
40 | 1: ~ |
41 | 10: ~ |
42 | 2: ~ |
43 | 3: ~ |
44 | 4: ~ |
45 | 5: ~ |
46 | 6: ~ |
47 | 7: ~ |
48 | 8: ~ |
49 | 9: ~ |
50 | number: 10 |
c2dae5d8 |
51 | object: |
69b45b7d |
52 | __CLASS__: Foo |
53 | number: 2 |
54 | string: foo |
55 | }; |
56 | |
c2dae5d8 |
57 | is('Foo', MooseX::Storage::Util->peek($packed), |
021c860a |
58 | '... got the right class name from the packed item'); |
69b45b7d |
59 | |
021c860a |
60 | SKIP: { |
c2dae5d8 |
61 | my $classname = eval { |
62 | MooseX::Storage::Util->peek($json => ('format' => 'JSON')) |
021c860a |
63 | }; |
64 | if ($@ =~ /^Could not load JSON module because/) { |
3f3dcd72 |
65 | die 'No JSON module found' if $ENV{AUTHOR_TESTING}; |
021c860a |
66 | skip "No JSON module found", 1; |
67 | } |
69b45b7d |
68 | |
c2dae5d8 |
69 | is('Foo', $classname, |
021c860a |
70 | '... got the right class name from the json item'); |
71 | } |
72 | |
73 | SKIP: { |
c2dae5d8 |
74 | my $classname = eval { |
021c860a |
75 | MooseX::Storage::Util->peek($yaml => ('format' => 'YAML')) |
76 | }; |
5aaf0d46 |
77 | if ($@ =~ /^Could not load YAML module because/ |
78 | or $@ =~ /^Can't locate Best/ |
79 | ) { |
3f3dcd72 |
80 | die 'No YAML module found' if $ENV{AUTHOR_TESTING}; |
021c860a |
81 | skip "No YAML module found", 1; |
c2dae5d8 |
82 | } |
83 | |
84 | is('Foo', $classname, |
021c860a |
85 | '... got the right class name from the yaml item'); |
86 | } |
69b45b7d |
87 | |
88 | |