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/) { | |
65 | skip "No JSON module found", 1; | |
66 | } | |
69b45b7d | 67 | |
c2dae5d8 | 68 | is('Foo', $classname, |
021c860a | 69 | '... got the right class name from the json item'); |
70 | } | |
71 | ||
72 | SKIP: { | |
c2dae5d8 | 73 | my $classname = eval { |
021c860a | 74 | MooseX::Storage::Util->peek($yaml => ('format' => 'YAML')) |
75 | }; | |
5aaf0d46 | 76 | if ($@ =~ /^Could not load YAML module because/ |
77 | or $@ =~ /^Can't locate Best/ | |
78 | ) { | |
021c860a | 79 | skip "No YAML module found", 1; |
c2dae5d8 | 80 | } |
81 | ||
82 | is('Foo', $classname, | |
021c860a | 83 | '... got the right class name from the yaml item'); |
84 | } | |
69b45b7d | 85 | |
86 |