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