line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::Utils; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
61623
|
use base qw(Exporter); |
|
27
|
|
|
|
|
73
|
|
|
27
|
|
|
|
|
2645
|
|
4
|
27
|
|
|
27
|
|
140
|
use strict; |
|
27
|
|
|
|
|
41
|
|
|
27
|
|
|
|
|
740
|
|
5
|
27
|
|
|
27
|
|
108
|
use warnings; |
|
27
|
|
|
|
|
39
|
|
|
27
|
|
|
|
|
841
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
1939
|
use Error::Pure qw(err); |
|
27
|
|
|
|
|
52331
|
|
|
27
|
|
|
|
|
1411
|
|
8
|
27
|
|
|
27
|
|
11911
|
use HTML::Entities; |
|
27
|
|
|
|
|
141591
|
|
|
27
|
|
|
|
|
1871
|
|
9
|
27
|
|
|
27
|
|
177
|
use Readonly; |
|
27
|
|
|
|
|
60
|
|
|
27
|
|
|
|
|
10512
|
|
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.12; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Encode newline in data to '\n' in output. |
21
|
|
|
|
|
|
|
sub encode_newline { |
22
|
1
|
|
|
1
|
1
|
67
|
my $string = shift; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
$string =~ s/\n/\\n/gms; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
return $string; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Encode '<&"' attribute entities. |
30
|
|
|
|
|
|
|
sub encode_attr_entities { |
31
|
92
|
|
|
92
|
1
|
1796
|
my $data_r = shift; |
32
|
|
|
|
|
|
|
|
33
|
92
|
100
|
|
|
|
174
|
if (ref $data_r eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
62
|
|
|
|
|
61
|
${$data_r} = encode_entities(decode_entities(${$data_r}), |
|
62
|
|
|
|
|
2697
|
|
|
62
|
|
|
|
|
234
|
|
35
|
|
|
|
|
|
|
$ATTR_CHARS); |
36
|
|
|
|
|
|
|
} elsif (ref $data_r eq 'ARRAY') { |
37
|
29
|
|
|
|
|
35
|
foreach my $one_data (@{$data_r}) { |
|
29
|
|
|
|
|
44
|
|
38
|
61
|
|
|
|
|
106
|
encode_attr_entities(\$one_data); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} elsif (ref $data_r eq $EMPTY_STR) { |
41
|
1
|
|
|
|
|
11
|
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
|
|
|
|
|
142
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Encode '<&NBSP' char entities. |
49
|
|
|
|
|
|
|
sub encode_char_entities { |
50
|
75
|
|
|
75
|
1
|
1844
|
my $data_r = shift; |
51
|
|
|
|
|
|
|
|
52
|
75
|
100
|
|
|
|
157
|
if (ref $data_r eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
53
|
41
|
|
|
|
|
53
|
${$data_r} = encode_entities(decode_entities(${$data_r}), |
|
41
|
|
|
|
|
2536
|
|
|
41
|
|
|
|
|
221
|
|
54
|
|
|
|
|
|
|
$CHAR_CHARS); |
55
|
|
|
|
|
|
|
} elsif (ref $data_r eq 'ARRAY') { |
56
|
33
|
|
|
|
|
38
|
foreach my $one_data (@{$data_r}) { |
|
33
|
|
|
|
|
61
|
|
57
|
40
|
|
|
|
|
101
|
encode_char_entities(\$one_data); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} elsif (ref $data_r eq $EMPTY_STR) { |
60
|
1
|
|
|
|
|
12
|
return encode_entities(decode_entities($data_r), $CHAR_CHARS); |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
0
|
err 'Reference \''.(ref $data_r).'\' doesn\'t supported.'; |
63
|
|
|
|
|
|
|
} |
64
|
74
|
|
|
|
|
135
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |