line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::Utils; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
72391
|
use base qw(Exporter); |
|
27
|
|
|
|
|
90
|
|
|
27
|
|
|
|
|
2958
|
|
4
|
27
|
|
|
27
|
|
172
|
use strict; |
|
27
|
|
|
|
|
61
|
|
|
27
|
|
|
|
|
871
|
|
5
|
27
|
|
|
27
|
|
138
|
use warnings; |
|
27
|
|
|
|
|
42
|
|
|
27
|
|
|
|
|
982
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
2385
|
use Error::Pure qw(err); |
|
27
|
|
|
|
|
64932
|
|
|
27
|
|
|
|
|
1147
|
|
8
|
27
|
|
|
27
|
|
13622
|
use HTML::Entities; |
|
27
|
|
|
|
|
157443
|
|
|
27
|
|
|
|
|
1982
|
|
9
|
27
|
|
|
27
|
|
203
|
use Readonly; |
|
27
|
|
|
|
|
67
|
|
|
27
|
|
|
|
|
11986
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Constants. |
12
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(encode_newline encode_attr_entities |
13
|
|
|
|
|
|
|
encode_char_entities); |
14
|
|
|
|
|
|
|
Readonly::Scalar my $ATTR_CHARS => q{<&"}; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $CHAR_CHARS => q{<&\240}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EMPTY_STR => q{}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 0.13; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Encode newline in data to '\n' in output. |
21
|
|
|
|
|
|
|
sub encode_newline { |
22
|
1
|
|
|
1
|
1
|
85
|
my $string = shift; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
6
|
$string =~ s/\n/\\n/gms; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
4
|
return $string; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Encode '<&"' attribute entities. |
30
|
|
|
|
|
|
|
sub encode_attr_entities { |
31
|
92
|
|
|
92
|
1
|
2443
|
my $data_r = shift; |
32
|
|
|
|
|
|
|
|
33
|
92
|
100
|
|
|
|
204
|
if (ref $data_r eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
62
|
|
|
|
|
87
|
${$data_r} = encode_entities(decode_entities(${$data_r}), |
|
62
|
|
|
|
|
3758
|
|
|
62
|
|
|
|
|
295
|
|
35
|
|
|
|
|
|
|
$ATTR_CHARS); |
36
|
|
|
|
|
|
|
} elsif (ref $data_r eq 'ARRAY') { |
37
|
29
|
|
|
|
|
42
|
foreach my $one_data (@{$data_r}) { |
|
29
|
|
|
|
|
57
|
|
38
|
61
|
|
|
|
|
120
|
encode_attr_entities(\$one_data); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} elsif (ref $data_r eq $EMPTY_STR) { |
41
|
1
|
|
|
|
|
14
|
return encode_entities(decode_entities($data_r), $ATTR_CHARS); |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
0
|
err 'Reference \''.(ref $data_r).'\' doesn\'t supported.'; |
44
|
|
|
|
|
|
|
} |
45
|
91
|
|
|
|
|
179
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Encode '<&NBSP' char entities. |
49
|
|
|
|
|
|
|
sub encode_char_entities { |
50
|
77
|
|
|
77
|
1
|
1932
|
my $data_r = shift; |
51
|
|
|
|
|
|
|
|
52
|
77
|
100
|
|
|
|
216
|
if (ref $data_r eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
53
|
42
|
|
|
|
|
61
|
${$data_r} = encode_entities(decode_entities(${$data_r}), |
|
42
|
|
|
|
|
3325
|
|
|
42
|
|
|
|
|
315
|
|
54
|
|
|
|
|
|
|
$CHAR_CHARS); |
55
|
|
|
|
|
|
|
} elsif (ref $data_r eq 'ARRAY') { |
56
|
34
|
|
|
|
|
48
|
foreach my $one_data (@{$data_r}) { |
|
34
|
|
|
|
|
74
|
|
57
|
41
|
|
|
|
|
100
|
encode_char_entities(\$one_data); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} elsif (ref $data_r eq $EMPTY_STR) { |
60
|
1
|
|
|
|
|
13
|
return encode_entities(decode_entities($data_r), $CHAR_CHARS); |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
0
|
err 'Reference \''.(ref $data_r).'\' doesn\'t supported.'; |
63
|
|
|
|
|
|
|
} |
64
|
76
|
|
|
|
|
182
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |