line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Quick; |
2
|
1
|
|
|
1
|
|
502
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
457
|
use utf8; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
22
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
380
|
use MySQL::Admin qw(init translate); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
127
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
1
|
|
|
1
|
|
4
|
use vars qw($defaultconfig $tmp $DefaultClass @EXPORT_OK @ISA $sStyle $bModPerl); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
269
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
@Template::Quick::EXPORT = qw(initTemplate appendHash Template initArray); |
10
|
|
|
|
|
|
|
%Template::Quick::EXPORT_TAGS = ('all' => [qw(initTemplate appendHash Template initArray )]); |
11
|
|
|
|
|
|
|
$Template::Quick::VERSION = '1.12'; |
12
|
|
|
|
|
|
|
$DefaultClass = 'Template::Quick' unless defined $Template::Quick::DefaultClass; |
13
|
|
|
|
|
|
|
our %tmplate; |
14
|
|
|
|
|
|
|
$sStyle = 'mysql'; |
15
|
|
|
|
|
|
|
$bModPerl = ($ENV{MOD_PERL}) ? 1 : 0; |
16
|
|
|
|
|
|
|
$defaultconfig = '/var/www/cgi-bin/config/settings.pl'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Template::Quick - A simple Template System |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Template::Quick; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$temp = new Template::Quick( {path => "./", template => "template.html"}); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
@data = ( |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
{name => 'Header'}, |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
{name => 'link', text => "Website", href => "http://lindnerei.de"}, |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{name => 'link', text => "Cpan", href => "http://search.cpan.org~lze"}, |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
{name => 'Footer'} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
print $temp->initArray(\@data); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
template.html: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
[Header] |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
A simple text. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
[/Header] |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
[link] |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
[text/] |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
[/link] |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
[Footer] |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
example by [tr=firstname/] Dirk [tr=name/] Lindner |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
[/Footer] |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 new |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
see SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
2
|
|
|
2
|
1
|
213
|
my ($class, @initializer) = @_; |
71
|
2
|
|
|
|
|
3
|
my $self = {}; |
72
|
2
|
|
33
|
|
|
11
|
bless $self, ref $class || $class || $DefaultClass; |
73
|
2
|
50
|
|
|
|
3
|
$self->initTemplate(@initializer) if (@initializer); |
74
|
2
|
|
|
|
|
6
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 initTemplate |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
%template = ( |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
path => "path", |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
style => "style", #defualt is lze |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
template => "index.html", |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
initTemplate(\%template); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub initTemplate { |
94
|
2
|
|
|
2
|
1
|
503
|
my ($self, @p) = getSelf(@_); |
95
|
2
|
|
|
|
|
2
|
my $hash = $p[0]; |
96
|
2
|
|
|
|
|
3
|
$DefaultClass = $self; |
97
|
2
|
50
|
|
|
|
5
|
my $configfile = defined $hash->{config} ? $hash->{config} : $defaultconfig; |
98
|
2
|
50
|
|
|
|
7
|
init($configfile) unless $bModPerl; |
99
|
1
|
|
|
1
|
|
5
|
use Fcntl qw(:flock); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
130
|
|
100
|
1
|
|
|
1
|
|
4
|
use Symbol; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
529
|
|
101
|
2
|
|
|
|
|
7
|
my $fh = gensym; |
102
|
2
|
50
|
|
|
|
25
|
$sStyle = $hash->{style} if defined $hash->{style}; |
103
|
2
|
|
|
|
|
6
|
my $m_sFile = "$hash->{path}/$sStyle/$hash->{template}"; |
104
|
2
|
50
|
|
|
|
44
|
open $fh, "$m_sFile" or warn "$!: $m_sFile"; |
105
|
2
|
|
|
|
|
22
|
seek $fh, 0, 0; |
106
|
2
|
|
|
|
|
78
|
my @lines = <$fh>; |
107
|
2
|
|
|
|
|
11
|
close $fh; |
108
|
2
|
|
|
|
|
3
|
my ($text, $o); |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
4
|
for (@lines) { |
111
|
84
|
|
|
|
|
63
|
$text .= chomp $_; |
112
|
|
|
|
|
|
|
SWITCH: { |
113
|
84
|
100
|
|
|
|
48
|
if ($_ =~ /\[([^\/|\]|']+)\]([^\[\/\1\]]*)/) { |
|
84
|
|
|
|
|
144
|
|
114
|
12
|
|
|
|
|
23
|
$tmplate{$1} = $2; |
115
|
12
|
|
|
|
|
8
|
$o = $1; |
116
|
12
|
|
|
|
|
10
|
last SWITCH; |
117
|
|
|
|
|
|
|
} |
118
|
72
|
100
|
|
|
|
78
|
if (defined $o) { |
119
|
70
|
100
|
|
|
|
262
|
if ($_ =~ /[^\[\/$o\]]/) { |
120
|
58
|
|
|
|
|
55
|
$tmplate{$o} .= $_; |
121
|
58
|
|
|
|
|
59
|
last SWITCH; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
2
|
100
|
|
|
|
13
|
$self->initArray($p[1]) if (defined $p[1]); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 Template() |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
see initTemplate |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub Template { |
136
|
0
|
|
|
0
|
1
|
0
|
my ($self, @p) = getSelf(@_); |
137
|
0
|
|
|
|
|
0
|
return $self->initArray(@p); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 appendHash() |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
appendHash(\%hash); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub appendHash { |
147
|
6
|
|
|
6
|
1
|
7
|
my ($self, @p) = getSelf(@_); |
148
|
6
|
|
|
|
|
5
|
my $hash = $p[0]; |
149
|
6
|
|
|
|
|
8
|
my $text = $tmplate{$hash->{name}}; |
150
|
6
|
|
|
|
|
5
|
foreach my $key (keys %{$hash}) { |
|
6
|
|
|
|
|
12
|
|
151
|
12
|
50
|
33
|
|
|
39
|
if (defined $text && defined $hash->{$key}) { |
152
|
12
|
50
|
33
|
|
|
31
|
if (defined $key && defined $hash->{$key}) { |
153
|
12
|
|
|
|
|
97
|
$text =~ s/\[($key)\/\]/$hash->{$key}/g; |
154
|
12
|
|
|
|
|
21
|
$text =~ s/\[tr=(\w*)\/\]/translate($1)/eg; |
|
0
|
|
|
|
|
0
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
6
|
|
|
|
|
19
|
return $text; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 initArray() |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub initArray { |
166
|
2
|
|
|
2
|
1
|
9
|
my ($self, @p) = getSelf(@_); |
167
|
2
|
|
|
|
|
2
|
my $tree = $p[0]; |
168
|
2
|
100
|
|
|
|
4
|
$tmp = undef if (defined $tmp); |
169
|
2
|
|
|
|
|
6
|
for (my $i = 0 ; $i < @$tree ; $i++) { |
170
|
6
|
|
|
|
|
2
|
$tmp .= $self->appendHash(\%{@$tree[$i]}); |
|
6
|
|
|
|
|
13
|
|
171
|
|
|
|
|
|
|
} |
172
|
2
|
|
|
|
|
10
|
return $tmp; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 getSelf() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub getSelf { |
180
|
10
|
50
|
33
|
10
|
1
|
39
|
return @_ if defined($_[0]) && (!ref($_[0])) && ($_[0] eq 'Template::Quick'); |
|
|
|
33
|
|
|
|
|
181
|
10
|
100
|
33
|
|
|
51
|
return (defined($_[0]) |
182
|
|
|
|
|
|
|
&& (ref($_[0]) eq 'Template::Quick' || UNIVERSAL::isa($_[0], 'Template::Quick'))) |
183
|
|
|
|
|
|
|
? @_ |
184
|
|
|
|
|
|
|
: ($Template::Quick::DefaultClass->new, @_); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 AUTHOR |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Dirk Lindner |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 LICENSE |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Copyright (C) 2008 by Hr. Dirk Lindner |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
196
|
|
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public License |
197
|
|
|
|
|
|
|
as published by the Free Software Foundation; |
198
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
199
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
200
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
201
|
|
|
|
|
|
|
GNU Lesser General Public License for more details. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |