line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Here::Template; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Here::Template - heredoc templates |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Here::Template; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
print <<'TMPL'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Hello, my pid is = $$ ?> |
14
|
|
|
|
|
|
|
Let's count to 10: for (1..10) { ?>$_ } ?> |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
TMPL |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Simple Filter::Util::Call based implementation of heredoc templates. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
To enable templates in some heredoc use quoted heredoc mark that contains |
23
|
|
|
|
|
|
|
B. Output is added to the buffer C<$here>. You can append data |
24
|
|
|
|
|
|
|
there as well: |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
print <<'TMPL'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Hello, my pid is = $$ ?> |
29
|
|
|
|
|
|
|
Let's count to 10: for (1..10) { $here.= "$_" } ?> |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
TMPL |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 EXPORT |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This module doesn't export anything by default. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Special argument B can be used to disable strict and |
38
|
|
|
|
|
|
|
warnings inside templates. E.g.: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use strict; |
41
|
|
|
|
|
|
|
use warnings; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use Here::Template 'relaxed'; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
print <<'TMPL'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Let's count to 10: |
48
|
|
|
|
|
|
|
for $k (1..10) { |
49
|
|
|
|
|
|
|
$here .= "$k "; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
?> |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
TMPL |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
1
|
|
23782
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
60
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
61
|
1
|
|
|
1
|
|
5
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
45
|
|
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
|
975
|
use Filter::Util::Call; |
|
1
|
|
|
|
|
9738
|
|
|
1
|
|
|
|
|
868
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub import { |
66
|
1
|
50
|
|
1
|
|
16
|
my $ctl = $_[1] eq 'relaxed' |
67
|
|
|
|
|
|
|
? 'no strict; no warnings;' : ''; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
filter_add sub { |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
2
|
|
3449
|
my $st = filter_read(); |
72
|
|
|
|
|
|
|
|
73
|
2
|
50
|
|
|
|
7
|
if ( m/ << \s* (['"]) ( [^\1]* TMPL [^\1]* ) \1 \s* /gcx ) { |
74
|
0
|
|
|
|
|
0
|
my $q = $1; |
75
|
0
|
|
|
|
|
0
|
my $eof = quotemeta $2; |
76
|
0
|
|
|
|
|
0
|
my $start = quotemeta ''; |
77
|
0
|
|
|
|
|
0
|
my $out = '$here'; |
78
|
0
|
|
|
|
|
0
|
my $end = quotemeta '?>'; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
my $buf = substr($_, 0, pos($_) - length($&)); |
81
|
0
|
|
|
|
|
0
|
my $buf_end = substr($_, pos($_)); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
chomp($buf_end); |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
return $st |
86
|
|
|
|
|
|
|
if /^\s*#/; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
$_ = ''; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# do { my $var = ' |
91
|
0
|
0
|
|
|
|
0
|
$buf .= "do{ $ctl \n".($out eq '$_' ? 'local' : 'my')." $out =$q"; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
while (1) { |
94
|
0
|
|
|
|
|
0
|
$st = filter_read(); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
0
|
if (/ $start (=)? /gcx) { |
97
|
0
|
|
|
|
|
0
|
my $echo = $1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# foo bar\' baz |
100
|
0
|
|
|
|
|
0
|
my $tmp = substr($_, 0, pos($_) - length($&)); |
101
|
0
|
|
|
|
|
0
|
$_ = substr($_, pos($_)); |
102
|
0
|
|
|
|
|
0
|
$tmp =~ s/$q/\\$q/g; |
103
|
0
|
|
|
|
|
0
|
$buf .= $tmp; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
$st = filter_read() |
106
|
|
|
|
|
|
|
while !/ $end /gcx; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# '; ... ; $out .=' |
109
|
0
|
|
|
|
|
0
|
$tmp = substr($_, 0, pos($_) - length($&)); |
110
|
0
|
|
|
|
|
0
|
$_ = substr($_, pos($_)); |
111
|
0
|
0
|
|
|
|
0
|
$buf .= "$q; ". |
112
|
|
|
|
|
|
|
($echo ? "$out.=$tmp" : "$tmp"). |
113
|
|
|
|
|
|
|
"; $out .=$q"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
0
|
if (/ $eof /gcx) { |
117
|
0
|
|
|
|
|
0
|
my $tmp = substr($_, 0, pos($_) - length($&)); |
118
|
0
|
|
|
|
|
0
|
$_ = substr($_, pos($_)); |
119
|
0
|
|
|
|
|
0
|
$tmp =~ s/$q/\\$q/g; |
120
|
0
|
|
|
|
|
0
|
$buf .= $tmp; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# '; $var } |
123
|
0
|
|
|
|
|
0
|
$buf .= "$q; $out }"; |
124
|
0
|
|
|
|
|
0
|
$_ = $buf.$buf_end.$_; |
125
|
0
|
|
|
|
|
0
|
last; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
last |
129
|
0
|
0
|
|
|
|
0
|
unless $st; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
2
|
|
|
|
|
1550
|
return $st; |
134
|
1
|
|
|
|
|
11
|
}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Alexandr Gomoliako |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 LICENSE |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright 2011-2012 Alexandr Gomoliako. All rights reserved. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or modified |
147
|
|
|
|
|
|
|
under the same terms as perl itself. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |