line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::EDI::Test; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
23723
|
use strict; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
299
|
|
4
|
6
|
|
|
6
|
|
36
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
190
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
8207
|
use JSON::XS; |
|
6
|
|
|
|
|
187049
|
|
|
6
|
|
|
|
|
640
|
|
7
|
6
|
|
|
6
|
|
60
|
use Exporter; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
220
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
34
|
use base qw/Exporter/; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
577
|
|
10
|
6
|
|
|
6
|
|
36
|
use vars qw/$VERSION @EXPORT_OK $parser/; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
496
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
6
|
|
|
6
|
|
14
|
$VERSION = 0.02; |
14
|
6
|
|
|
|
|
2193
|
@EXPORT_OK = qw/ JSONObject2Perl ordrsp_data pretty_json /; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub JSONObject2Perl { |
19
|
24114
|
|
|
24114
|
0
|
29368
|
my $obj = shift; |
20
|
24114
|
100
|
|
|
|
53784
|
if ( ref $obj eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
21
|
5994
|
50
|
|
|
|
17074
|
if ( defined $obj->{'__c'} ) { |
22
|
0
|
|
|
|
|
0
|
die "We somehow got a special (Evergreen) object in our data"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
# is a hash w/o class marker; simply revivify innards |
25
|
5994
|
|
|
|
|
70893
|
for my $k (keys %$obj) { |
26
|
11352
|
50
|
|
|
|
30229
|
$obj->{$k} = JSONObject2Perl($obj->{$k}) unless ref $obj->{$k} eq 'JSON::XS::Boolean'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} elsif ( ref $obj eq 'ARRAY' ) { |
29
|
5652
|
|
|
|
|
8345
|
for my $i (0..scalar(@$obj) - 1) { |
30
|
12756
|
50
|
|
|
|
37049
|
$obj->[$i] = JSONObject2Perl($obj->[$i]) unless ref $obj->[$i] eq 'JSON::XS::Boolean'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
# ELSE: return vivified non-class hashes, all arrays, and anything that isn't a hash or array ref |
34
|
24114
|
|
|
|
|
78163
|
return $obj; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub pretty_json { |
38
|
0
|
0
|
|
0
|
0
|
0
|
@_ or die "pretty_json() missing required argument"; |
39
|
0
|
0
|
|
|
|
0
|
unless ($parser) { |
40
|
0
|
|
|
|
|
0
|
$parser = JSON::XS->new; |
41
|
0
|
|
|
|
|
0
|
$parser->ascii(1); # output \u escaped strings for any char with a value over 127 |
42
|
0
|
|
|
|
|
0
|
$parser->allow_nonref(1); # allows non-reference values to equate to themselves (see perldoc) |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
return $parser->indent(1)->space_before(1)->decode(shift); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ordrsp_data { |
48
|
6
|
50
|
|
6
|
0
|
189
|
unless ($parser) { |
49
|
6
|
|
|
|
|
121
|
$parser = JSON::XS->new; |
50
|
6
|
|
|
|
|
31
|
$parser->ascii(1); # output \u escaped strings for any char with a value over 127 |
51
|
6
|
|
|
|
|
22
|
$parser->allow_nonref(1); # allows non-reference values to equate to themselves (see perldoc) |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
6
|
50
|
|
|
|
473422
|
my $slurp = join('', ) or die __PACKAGE__ . " FAILED reading DATA handle"; |
55
|
6
|
50
|
|
|
|
23732
|
my $foo = ($parser->decode($slurp)) or warn "JSON parser failed to decode DATA"; |
56
|
6
|
|
|
|
|
46
|
return JSONObject2Perl($foo); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__DATA__ |