line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Quick; |
2
|
1
|
|
|
1
|
|
523
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
3
|
1
|
|
|
1
|
|
529
|
use utf8; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
22
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
347
|
use MySQL::Admin qw(init translate); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
139
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
1
|
|
|
1
|
|
5
|
use vars qw($defaultconfig $tmp $DefaultClass @EXPORT_OK @ISA $sStyle $bModPerl); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
221
|
|
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.1'; |
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
|
153
|
my ($class, @initializer) = @_; |
71
|
2
|
|
|
|
|
3
|
my $self = {}; |
72
|
2
|
|
33
|
|
|
11
|
bless $self, ref $class || $class || $DefaultClass; |
73
|
2
|
50
|
|
|
|
4
|
$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
|
446
|
my ($self, @p) = getSelf(@_); |
95
|
2
|
|
|
|
|
3
|
my $hash = $p[0]; |
96
|
2
|
|
|
|
|
4
|
$DefaultClass = $self; |
97
|
2
|
50
|
|
|
|
5
|
my $configfile = defined $hash->{config} ? $hash->{config} : $defaultconfig; |
98
|
2
|
50
|
|
|
|
8
|
init($configfile) unless $bModPerl; |
99
|
1
|
|
|
1
|
|
5
|
use Fcntl qw(:flock); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
118
|
|
100
|
1
|
|
|
1
|
|
4
|
use Symbol; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
549
|
|
101
|
2
|
|
|
|
|
7
|
my $fh = gensym; |
102
|
2
|
50
|
|
|
|
25
|
$sStyle = $hash->{style} if defined $hash->{style}; |
103
|
2
|
|
|
|
|
5
|
my $m_sFile = "$hash->{path}/$sStyle/$hash->{template}"; |
104
|
2
|
50
|
|
|
|
47
|
open $fh, "$m_sFile" or warn "$!: $m_sFile"; |
105
|
2
|
|
|
|
|
11
|
seek $fh, 0, 0; |
106
|
2
|
|
|
|
|
63
|
my @lines = <$fh>; |
107
|
2
|
|
|
|
|
12
|
close $fh; |
108
|
2
|
|
|
|
|
3
|
my ($text, $o); |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
3
|
for (@lines) { |
111
|
84
|
|
|
|
|
72
|
$text .= chomp $_; |
112
|
|
|
|
|
|
|
SWITCH: { |
113
|
84
|
100
|
|
|
|
42
|
if ($_ =~ /\[([^\/|\]|']+)\]([^\[\/\1\]]*)/) { |
|
84
|
|
|
|
|
152
|
|
114
|
12
|
|
|
|
|
26
|
$tmplate{$1} = $2; |
115
|
12
|
|
|
|
|
13
|
$o = $1; |
116
|
12
|
|
|
|
|
14
|
last SWITCH; |
117
|
|
|
|
|
|
|
} |
118
|
72
|
100
|
|
|
|
80
|
if (defined $o) { |
119
|
70
|
100
|
|
|
|
317
|
if ($_ =~ /[^\[\/$o\]]/) { |
120
|
58
|
|
|
|
|
62
|
$tmplate{$o} .= $_; |
121
|
58
|
|
|
|
|
55
|
last SWITCH; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
2
|
100
|
|
|
|
14
|
$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
|
8
|
my ($self, @p) = getSelf(@_); |
148
|
6
|
|
|
|
|
4
|
my $hash = $p[0]; |
149
|
6
|
|
|
|
|
9
|
my $text = $tmplate{$hash->{name}}; |
150
|
6
|
|
|
|
|
4
|
foreach my $key (keys %{$hash}) { |
|
6
|
|
|
|
|
12
|
|
151
|
12
|
50
|
33
|
|
|
40
|
if (defined $text && defined $hash->{$key}) { |
152
|
12
|
50
|
33
|
|
|
29
|
if (defined $key && defined $hash->{$key}) { |
153
|
12
|
|
|
|
|
90
|
$text =~ s/\[($key)\/\]/$hash->{$key}/g; |
154
|
12
|
|
|
|
|
22
|
$text =~ s/\[tr=(\w*)\/\]/translate($1)/eg; |
|
0
|
|
|
|
|
0
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
6
|
|
|
|
|
18
|
return $text; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 initArray() |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub initArray { |
166
|
2
|
|
|
2
|
1
|
8
|
my ($self, @p) = getSelf(@_); |
167
|
2
|
|
|
|
|
3
|
my $tree = $p[0]; |
168
|
2
|
100
|
|
|
|
5
|
$tmp = undef if (defined $tmp); |
169
|
2
|
|
|
|
|
6
|
for (my $i = 0 ; $i < @$tree ; $i++) { |
170
|
6
|
|
|
|
|
5
|
$tmp .= $self->appendHash(\%{@$tree[$i]}); |
|
6
|
|
|
|
|
12
|
|
171
|
|
|
|
|
|
|
} |
172
|
2
|
|
|
|
|
10
|
return $tmp; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 getSelf() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub getSelf { |
180
|
10
|
50
|
33
|
10
|
1
|
37
|
return @_ if defined($_[0]) && (!ref($_[0])) && ($_[0] eq 'Template::Quick'); |
|
|
|
33
|
|
|
|
|
181
|
10
|
100
|
33
|
|
|
45
|
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; |