line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MiniTmpl; |
2
|
11
|
|
|
11
|
|
628139
|
use 5.012000; |
|
11
|
|
|
|
|
114
|
|
3
|
11
|
|
|
11
|
|
48
|
use warnings; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
251
|
|
4
|
11
|
|
|
11
|
|
45
|
use strict; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
222
|
|
5
|
11
|
|
|
11
|
|
4957
|
use utf8; |
|
11
|
|
|
|
|
120
|
|
|
11
|
|
|
|
|
50
|
|
6
|
11
|
|
|
11
|
|
284
|
use Carp; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
683
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 'v2.0.1'; |
9
|
|
|
|
|
|
|
|
10
|
11
|
|
|
11
|
|
4511
|
use Export::Attrs; |
|
11
|
|
|
|
|
75587
|
|
|
11
|
|
|
|
|
75
|
|
11
|
11
|
|
|
11
|
|
6826
|
use JSON::XS qw( encode_json ); |
|
11
|
|
|
|
|
51650
|
|
|
11
|
|
|
|
|
527
|
|
12
|
11
|
|
|
11
|
|
3990
|
use URI::Escape qw(); |
|
11
|
|
|
|
|
13204
|
|
|
11
|
|
|
|
|
238
|
|
13
|
11
|
|
|
11
|
|
4765
|
use HTML::Entities qw(); |
|
11
|
|
|
|
|
52602
|
|
|
11
|
|
|
|
|
670
|
|
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
11
|
|
83
|
use constant UNSAFE_HTML=> '&"\'<>' . join q{},map{chr}0..8,11,12,14..31,127; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
27
|
|
|
330
|
|
|
|
|
1496
|
|
16
|
11
|
|
|
11
|
|
65
|
use constant RAWPRE => q{$}.__PACKAGE__.'::__ .= '; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
425
|
|
17
|
11
|
|
|
11
|
|
64
|
use constant RAWPOST => q{}; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
475
|
|
18
|
11
|
|
|
11
|
|
52
|
use constant UTF8PRE => q{$}.__PACKAGE__.'::__utf8 = '; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
627
|
|
19
|
11
|
|
|
|
|
1386
|
use constant UTF8POST => 'utf8::encode($'.__PACKAGE__.'::__utf8);' . |
20
|
11
|
|
|
11
|
|
54
|
q{$}.__PACKAGE__.'::__ .= $'.__PACKAGE__.'::__utf8;'; |
|
11
|
|
|
|
|
18
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $__; |
23
|
|
|
|
|
|
|
our $__utf8; |
24
|
|
|
|
|
|
|
our $TMPL_DIR = q{./}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %CACHE; |
27
|
|
|
|
|
|
|
my ($PRE, $POST) = (UTF8PRE, UTF8POST); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub raw :Export { |
31
|
1
|
|
|
1
|
1
|
704
|
my ($is_raw) = @_; |
32
|
1
|
50
|
|
|
|
5
|
($PRE, $POST) = $is_raw ? (RAWPRE, RAWPOST) : (UTF8PRE, UTF8POST); |
33
|
1
|
|
|
|
|
2
|
return; |
34
|
11
|
|
|
11
|
|
69
|
} |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
69
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub render :Export { |
37
|
55
|
|
|
55
|
1
|
26273
|
my ($tmpl, %p) = @_; |
38
|
55
|
100
|
|
|
|
279
|
my $path = $tmpl =~ m{\A[.]?/}xms ? $tmpl : "$TMPL_DIR$tmpl"; |
39
|
55
|
|
|
|
|
178
|
1 while $path =~ s{(\A|/) (?![.][.]?/) [^/]+/[.][.]/}{$1}xms; ## no critic(ProhibitPostfixControls) |
40
|
55
|
|
|
|
|
93
|
my $pkg = caller; |
41
|
55
|
|
66
|
|
|
609
|
$CACHE{$path}{$pkg} ||= tmpl2code($tmpl); |
42
|
52
|
|
|
|
|
72
|
return ${ $CACHE{$path}{$pkg}->(%p) }; |
|
52
|
|
|
|
|
155
|
|
43
|
11
|
|
|
11
|
|
4037
|
} |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
50
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub tmpl2code :Export { |
46
|
41
|
|
|
41
|
1
|
992
|
my ($tmpl) = @_; |
47
|
41
|
100
|
|
|
|
157
|
my $path = $tmpl =~ m{\A[.]?/}xms ? $tmpl : "$TMPL_DIR$tmpl"; |
48
|
41
|
|
|
|
|
108
|
1 while $path =~ s{(\A|/) (?![.][.]?/) [^/]+/[.][.]/}{$1}xms; ## no critic(ProhibitPostfixControls) |
49
|
41
|
|
|
|
|
57
|
my $dir = $path; |
50
|
41
|
|
|
|
|
183
|
$dir =~ s{/[^/]*\z}{/}xms; |
51
|
41
|
|
|
|
|
73
|
my $line = 1; |
52
|
41
|
|
|
|
|
70
|
my $pkg = caller; |
53
|
41
|
100
|
|
|
|
403
|
if ($pkg eq __PACKAGE__) { |
54
|
34
|
|
|
|
|
59
|
$pkg = caller 1; |
55
|
|
|
|
|
|
|
} |
56
|
41
|
|
|
|
|
508
|
my $e |
57
|
|
|
|
|
|
|
= 'package '.$pkg.'; use warnings; use strict;' |
58
|
|
|
|
|
|
|
. 'sub {' |
59
|
|
|
|
|
|
|
. 'local $'.__PACKAGE__.'::__ = q{};' |
60
|
|
|
|
|
|
|
. 'local $'.__PACKAGE__."::TMPL_DIR = \"\Q$dir\E\";" |
61
|
|
|
|
|
|
|
. 'local %_ = @_;' |
62
|
|
|
|
|
|
|
. "\n#line $line \"$path\"\n" |
63
|
|
|
|
|
|
|
; |
64
|
41
|
50
|
|
|
|
1425
|
open my $fh, '<', $path or croak "open: $!"; |
65
|
41
|
|
|
|
|
90
|
my $s = do { local $/ = undef; <$fh> }; |
|
41
|
|
|
|
|
171
|
|
|
41
|
|
|
|
|
959
|
|
66
|
41
|
50
|
|
|
|
360
|
close $fh or croak "close: $!"; |
67
|
41
|
|
|
|
|
84
|
while ( 1 ) { |
68
|
261
|
100
|
|
|
|
1645
|
$e .= |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$s=~/\G/xmsgc |
70
|
|
|
|
|
|
|
? "$1;" |
71
|
|
|
|
|
|
|
: $s=~/\G&~ ( (?>[^~]*) .*? ) ~&/xmsgc |
72
|
|
|
|
|
|
|
? "$1;" |
73
|
|
|
|
|
|
|
: $s=~/\G@~ ( (?>[^~]*) .*? ) ~@/xmsgc |
74
|
|
|
|
|
|
|
? $PRE."HTML::Entities::encode_entities(''.(do { $1; }), ".__PACKAGE__.'::UNSAFE_HTML);'.$POST |
75
|
|
|
|
|
|
|
: $s=~/\G\#~ ( (?>[^~]*) .*? ) ~\#/xmsgc |
76
|
|
|
|
|
|
|
? $PRE."do { $1; };".$POST |
77
|
|
|
|
|
|
|
: $s=~/\G\^~ ( (?>[^~]*) .*? ) ~\^/xmsgc |
78
|
|
|
|
|
|
|
? $PRE."URI::Escape::uri_escape_utf8(''.(do { $1; }));".$POST |
79
|
|
|
|
|
|
|
: $s=~/\G ( (?>[^<&@\#^]*) .*? ) (?= |