line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include.pm
|
2
|
|
|
|
|
|
|
#Last Change: 2009-01-19
|
3
|
|
|
|
|
|
|
#Copyright (c) 2009 Marc-Seabstian "Maluku" Lucksch
|
4
|
|
|
|
|
|
|
#Version 0.8
|
5
|
|
|
|
|
|
|
####################
|
6
|
|
|
|
|
|
|
#This file is part of the Dotiac::DTL project.
|
7
|
|
|
|
|
|
|
#http://search.cpan.org/perldoc?Dotiac::DTL
|
8
|
|
|
|
|
|
|
#
|
9
|
|
|
|
|
|
|
#include.pm is published under the terms of the MIT license, which basically
|
10
|
|
|
|
|
|
|
#means "Do with it whatever you want". For more information, see the
|
11
|
|
|
|
|
|
|
#license.txt file that should be enclosed with libsofu distributions. A copy of
|
12
|
|
|
|
|
|
|
#the license is (at the time of writing) also available at
|
13
|
|
|
|
|
|
|
#http://www.opensource.org/licenses/mit-license.php .
|
14
|
|
|
|
|
|
|
###############################################################################
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Dotiac::DTL::Tag::include;
|
18
|
11
|
|
|
11
|
|
67
|
use base qw/Dotiac::DTL::Tag/;
|
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
958
|
|
19
|
11
|
|
|
11
|
|
65
|
use strict;
|
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
337
|
|
20
|
11
|
|
|
11
|
|
59
|
use warnings;
|
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
30592
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 0.8;
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new {
|
25
|
4
|
|
|
4
|
1
|
9
|
my $class=shift;
|
26
|
4
|
|
|
|
|
13
|
my $self={p=>shift()};
|
27
|
4
|
|
|
|
|
8
|
my $name=shift;
|
28
|
4
|
50
|
|
|
|
13
|
die "This include needs a filename or variable" unless $name;
|
29
|
4
|
|
|
|
|
15
|
$name=(Dotiac::DTL::get_variables($name))[0];
|
30
|
4
|
|
|
|
|
8
|
my $f=substr $name,0,1;
|
31
|
4
|
|
|
|
|
10
|
my $e=substr $name,-1,1;
|
32
|
4
|
100
|
66
|
|
|
40
|
if ($f eq "`" and $e eq "`") {
|
33
|
2
|
|
|
|
|
14
|
$self->{load}=Dotiac::DTL::devar($name,{},0);
|
34
|
2
|
|
|
|
|
17
|
my $tem = Dotiac::DTL->safenew($self->{load});
|
35
|
2
|
|
|
|
|
11
|
$self->{content}=$tem->{first};
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
else {
|
38
|
2
|
|
|
|
|
6
|
$self->{var}=$name;
|
39
|
|
|
|
|
|
|
}
|
40
|
4
|
|
|
|
|
10
|
bless $self,$class;
|
41
|
4
|
|
|
|
|
15
|
return $self;
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
sub print {
|
44
|
7
|
|
|
7
|
1
|
14
|
my $self=shift;
|
45
|
7
|
|
|
|
|
36
|
print $self->{p};
|
46
|
7
|
100
|
|
|
|
23
|
if ($self->{content}) {
|
47
|
3
|
|
|
|
|
18
|
$self->{content}->print(@_);
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
else {
|
50
|
4
|
|
|
|
|
14
|
my $tem = Dotiac::DTL::devar_raw($self->{var},@_);
|
51
|
4
|
|
|
|
|
15
|
my $s=$tem->content();
|
52
|
4
|
100
|
33
|
|
|
12
|
if ($tem->scalar()) {
|
|
|
50
|
|
|
|
|
|
53
|
2
|
|
|
|
|
16
|
$tem = Dotiac::DTL->safenew($tem->repr);
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
elsif ($tem->object() and $tem->content->isa("Dotiac::DTL::Template")) {
|
56
|
2
|
|
|
|
|
7
|
$tem=$tem->content;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
else {
|
59
|
0
|
|
|
|
|
0
|
die "Can't include \"$tem\"";
|
60
|
|
|
|
|
|
|
}
|
61
|
4
|
50
|
|
|
|
23
|
die "Cyclic include detected " if $Dotiac::DTL::included{$s}++;
|
62
|
4
|
|
|
|
|
16
|
$tem->{first}->print(@_);
|
63
|
4
|
|
|
|
|
15
|
$Dotiac::DTL::included{$s}=0;
|
64
|
|
|
|
|
|
|
}
|
65
|
7
|
50
|
|
|
|
39
|
$self->{n}->print(@_) if $self->{n};
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
sub string {
|
68
|
7
|
|
|
7
|
1
|
11
|
my $self=shift;
|
69
|
7
|
100
|
|
|
|
27
|
if ($self->{content}) {
|
70
|
3
|
50
|
|
|
|
20
|
return $self->{p}.$self->{content}->string(@_).($self->{n}?$self->{n}->string(@_):"");
|
71
|
|
|
|
|
|
|
}
|
72
|
4
|
|
|
|
|
16
|
my $tem = Dotiac::DTL::devar_raw($self->{var},@_);
|
73
|
4
|
|
|
|
|
18
|
my $s=$tem->content();
|
74
|
4
|
100
|
33
|
|
|
14
|
if ($tem->scalar()) {
|
|
|
50
|
|
|
|
|
|
75
|
2
|
|
|
|
|
12
|
$tem = Dotiac::DTL->safenew($tem->repr);
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
elsif ($tem->object() and $tem->content->isa("Dotiac::DTL::Template")) {
|
78
|
2
|
|
|
|
|
7
|
$tem=$tem->content;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
else {
|
81
|
0
|
|
|
|
|
0
|
die "Can't include \"$tem\"";
|
82
|
|
|
|
|
|
|
}
|
83
|
4
|
50
|
|
|
|
28
|
die "Cyclic include detected " if $Dotiac::DTL::included{$s}++;
|
84
|
4
|
50
|
|
|
|
19
|
my $r=$self->{p}.$tem->{first}->string(@_).($self->{n}?$self->{n}->string(@_):"");
|
85
|
4
|
|
|
|
|
16
|
$Dotiac::DTL::included{$s}=0;
|
86
|
4
|
|
|
|
|
20
|
return $r
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
sub perl {
|
90
|
7
|
|
|
7
|
1
|
16
|
my $self=shift;
|
91
|
7
|
|
|
|
|
11
|
my $fh=shift;
|
92
|
7
|
|
|
|
|
14
|
my $id=shift;
|
93
|
7
|
|
|
|
|
43
|
$self->SUPER::perl($fh,$id,@_);
|
94
|
7
|
100
|
|
|
|
22
|
if ($self->{load}) {
|
95
|
3
|
|
|
|
|
22
|
print $fh "my \$template$id=Dotiac::DTL->safenew(\"".quotemeta($self->{load})."\");\n";
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
else {
|
98
|
4
|
|
|
|
|
9
|
print $fh "my ";
|
99
|
4
|
|
|
|
|
22
|
print $fh (Data::Dumper->Dump([$self->{var}],["\$name$id"]));
|
100
|
|
|
|
|
|
|
}
|
101
|
7
|
|
|
|
|
186
|
return $self->{n}->perl($fh,$id+1,@_);
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
sub perlprint {
|
104
|
7
|
|
|
7
|
1
|
12
|
my $self=shift;
|
105
|
7
|
|
|
|
|
9
|
my $fh=shift;
|
106
|
7
|
|
|
|
|
210
|
my $id=shift;
|
107
|
7
|
|
|
|
|
10
|
my $level=shift;
|
108
|
7
|
|
|
|
|
34
|
$self->SUPER::perlprint($fh,$id,$level,@_);
|
109
|
7
|
|
|
|
|
16
|
my $in="\t" x $level;
|
110
|
7
|
100
|
|
|
|
22
|
if ($self->{content}) {
|
111
|
3
|
|
|
|
|
10
|
print $fh $in,"die \"Cyclic include detected \" if \$Dotiac::DTL::included{\$template$id}++;\n";
|
112
|
3
|
|
|
|
|
12
|
print $fh "$in\$template$id"."->{first}->print(\$vars,\$escape,\@_);\n";
|
113
|
3
|
|
|
|
|
9
|
print $fh $in,"\$Dotiac::DTL::included{\$template$id}=0;\n";
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
else {
|
116
|
4
|
|
|
|
|
14
|
print $fh $in,"my \$template$id = Dotiac::DTL::devar_raw(\$name$id,\$vars,\$escape,\@_);\n";
|
117
|
4
|
|
|
|
|
19
|
print $fh $in,"my \$s$id=\$template$id->content();\n";
|
118
|
4
|
|
|
|
|
9
|
print $fh $in,"if (\$template$id->scalar()) {\n";
|
119
|
4
|
|
|
|
|
10
|
print $fh $in,"\t\$template$id = Dotiac::DTL->safenew(\$template$id->repr());\n";
|
120
|
4
|
|
|
|
|
12
|
print $fh $in,"} elsif (\$template$id->object() and \$template$id->content->isa(\"Dotiac::DTL::Template\")) {\n";
|
121
|
4
|
|
|
|
|
94
|
print $fh $in,"\t\$template$id=\$template$id->content;\n";
|
122
|
4
|
|
|
|
|
8
|
print $fh $in,"} else {\n";
|
123
|
4
|
|
|
|
|
9
|
print $fh $in,"\tdie \"Can't include \\\"\$template$id\\\"\";\n";
|
124
|
4
|
|
|
|
|
9
|
print $fh $in,"}\n";
|
125
|
4
|
|
|
|
|
6
|
print $fh $in,"die \"Cyclic include detected \" if \$Dotiac::DTL::included{\$s$id}++;\n";
|
126
|
4
|
|
|
|
|
10
|
print $fh $in,"\$template$id"."->{first}->print(\$vars,\$escape,\@_);\n";
|
127
|
4
|
|
|
|
|
6
|
print $fh $in,"\$Dotiac::DTL::included{\$s$id}=0;\n";
|
128
|
|
|
|
|
|
|
}
|
129
|
7
|
|
|
|
|
38
|
return $self->{n}->perlprint($fh,$id+1,$level,@_);
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
sub perlstring {
|
132
|
7
|
|
|
7
|
1
|
13
|
my $self=shift;
|
133
|
7
|
|
|
|
|
8
|
my $fh=shift;
|
134
|
7
|
|
|
|
|
11
|
my $id=shift;
|
135
|
7
|
|
|
|
|
9
|
my $level=shift;
|
136
|
7
|
|
|
|
|
43
|
$self->SUPER::perlstring($fh,$id,$level,@_);
|
137
|
7
|
|
|
|
|
15
|
my $in="\t" x $level;
|
138
|
7
|
100
|
|
|
|
22
|
if ($self->{content}) {
|
139
|
3
|
|
|
|
|
10
|
print $fh $in,"die \"Cyclic include detected \" if \$Dotiac::DTL::included{\$template$id}++;\n";
|
140
|
3
|
|
|
|
|
13
|
print $fh "$in\$r.=\$template$id"."->{first}->string(\$vars,\$escape,\@_);\n";
|
141
|
3
|
|
|
|
|
16
|
print $fh $in,"\$Dotiac::DTL::included{\$template$id}=0;\n";
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
else {
|
144
|
4
|
|
|
|
|
15
|
print $fh $in,"my \$template$id = Dotiac::DTL::devar_raw(\$name$id,\$vars,\$escape,\@_);\n";
|
145
|
4
|
|
|
|
|
9
|
print $fh $in,"my \$s$id=\$template$id->content();\n";
|
146
|
4
|
|
|
|
|
10
|
print $fh $in,"if (\$template$id->scalar()) {\n";
|
147
|
4
|
|
|
|
|
10
|
print $fh $in,"\t\$template$id = Dotiac::DTL->safenew(\$template$id->repr());\n";
|
148
|
4
|
|
|
|
|
10
|
print $fh $in,"} elsif (\$template$id->object() and \$template$id->content->isa(\"Dotiac::DTL::Template\")) {\n";
|
149
|
4
|
|
|
|
|
10
|
print $fh $in,"\t\$template$id=\$template$id->content;\n";
|
150
|
4
|
|
|
|
|
6
|
print $fh $in,"} else {\n";
|
151
|
4
|
|
|
|
|
15
|
print $fh $in,"\tdie \"Can't include \\\"\$template$id\\\"\";\n";
|
152
|
4
|
|
|
|
|
6
|
print $fh $in,"}\n";
|
153
|
4
|
|
|
|
|
11
|
print $fh $in,"die \"Cyclic include detected \" if \$Dotiac::DTL::included{\$s$id}++;\n";
|
154
|
4
|
|
|
|
|
9
|
print $fh $in,"\$r.=\$template$id"."->{first}->string(\$vars,\$escape,\@_);\n";
|
155
|
4
|
|
|
|
|
16
|
print $fh $in,"\$Dotiac::DTL::included{\$s$id}=0;\n";
|
156
|
|
|
|
|
|
|
}
|
157
|
7
|
|
|
|
|
33
|
return $self->{n}->perlstring($fh,$id+1,$level,@_);
|
158
|
|
|
|
|
|
|
}
|
159
|
|
|
|
|
|
|
sub perlcount {
|
160
|
0
|
|
|
0
|
1
|
0
|
my $self=shift;
|
161
|
0
|
|
|
|
|
0
|
my $id=shift;
|
162
|
0
|
|
|
|
|
0
|
return $self->{n}->perlcount($id+1);
|
163
|
|
|
|
|
|
|
}
|
164
|
|
|
|
|
|
|
sub perleval {
|
165
|
7
|
|
|
7
|
1
|
10
|
my $self=shift;
|
166
|
7
|
|
|
|
|
9
|
my $fh=shift;
|
167
|
7
|
|
|
|
|
22
|
my $id=shift;
|
168
|
7
|
|
|
|
|
9
|
my $level=shift;
|
169
|
7
|
|
|
|
|
16
|
my $in="\t" x $level;
|
170
|
7
|
100
|
|
|
|
21
|
if ($self->{content}) {
|
171
|
3
|
|
|
|
|
18
|
print $fh $in,"die \"Cyclic include detected \" if \$Dotiac::DTL::included{\$template$id}++;\n";
|
172
|
3
|
|
|
|
|
11
|
print $fh "$in\$template$id"."->{first}->eval(\$vars,\$escape,\@_);\n";
|
173
|
3
|
|
|
|
|
9
|
print $fh $in,"\$Dotiac::DTL::included{\$template$id}=0;\n";
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
else {
|
176
|
4
|
|
|
|
|
18
|
print $fh $in,"my \$template$id = Dotiac::DTL::devar_raw(\$name$id,\$vars,\$escape,\@_);\n";
|
177
|
4
|
|
|
|
|
9
|
print $fh $in,"my \$s$id=\$template$id->content();\n";
|
178
|
4
|
|
|
|
|
9
|
print $fh $in,"if (\$template$id->scalar()) {\n";
|
179
|
4
|
|
|
|
|
11
|
print $fh $in,"\t\$template$id = Dotiac::DTL->safenew(\$template$id->repr());\n";
|
180
|
4
|
|
|
|
|
10
|
print $fh $in,"} elsif (\$template$id->object() and \$template$id->content->isa(\"Dotiac::DTL\")) {\n";
|
181
|
4
|
|
|
|
|
9
|
print $fh $in,"\t\$template$id=\$template$id->content;\n";
|
182
|
4
|
|
|
|
|
7
|
print $fh $in,"} else {\n";
|
183
|
4
|
|
|
|
|
8
|
print $fh $in,"\tdie \"Can't include \\\"\$template$id\\\"\";\n";
|
184
|
4
|
|
|
|
|
6
|
print $fh $in,"}\n";
|
185
|
4
|
|
|
|
|
8
|
print $fh $in,"die \"Cyclic include detected \" if \$Dotiac::DTL::included{\$s$id}++;\n";
|
186
|
4
|
|
|
|
|
9
|
print $fh $in,"\$template$id"."->{first}->eval(\$vars,\$escape,\@_);\n";
|
187
|
4
|
|
|
|
|
10
|
print $fh $in,"\$Dotiac::DTL::included{\$s$id}=0;\n";
|
188
|
|
|
|
|
|
|
}
|
189
|
7
|
|
|
|
|
41
|
return $self->{n}->perleval($fh,$id+1,$level,@_);
|
190
|
|
|
|
|
|
|
}
|
191
|
|
|
|
|
|
|
sub perlinit {
|
192
|
7
|
|
|
7
|
1
|
13
|
my $self=shift;
|
193
|
7
|
|
|
|
|
12
|
my $fh=shift;
|
194
|
7
|
|
|
|
|
9
|
my $id=shift;
|
195
|
7
|
|
|
|
|
29
|
return $self->{n}->perlinit($fh,$id+1,@_);
|
196
|
|
|
|
|
|
|
}
|
197
|
|
|
|
|
|
|
sub next {
|
198
|
4
|
|
|
4
|
1
|
8
|
my $self=shift;
|
199
|
4
|
|
|
|
|
26
|
$self->{n}=shift;
|
200
|
|
|
|
|
|
|
}
|
201
|
|
|
|
|
|
|
sub eval {
|
202
|
0
|
|
|
0
|
1
|
|
my $self=shift;
|
203
|
0
|
0
|
|
|
|
|
if ($self->{content}) {
|
204
|
0
|
|
|
|
|
|
$self->{content}->eval(@_) ;
|
205
|
|
|
|
|
|
|
}
|
206
|
|
|
|
|
|
|
else {
|
207
|
0
|
|
|
|
|
|
my $tem = Dotiac::DTL::devar_raw($self->{var},@_);
|
208
|
0
|
|
|
|
|
|
my $s=$tem->content();
|
209
|
0
|
0
|
0
|
|
|
|
if ($tem->scalar()) {
|
|
|
0
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
$tem = Dotiac::DTL->safenew($tem->repr);
|
211
|
|
|
|
|
|
|
}
|
212
|
|
|
|
|
|
|
elsif ($tem->object() and $tem->content->isa("Dotiac::DTL")) {
|
213
|
0
|
|
|
|
|
|
$tem=$tem->content;
|
214
|
|
|
|
|
|
|
}
|
215
|
|
|
|
|
|
|
else {
|
216
|
0
|
|
|
|
|
|
die "Can't include \"$tem\"";
|
217
|
|
|
|
|
|
|
}
|
218
|
0
|
0
|
|
|
|
|
die "Cyclic include detected " if $Dotiac::DTL::included{$s}++;
|
219
|
0
|
|
|
|
|
|
$tem->{first}->eval(@_);
|
220
|
0
|
|
|
|
|
|
$Dotiac::DTL::included{$s}=0;
|
221
|
|
|
|
|
|
|
}
|
222
|
0
|
|
|
|
|
|
$self->{n}->eval(@_);
|
223
|
|
|
|
|
|
|
}
|
224
|
|
|
|
|
|
|
1;
|
225
|
|
|
|
|
|
|
__END__
|