| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Template::Direct::Page; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
16
|
use base Template::Direct::Base; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1851
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
16
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
71
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
64
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Template::Direct::Page - Handle an entire page as an object |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Provide over all support for a page object |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 METHODS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1969
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $findTag = qr/(?
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 I<$class>->new( $template, %p ) |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Create a new Page object with specified template content. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
sub new { |
|
31
|
2
|
|
|
2
|
1
|
8
|
my ($class, $template, %p) = @_; |
|
32
|
2
|
|
|
|
|
21
|
my $self = $class->SUPER::new( %p ); |
|
33
|
2
|
|
|
|
|
22
|
$self->{'content'} = $template; |
|
34
|
2
|
|
|
|
|
8
|
return $self; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 I<$page>->tagName( ) |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns 'page' |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
0
|
|
|
0
|
1
|
0
|
sub tagName { 'page' } |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 I<$page>->singleTag( ) |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Returns true |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
|
49
|
1
|
|
|
1
|
1
|
4
|
sub singleTag { 1 } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 I<$page>->subTags( ) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns all expected page tags: [ if, list, page ] |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
sub subTags { |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
2
|
|
|
2
|
1
|
15
|
'if' => 'Template::Direct::Conditional', |
|
59
|
|
|
|
|
|
|
'list' => 'Template::Direct::List', |
|
60
|
|
|
|
|
|
|
'page' => 'Template::Direct::SubPage', |
|
61
|
|
|
|
|
|
|
'maths' => 'Template::Direct::Maths', |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 I<$page>->parent( ) |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Page tags have no parent tags, returns undef. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
0
|
|
|
0
|
1
|
0
|
sub parent { undef } |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 I<$page>->depth( ) |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Page tags have no tag depth being root, returns 0. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
40
|
|
|
40
|
1
|
124
|
sub depth { 0 } |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 I<$page>->classDepth( ) |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Page tags have no class depth being root, returns 0. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
|
84
|
0
|
|
|
0
|
1
|
0
|
sub classDepth { 0 } |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 I<$page>->classParent( ) |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Page tags have no class parent tags, returns undef. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
0
|
|
|
0
|
1
|
0
|
sub classParent { undef } |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 $object->compile( ) |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Returns the template correctly processed with the data |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
sub compile { |
|
99
|
2
|
|
|
2
|
1
|
4
|
my ($self, $data) = @_; |
|
100
|
2
|
100
|
|
|
|
8
|
if(ref($data) ne 'Template::Direct::Data') { |
|
101
|
1
|
|
|
|
|
9
|
$data = Template::Direct::Data->new($data); |
|
102
|
|
|
|
|
|
|
# $data->dataDump(); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
# Arrange any pre-compile steps |
|
105
|
2
|
50
|
|
|
|
13
|
if(not $self->isPreCompiled()) { |
|
106
|
2
|
|
|
|
|
13
|
$self->markAllTags( \$self->{'content'} ); |
|
107
|
|
|
|
|
|
|
#warn "Content found: $self->{'content'}\n"; |
|
108
|
2
|
|
|
|
|
7
|
$self->{'preCompiled'} = 1; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# running parents compile rutine will process any structures |
|
112
|
|
|
|
|
|
|
# found by the above pre-compile step. |
|
113
|
2
|
|
|
|
|
8
|
my $body = $self->{'content'}; |
|
114
|
2
|
|
|
|
|
18
|
$self->SUPER::compile( $data, \$body ); |
|
115
|
2
|
|
|
|
|
22
|
$self->cleanContent( \$body ); |
|
116
|
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
8
|
$self->{'body'} = $body; |
|
118
|
2
|
|
|
|
|
17
|
return $self->{'body'}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 $object->isPreCompiled( ) |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns 1 if the template has been compiled into |
|
125
|
|
|
|
|
|
|
It's tag marked form, this pairs up with the children |
|
126
|
|
|
|
|
|
|
structure to compile the template with a data set. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
2
|
50
|
|
2
|
1
|
16
|
sub isPreCompiled { $_[0]->{'preCompiled'} || 0 } |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 $object->markAllTags( \$content ) |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Take any kind of structure and mark it out with unique id's, returns a structure of objects |
|
135
|
|
|
|
|
|
|
that relate to the first layer of items. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
|
138
|
|
|
|
|
|
|
sub markAllTags { |
|
139
|
2
|
|
|
2
|
1
|
4
|
my ($self, $content) = @_; |
|
140
|
|
|
|
|
|
|
|
|
141
|
2
|
|
|
|
|
3
|
my $tagIndex = 0; |
|
142
|
2
|
|
|
|
|
4
|
my @stack; |
|
143
|
|
|
|
|
|
|
my %class; |
|
144
|
2
|
|
|
|
|
15
|
my $tags = $self->subTags(); |
|
145
|
|
|
|
|
|
|
|
|
146
|
2
|
|
|
|
|
29
|
while ( $$content =~ s/$findTag/{{TAG$tagIndex}}/ ) { |
|
147
|
244
|
|
|
|
|
521
|
my $endTag = $1 eq '/'; |
|
148
|
244
|
|
|
|
|
382
|
my $simpleTag = $4 eq '/'; |
|
149
|
244
|
|
|
|
|
355
|
my $name = $2; |
|
150
|
244
|
|
|
|
|
343
|
my $data = $3; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Initalise this class parent stack |
|
153
|
244
|
100
|
|
|
|
618
|
$class{$name} = [] if not defined $class{$name}; |
|
154
|
244
|
|
|
|
|
358
|
my $cstack = $class{$name}; |
|
155
|
|
|
|
|
|
|
|
|
156
|
244
|
100
|
|
|
|
443
|
if(not $endTag) { |
|
157
|
138
|
100
|
|
|
|
269
|
if($tags->{$name}) { |
|
158
|
|
|
|
|
|
|
# Initalise this class parent stack |
|
159
|
58
|
50
|
|
|
|
114
|
$class{$name} = [] if not defined $class{$name}; |
|
160
|
58
|
|
|
|
|
75
|
my $cstack = $class{$name}; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Start of a new template tag |
|
163
|
58
|
|
|
|
|
280
|
my $object = $tags->{$name}->new( $tagIndex, $data, |
|
164
|
|
|
|
|
|
|
Language => $self->{'Language'}, |
|
165
|
|
|
|
|
|
|
Directory => $self->{'Directory'}, |
|
166
|
|
|
|
|
|
|
); |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Create miriad double links |
|
169
|
58
|
100
|
|
|
|
232
|
$object->setParent( @stack > 0 ? $stack[$#stack] : $self ); |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Create class double links (same set of classes) |
|
172
|
58
|
100
|
|
|
|
86
|
$object->setClassParent( $cstack->[$#{$cstack}] ) if @{$cstack} > 0; |
|
|
12
|
|
|
|
|
45
|
|
|
|
58
|
|
|
|
|
146
|
|
|
173
|
|
|
|
|
|
|
|
|
174
|
58
|
100
|
|
|
|
171
|
if($object->singleTag()) { |
|
175
|
|
|
|
|
|
|
# End current tag right now |
|
176
|
8
|
50
|
|
|
|
13
|
if(@stack) { |
|
177
|
0
|
|
|
|
|
0
|
$stack[$#stack]->addChild($object); |
|
178
|
|
|
|
|
|
|
} else { |
|
179
|
8
|
|
|
|
|
34
|
$self->addChild($object); |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
} else { |
|
182
|
|
|
|
|
|
|
# Stack the objects up for depth |
|
183
|
50
|
|
|
|
|
65
|
push @stack, $object; |
|
184
|
50
|
|
|
|
|
52
|
push @{$cstack}, $object; |
|
|
50
|
|
|
|
|
173
|
|
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} else { |
|
188
|
80
|
|
|
|
|
98
|
my $found = 0; |
|
189
|
80
|
|
|
|
|
195
|
for(my $i=0;$i<=$#stack;$i++) { |
|
190
|
84
|
100
|
|
|
|
295
|
if($stack[$#stack-$i]->hasTag( $name )) { |
|
191
|
80
|
|
|
|
|
264
|
$stack[$#stack-$i]->addSubTag( $name, $tagIndex, $data ); |
|
192
|
80
|
|
|
|
|
101
|
$found = 1; |
|
193
|
80
|
|
|
|
|
105
|
last; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
80
|
50
|
|
|
|
256
|
if(not $found) { |
|
197
|
0
|
|
|
|
|
0
|
die "Unknown tag: '$name' at $tagIndex; stopping\n"; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
} else { |
|
201
|
106
|
100
|
|
|
|
368
|
if($stack[$#stack]->tagName() eq $name) { |
|
|
|
50
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# End of current template tag set |
|
203
|
50
|
|
|
|
|
56
|
my $cobj = pop @{$cstack}; |
|
|
50
|
|
|
|
|
74
|
|
|
204
|
50
|
|
|
|
|
77
|
my $obj = pop @stack; |
|
205
|
50
|
|
|
|
|
153
|
$obj->setEndTag( $tagIndex ); |
|
206
|
50
|
100
|
|
|
|
101
|
if(@stack) { |
|
207
|
18
|
|
|
|
|
56
|
$stack[$#stack]->addChild($obj); |
|
208
|
|
|
|
|
|
|
} else { |
|
209
|
32
|
|
|
|
|
88
|
$self->addChild($obj); |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
} elsif($stack[$#stack]->hasTag( $name )) { |
|
212
|
|
|
|
|
|
|
# End of a sub structure tag |
|
213
|
56
|
|
|
|
|
177
|
$stack[$#stack]->addEndSubTag( $name, $tagIndex ); |
|
214
|
|
|
|
|
|
|
} else { |
|
215
|
0
|
|
|
|
|
0
|
die "Unknown or misplaced template tag, $name at $tagIndex; stopping\n"; |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
244
|
|
|
|
|
6536
|
$tagIndex++; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
2
|
|
|
|
|
15
|
return $self; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHOR |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Martin Owens - Copyright 2007, AGPL |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |
|
229
|
|
|
|
|
|
|
1; |