line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Orze; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Orze - Another static website generator |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Version 1.11 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This module is only intended to be used by the script orze. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
See L for more information. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
25051
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
20
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
577
|
use Orze::Modules; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1509
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '1.11'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# default value for attributes |
27
|
|
|
|
|
|
|
my %defaults = ( |
28
|
|
|
|
|
|
|
driver => "Template", |
29
|
|
|
|
|
|
|
template => "index", |
30
|
|
|
|
|
|
|
inmenu => 1, |
31
|
|
|
|
|
|
|
extension => "html", |
32
|
|
|
|
|
|
|
pubmode => "g+rX", |
33
|
|
|
|
|
|
|
pubgroup => "www-data", |
34
|
|
|
|
|
|
|
outputdir => "", |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Create a new orze project, given an xml tree and some options. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $project = XML::Twig->new->parsefile("project.xml"); |
42
|
|
|
|
|
|
|
$project->set_pretty_print('indented'); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $orze = Orze->new($project, %options); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
0
|
|
|
0
|
1
|
|
my ($name, $project, %options) = @_; |
50
|
0
|
|
|
|
|
|
my $self = {}; |
51
|
0
|
|
|
|
|
|
bless $self; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $site = { |
54
|
|
|
|
|
|
|
pages => {}, |
55
|
|
|
|
|
|
|
variables => {}, |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->{project} = $project; |
59
|
0
|
|
|
|
|
|
$self->{options} = \%options; |
60
|
0
|
|
|
|
|
|
$self->{site} = $site; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _propagate { |
66
|
0
|
|
|
0
|
|
|
my ($self, $page, $path) = @_; |
67
|
0
|
|
|
|
|
|
my $parent = $page->parent; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
$path = '' unless defined($path); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if (defined($parent)) { |
72
|
0
|
|
|
|
|
|
print "Reading " . $path . $page->att('name') . "\n"; |
73
|
0
|
|
|
|
|
|
foreach (keys %{$parent->{'att'}}) { |
|
0
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (!defined($page->att($_))) { |
75
|
0
|
|
|
|
|
|
$page->set_att($_ => $parent->att($_)); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my %vars = (); |
80
|
0
|
|
|
|
|
|
foreach ($page->children('var')) { |
81
|
0
|
|
|
|
|
|
$vars{$_->att('name')} = 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
foreach ($page->parent->children('var')) { |
85
|
0
|
0
|
|
|
|
|
if (!exists($vars{$_->att('name')})) { |
86
|
0
|
|
|
|
|
|
my $var = $_->copy; |
87
|
0
|
|
|
|
|
|
$var->paste(first_child => $page); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
0
|
|
|
|
|
|
foreach (keys %defaults) { |
93
|
0
|
0
|
|
|
|
|
if (!defined($page->att($_))) { |
94
|
0
|
|
|
|
|
|
$page->set_att($_ => $defaults{$_}); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$page->set_att(path => $path); |
100
|
0
|
|
|
|
|
|
foreach ($page->children('page')) { |
101
|
0
|
|
|
|
|
|
my $newpath = ""; |
102
|
0
|
0
|
|
|
|
|
if (defined($parent)) { |
103
|
0
|
|
|
|
|
|
$newpath = $path . $page->att('name') . "/"; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
$self->_propagate($_, $newpath); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _evaluate { |
110
|
0
|
|
|
0
|
|
|
my ($self, $page, $site) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ($page->parent) { |
113
|
0
|
|
|
|
|
|
my $path = $page->att('path'); |
114
|
0
|
|
|
|
|
|
my $name = $page->att('name'); |
115
|
0
|
|
|
|
|
|
print "Evaluating in " . $path . $name . "\n"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
0
|
|
|
|
|
|
print "Evaluating in /\n"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
foreach ($page->children('var')) { |
122
|
0
|
|
|
|
|
|
my $varname = $_->att('name'); |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if (defined($_->att('src'))) { |
125
|
0
|
|
|
|
|
|
my $module_name = $_->att('src'); |
126
|
0
|
|
|
|
|
|
my $module = loadSource($module_name); |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $source = $module->new($page, $_); |
129
|
0
|
|
|
|
|
|
$site->{variables}->{$varname} = $source->evaluate(); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
0
|
|
|
|
|
|
$site->{variables}->{$varname} = $_->text; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
foreach ($page->children('page')) { |
137
|
0
|
|
|
|
|
|
my $name = $_->att('name'); |
138
|
0
|
|
|
|
|
|
$site->{pages}->{$name} = { |
139
|
|
|
|
|
|
|
pages => {}, |
140
|
|
|
|
|
|
|
variables => {}, |
141
|
|
|
|
|
|
|
}; |
142
|
0
|
|
|
|
|
|
$self->_evaluate($_, $site->{pages}->{$name}); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub _process { |
147
|
0
|
|
|
0
|
|
|
my ($self, $page, $site) = @_; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my @without = @{$self->{options}->{without}}; |
|
0
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if ($page->parent) { |
152
|
0
|
|
|
|
|
|
my $path = $page->att('path'); |
153
|
0
|
|
|
|
|
|
my $name = $page->att('name'); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
my $module_name = $page->att('driver'); |
156
|
0
|
0
|
|
|
|
|
if (grep {$_ eq $module_name} @without) { |
|
0
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
print "Skipping of " . $path |
158
|
|
|
|
|
|
|
. $name . " because of " . $module_name . "\n"; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
else { |
161
|
0
|
|
|
|
|
|
my $module = loadDriver($module_name); |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $driver = $module->new($page, $site->{variables}); |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
print "Processing of " . $path |
166
|
|
|
|
|
|
|
. $name . " with " . $module_name . "\n"; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$driver->process(); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
foreach ($page->children('page')) { |
173
|
0
|
|
|
|
|
|
my $name = $_->att('name'); |
174
|
0
|
|
|
|
|
|
$self->_process($_, $site->{pages}->{$name}, @without); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _scripts { |
179
|
0
|
|
|
0
|
|
|
my ($self, $page) = @_; |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
if ($page->children('script')) { |
182
|
0
|
|
|
|
|
|
my $loc; |
183
|
0
|
0
|
|
|
|
|
if ($page->parent) { |
184
|
0
|
|
|
|
|
|
$loc = $page->att('path') . $page->att('name'); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
0
|
|
|
|
|
|
$loc = "/"; |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
|
print "Running scripts in ", $loc, "\n"; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
foreach ($page->children('script')) { |
193
|
0
|
|
|
|
|
|
system $_->text; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
foreach ($page->children('page')) { |
197
|
0
|
|
|
|
|
|
$self->_scripts($_); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub _post { |
202
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
my $pub = shift; |
205
|
0
|
0
|
|
|
|
|
if ($pub) { |
206
|
0
|
|
|
|
|
|
system "chgrp " . $defaults{pubgroup} . " -R www/"; |
207
|
0
|
|
|
|
|
|
system "chmod " . $defaults{pubmode} . " -R www/"; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 compile |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Build the project. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $orze = Orze->new($project, %options); |
216
|
|
|
|
|
|
|
$orze->compile; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub compile { |
221
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my $project = $self->{project}; |
224
|
0
|
|
|
|
|
|
my $site = $self->{site}; |
225
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
$self->_propagate($project->root); |
227
|
0
|
|
|
|
|
|
$self->_evaluate($project->root, $site); |
228
|
0
|
|
|
|
|
|
$self->_process($project->root, $site); |
229
|
0
|
|
|
|
|
|
$self->_scripts($project->root); |
230
|
0
|
|
|
|
|
|
$self->_post(); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|