line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::Utils; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
79736
|
use base qw(Exporter); |
|
27
|
|
|
|
|
83
|
|
|
27
|
|
|
|
|
2973
|
|
4
|
27
|
|
|
27
|
|
166
|
use strict; |
|
27
|
|
|
|
|
58
|
|
|
27
|
|
|
|
|
930
|
|
5
|
27
|
|
|
27
|
|
168
|
use warnings; |
|
27
|
|
|
|
|
63
|
|
|
27
|
|
|
|
|
922
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
2375
|
use Error::Pure qw(err); |
|
27
|
|
|
|
|
66356
|
|
|
27
|
|
|
|
|
1171
|
|
8
|
27
|
|
|
27
|
|
14133
|
use HTML::Entities; |
|
27
|
|
|
|
|
157343
|
|
|
27
|
|
|
|
|
1907
|
|
9
|
27
|
|
|
27
|
|
191
|
use Readonly; |
|
27
|
|
|
|
|
52
|
|
|
27
|
|
|
|
|
11883
|
|
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.14; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Encode newline in data to '\n' in output. |
21
|
|
|
|
|
|
|
sub encode_newline { |
22
|
1
|
|
|
1
|
1
|
83
|
my $string = shift; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
5
|
$string =~ s/\n/\\n/gms; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
5
|
return $string; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Encode '<&"' attribute entities. |
30
|
|
|
|
|
|
|
sub encode_attr_entities { |
31
|
92
|
|
|
92
|
1
|
1783
|
my $data_r = shift; |
32
|
|
|
|
|
|
|
|
33
|
92
|
100
|
|
|
|
211
|
if (ref $data_r eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
62
|
|
|
|
|
82
|
${$data_r} = encode_entities(decode_entities(${$data_r}), |
|
62
|
|
|
|
|
3222
|
|
|
62
|
|
|
|
|
291
|
|
35
|
|
|
|
|
|
|
$ATTR_CHARS); |
36
|
|
|
|
|
|
|
} elsif (ref $data_r eq 'ARRAY') { |
37
|
29
|
|
|
|
|
39
|
foreach my $one_data (@{$data_r}) { |
|
29
|
|
|
|
|
57
|
|
38
|
61
|
|
|
|
|
132
|
encode_attr_entities(\$one_data); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} elsif (ref $data_r eq $EMPTY_STR) { |
41
|
1
|
|
|
|
|
13
|
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
|
|
|
|
|
188
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Encode '<&NBSP' char entities. |
49
|
|
|
|
|
|
|
sub encode_char_entities { |
50
|
77
|
|
|
77
|
1
|
1833
|
my $data_r = shift; |
51
|
|
|
|
|
|
|
|
52
|
77
|
100
|
|
|
|
210
|
if (ref $data_r eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
53
|
42
|
|
|
|
|
63
|
${$data_r} = encode_entities(decode_entities(${$data_r}), |
|
42
|
|
|
|
|
3360
|
|
|
42
|
|
|
|
|
262
|
|
54
|
|
|
|
|
|
|
$CHAR_CHARS); |
55
|
|
|
|
|
|
|
} elsif (ref $data_r eq 'ARRAY') { |
56
|
34
|
|
|
|
|
55
|
foreach my $one_data (@{$data_r}) { |
|
34
|
|
|
|
|
73
|
|
57
|
41
|
|
|
|
|
107
|
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
|
|
|
|
|
166
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |