line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xatena::Util; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
889
|
use strict; |
|
21
|
|
|
|
|
46
|
|
|
21
|
|
|
|
|
637
|
|
4
|
21
|
|
|
21
|
|
103
|
use warnings; |
|
21
|
|
|
|
|
38
|
|
|
21
|
|
|
|
|
853
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw(escape_html template unindent); |
7
|
21
|
|
|
21
|
|
18301
|
use Exporter::Lite; |
|
21
|
|
|
|
|
18719
|
|
|
21
|
|
|
|
|
144
|
|
8
|
21
|
|
|
21
|
|
19560
|
use Text::MicroTemplate; |
|
21
|
|
|
|
|
72406
|
|
|
21
|
|
|
|
|
7272
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %escape = ( |
11
|
|
|
|
|
|
|
'&' => '&', |
12
|
|
|
|
|
|
|
'<' => '<', |
13
|
|
|
|
|
|
|
'>' => '>', |
14
|
|
|
|
|
|
|
'"' => '"', |
15
|
|
|
|
|
|
|
"'" => ''', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
sub escape_html ($) { ## no critic |
18
|
22
|
|
|
22
|
0
|
53
|
my ($str) = @_; |
19
|
22
|
|
|
|
|
100
|
my $escape = join "|", keys %escape; |
20
|
22
|
|
|
|
|
301
|
$str =~ s{($escape)}{ $escape{$1} }ego; |
|
33
|
|
|
|
|
133
|
|
21
|
22
|
|
|
|
|
178
|
$str; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub unindent ($) { ## no critic |
25
|
73
|
|
|
73
|
0
|
137
|
my $string = shift; |
26
|
73
|
|
|
|
|
312
|
my ($indent) = ($string =~ /^\n?(\s*)/); |
27
|
73
|
|
|
|
|
847
|
$string =~ s/^$indent//gm; |
28
|
73
|
|
|
|
|
548
|
$string =~ s/\s+$//; |
29
|
73
|
|
|
|
|
509
|
$string; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub template ($$) { ## no critic |
33
|
71
|
|
|
71
|
0
|
139
|
my ($template, $keys) = @_; |
34
|
|
|
|
|
|
|
|
35
|
71
|
|
|
|
|
224
|
my $mt = Text::MicroTemplate->new( |
36
|
|
|
|
|
|
|
tag_start => '{{', |
37
|
|
|
|
|
|
|
tag_end => '}}', |
38
|
|
|
|
|
|
|
template => unindent $template, |
39
|
|
|
|
|
|
|
escape_func => undef, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
71
|
|
|
|
|
24296
|
my $code = $mt->code; |
43
|
71
|
|
|
|
|
13903
|
my $expand = join('; ', map { "my \$$_ = \$_[0]->{$_}" } @$keys); |
|
158
|
|
|
|
|
499
|
|
44
|
71
|
50
|
|
|
|
20592
|
my $renderer = eval << " ..." or die $@; ## no critic |
45
|
|
|
|
|
|
|
sub { |
46
|
|
|
|
|
|
|
$expand; |
47
|
|
|
|
|
|
|
$code->(); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
... |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |