line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Blatte; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
60817
|
use strict; |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
544
|
|
4
|
12
|
|
|
12
|
|
60
|
use base 'Exporter'; |
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
1705
|
|
5
|
12
|
|
|
12
|
|
66
|
use vars qw($VERSION @EXPORT_OK); |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
1148
|
|
6
|
|
|
|
|
|
|
|
7
|
12
|
|
|
12
|
|
6797
|
use Blatte::Ws; |
|
12
|
|
|
|
|
42
|
|
|
12
|
|
|
|
|
577
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
12
|
|
|
12
|
|
34
|
$VERSION = '0.9.4'; |
11
|
12
|
|
|
|
|
502
|
@EXPORT_OK = qw(Parse traverse |
12
|
|
|
|
|
|
|
flatten |
13
|
|
|
|
|
|
|
wrapws unwrapws wsof |
14
|
|
|
|
|
|
|
true quote); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $parser; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub Parse { |
20
|
43
|
|
|
43
|
1
|
25348
|
my $input = shift; |
21
|
|
|
|
|
|
|
|
22
|
43
|
100
|
|
|
|
158
|
if (!defined($parser)) { |
23
|
12
|
|
|
12
|
|
35738
|
use Blatte::Parser; |
|
12
|
|
|
|
|
44
|
|
|
12
|
|
|
|
|
8492
|
|
24
|
12
|
50
|
|
|
|
166
|
$parser = new Blatte::Parser() unless defined($parser); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
43
|
|
|
|
|
222
|
$parser->parse($input); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub wrapws { |
31
|
304
|
|
|
304
|
1
|
9246
|
my($ws, $obj) = @_; |
32
|
304
|
|
|
|
|
1415
|
new Blatte::Ws($ws, $obj); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub unwrapws { |
36
|
113
|
|
|
113
|
1
|
398
|
my $obj = shift; |
37
|
113
|
100
|
100
|
|
|
731
|
if (defined($obj) && UNIVERSAL::isa($obj, 'Blatte::Ws')) { |
38
|
40
|
|
|
|
|
115
|
return &unwrapws($obj->obj()); |
39
|
|
|
|
|
|
|
} |
40
|
73
|
|
|
|
|
623
|
$obj; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub wsof { |
44
|
110
|
|
|
110
|
1
|
225
|
my $obj = shift; |
45
|
110
|
50
|
33
|
|
|
759
|
if (defined($obj) && UNIVERSAL::isa($obj, 'Blatte::Ws')) { |
46
|
110
|
|
|
|
|
321
|
return $obj->ws(); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
0
|
''; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub true { |
52
|
12
|
|
|
12
|
1
|
600
|
my $obj = &unwrapws(shift); |
53
|
|
|
|
|
|
|
|
54
|
12
|
100
|
100
|
|
|
96
|
if (defined($obj) && (ref($obj) eq 'ARRAY')) { |
55
|
3
|
50
|
|
|
|
57
|
@$obj && $obj; # empty array counts as false |
56
|
|
|
|
|
|
|
} else { |
57
|
9
|
|
|
|
|
126
|
$obj; # else use Perl rules |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub quote { |
62
|
0
|
|
|
0
|
1
|
0
|
my $str = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
if ($str eq '') { |
|
|
0
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
$str = '\\"\\"'; |
66
|
|
|
|
|
|
|
} elsif ($str =~ /\s/) { |
67
|
0
|
|
|
|
|
0
|
$str =~ s/\\/\\\\/g; |
68
|
0
|
|
|
|
|
0
|
$str = "\\\"$str\\\""; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
0
|
$str =~ s/([\\{}])/\\$1/g; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
0
|
$str; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub traverse { |
76
|
140
|
|
|
140
|
1
|
216
|
my($obj, $cb, $ws) = @_; |
77
|
|
|
|
|
|
|
|
78
|
140
|
100
|
|
|
|
868
|
if (UNIVERSAL::isa($obj, 'Blatte::Ws')) { |
79
|
68
|
100
|
|
|
|
285
|
return &traverse($obj->obj(), $cb, (defined($ws) ? $ws : $obj->ws())); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
72
|
100
|
|
|
|
179
|
if (ref($obj) eq 'ARRAY') { |
83
|
17
|
|
|
|
|
24
|
my $result; |
84
|
|
|
|
|
|
|
|
85
|
17
|
100
|
|
|
|
306
|
if (@$obj) { |
86
|
10
|
|
|
|
|
37
|
$result = &traverse($obj->[0], $cb, $ws); |
87
|
10
|
|
|
|
|
32
|
foreach my $subobj (@{$obj}[1 .. $#$obj]) { |
|
10
|
|
|
|
|
27
|
|
88
|
19
|
50
|
|
|
|
57
|
my $r2 = &traverse($subobj, $cb, ($result ? undef : $ws)); |
89
|
19
|
|
33
|
|
|
346
|
$result ||= $r2; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
17
|
|
|
|
|
42
|
return $result; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
55
|
|
|
|
|
193
|
return &$cb($ws, $obj); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub flatten { |
100
|
43
|
|
|
43
|
1
|
283
|
my($obj, $inital_ws) = @_; |
101
|
|
|
|
|
|
|
|
102
|
43
|
|
|
|
|
75
|
my $result = ''; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
&traverse($obj, sub { |
105
|
55
|
|
|
55
|
|
91
|
my($ws, $obj) = @_; |
106
|
55
|
50
|
|
|
|
141
|
$result .= $ws if defined($ws); |
107
|
55
|
|
|
|
|
110
|
$result .= $obj; |
108
|
55
|
|
|
|
|
149
|
return 1; |
109
|
43
|
|
|
|
|
339
|
}, $inital_ws); |
110
|
|
|
|
|
|
|
|
111
|
43
|
|
|
|
|
289
|
$result; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |