line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::SL::Tuba; |
2
|
2
|
|
|
2
|
|
9193
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
51
|
|
3
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
799
|
use JSON::SL; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
5
|
2
|
|
|
2
|
|
9
|
use base qw(Exporter); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
260
|
|
6
|
|
|
|
|
|
|
our @EXPORT; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my (%ActionMap,%TypeMap); |
9
|
|
|
|
|
|
|
my $_cg_typehash; |
10
|
|
|
|
|
|
|
my $_cg_modehash; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
2
|
|
|
2
|
|
7
|
%ActionMap = ( |
14
|
|
|
|
|
|
|
'+' => 'start', |
15
|
|
|
|
|
|
|
'-' => 'end', |
16
|
|
|
|
|
|
|
'>' => 'on' |
17
|
|
|
|
|
|
|
); |
18
|
2
|
|
|
|
|
12
|
%TypeMap = ( |
19
|
|
|
|
|
|
|
'{' => 'object', |
20
|
|
|
|
|
|
|
'[' => 'list', |
21
|
|
|
|
|
|
|
'c' => 'data', |
22
|
|
|
|
|
|
|
'D' => 'json', |
23
|
|
|
|
|
|
|
'#' => 'key', |
24
|
|
|
|
|
|
|
'"' => 'string', |
25
|
|
|
|
|
|
|
'^' => 'special', |
26
|
|
|
|
|
|
|
'?' => 'boolean', |
27
|
|
|
|
|
|
|
'=' => 'number', |
28
|
|
|
|
|
|
|
'~' => 'null' |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
9
|
while (my ($sym,$name) = each %ActionMap) { |
32
|
6
|
|
|
|
|
20
|
$_cg_modehash->{uc($name)} = ord($sym); |
33
|
|
|
|
|
|
|
} |
34
|
2
|
|
|
|
|
7
|
while (my ($sym,$name) = each %TypeMap) { |
35
|
20
|
|
|
|
|
95
|
$_cg_typehash->{uc($name)} = ord($sym); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
863
|
use Constant::Generate $_cg_typehash, prefix => "TUBA_TYPE_", export => 1; |
|
2
|
|
|
|
|
11406
|
|
|
2
|
|
|
|
|
7
|
|
40
|
2
|
|
|
2
|
|
529
|
use Constant::Generate $_cg_modehash, prefix => "TUBA_MODE_", export =>1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our %CloseTokens = ( |
43
|
|
|
|
|
|
|
'{' => '}', |
44
|
|
|
|
|
|
|
'"' => '"', |
45
|
|
|
|
|
|
|
'[' => ']' |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
2
|
|
|
2
|
0
|
755
|
my ($cls,%options) = @_; |
50
|
2
|
|
|
|
|
131
|
my $o = $cls->_initialize(); |
51
|
|
|
|
|
|
|
|
52
|
2
|
50
|
33
|
|
|
15
|
unless (exists $options{accum_kv} and |
53
|
|
|
|
|
|
|
not delete $options{accum_kv}) { |
54
|
2
|
|
|
|
|
12
|
$o->accum_kv(1); |
55
|
|
|
|
|
|
|
} |
56
|
2
|
50
|
33
|
|
|
8
|
unless (exists $options{accum_all}and |
57
|
|
|
|
|
|
|
not delete $options{accum_all}) { |
58
|
2
|
|
|
|
|
6
|
$o->accum_all(1); |
59
|
|
|
|
|
|
|
} |
60
|
2
|
|
|
|
|
15
|
while (my ($k,$v) = each %options) { |
61
|
0
|
|
|
|
|
0
|
$o->can($k)->($o,$v); |
62
|
|
|
|
|
|
|
} |
63
|
2
|
|
|
|
|
5
|
return $o; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# TODO: I can't think why I've hidden this? |
67
|
|
|
|
|
|
|
{ |
68
|
2
|
|
|
2
|
|
545
|
no warnings 'once'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
576
|
|
69
|
|
|
|
|
|
|
*parse = *_parse; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# set accumulator parameters: |
73
|
|
|
|
|
|
|
sub accum { |
74
|
3
|
|
|
3
|
1
|
5
|
my ($tuba,%modes) = @_; |
75
|
3
|
|
|
|
|
11
|
while (my ($mode,$bool) = each %modes) { |
76
|
15
|
50
|
|
|
|
26
|
if ($mode !~ m{[\=\~\?\#"]}) { |
77
|
0
|
|
|
|
|
0
|
die("Invalid mode '$mode'. Mode must be one of [^#\"]"); |
78
|
|
|
|
|
|
|
} |
79
|
15
|
|
|
|
|
45
|
$tuba->_ax_opt(ord("$mode"), $bool); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub accum_enabled_for { |
84
|
5
|
|
|
5
|
0
|
1694
|
my ($tuba,$mode) = @_; |
85
|
5
|
50
|
|
|
|
19
|
if ($mode !~ m{[\=\~\?\#"]}) { |
86
|
0
|
|
|
|
|
0
|
die("Invalid type '$mode'. Mode must be one of [^#\"]"); |
87
|
|
|
|
|
|
|
} |
88
|
5
|
|
|
|
|
33
|
return $tuba->_ax_opt(ord("$mode")) |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub accum_all { |
92
|
3
|
|
|
3
|
1
|
5
|
my ($tuba,$boolean) = @_; |
93
|
3
|
50
|
|
|
|
9
|
if (@_ != 2) { |
94
|
0
|
|
|
|
|
0
|
die("Must have boolean argument!"); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
my %opts = map { |
97
|
3
|
|
|
|
|
4
|
$_, $boolean |
|
15
|
|
|
|
|
22
|
|
98
|
|
|
|
|
|
|
} ('=','~','#','?','"'); |
99
|
3
|
|
|
|
|
13
|
$tuba->accum(%opts); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#build convenience methods: |
103
|
|
|
|
|
|
|
foreach (['key', '#'], |
104
|
|
|
|
|
|
|
['string', '"'], |
105
|
|
|
|
|
|
|
['number', '='], |
106
|
|
|
|
|
|
|
['boolean', '?'], |
107
|
|
|
|
|
|
|
['null', '~'] |
108
|
|
|
|
|
|
|
) { |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my ($mode,$sym) = @$_; |
111
|
2
|
|
|
2
|
|
9
|
no strict 'refs'; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
135
|
|
112
|
|
|
|
|
|
|
*{"accum_$mode"} = sub { |
113
|
0
|
|
|
0
|
|
|
my ($tuba,$bool) = @_; |
114
|
0
|
|
|
|
|
|
$tuba->_ax_opt(ord($sym), $bool); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |