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