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