line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Transit::Reader; |
2
|
4
|
|
|
4
|
|
1330
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
114
|
|
3
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
72
|
|
4
|
4
|
|
|
4
|
|
11
|
no warnings 'uninitialized'; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
126
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.8.04'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
3019
|
use JSON; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my ($class, %args) = @_; |
12
|
|
|
|
|
|
|
return bless { |
13
|
|
|
|
|
|
|
%args, |
14
|
|
|
|
|
|
|
cache => [], |
15
|
|
|
|
|
|
|
cache_counter => 0, |
16
|
|
|
|
|
|
|
}, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub read { |
20
|
|
|
|
|
|
|
my ($self, $json) = @_; |
21
|
|
|
|
|
|
|
return $self->_convert($self->_decode($json)); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _convert_from_cached { |
25
|
|
|
|
|
|
|
my ($self, $data) = @_; |
26
|
|
|
|
|
|
|
return $self->_convert($self->_cache($data, 1)); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _cache { |
30
|
|
|
|
|
|
|
my ($self, $data, $cacheable) = @_; |
31
|
|
|
|
|
|
|
return $self->{cache}[$1] if $data =~ /^\^(\d+)$/; |
32
|
|
|
|
|
|
|
$self->{cache}->[$self->{cache_counter}++] = $data if length($data) > 3 && $cacheable; |
33
|
|
|
|
|
|
|
return $data; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _convert { |
37
|
|
|
|
|
|
|
my ($self, $json) = @_; |
38
|
|
|
|
|
|
|
if (ref($json) eq 'ARRAY') { |
39
|
|
|
|
|
|
|
return $self->_convert($json->[1]) if $json->[0] eq "~#'"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if ($self->_cache($json->[0], $json->[0] =~ /^~#/) =~ /^~#(.+)$/) { |
42
|
|
|
|
|
|
|
return $self->{handlers}{$1}->fromRep(@$json[1..$#$json]); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return $self->_convert_map($json) if $json->[0] eq "^ "; |
46
|
|
|
|
|
|
|
return [map {$self->_convert($_)} @$json]; |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
return "" if $json eq "~_"; |
49
|
|
|
|
|
|
|
return $json ? 1 : 0 if JSON::is_bool($json); |
50
|
|
|
|
|
|
|
return 1 if $json eq "~?t"; |
51
|
|
|
|
|
|
|
return 0 if $json eq "~?f"; |
52
|
|
|
|
|
|
|
return $1 if $json =~ /^~.(.+)$/; |
53
|
|
|
|
|
|
|
return $json; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _convert_map { |
58
|
|
|
|
|
|
|
my ($self, $map) = @_; |
59
|
|
|
|
|
|
|
my %map = @$map[1..$#$map]; |
60
|
|
|
|
|
|
|
return {map {$self->_convert_from_cached($_) => $self->_convert($map{$_})} keys %map}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |