| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Toader::Templates; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
24920
|
use warnings; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
134
|
|
|
4
|
5
|
|
|
5
|
|
26
|
use strict; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
126
|
|
|
5
|
5
|
|
|
5
|
|
2496
|
use Toader::isaToaderDir; |
|
|
5
|
|
|
|
|
14
|
|
|
|
5
|
|
|
|
|
115
|
|
|
6
|
5
|
|
|
5
|
|
36
|
use Cwd 'abs_path'; |
|
|
5
|
|
|
|
|
5
|
|
|
|
5
|
|
|
|
|
280
|
|
|
7
|
5
|
|
|
5
|
|
25
|
use base 'Error::Helper'; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
275
|
|
|
8
|
5
|
|
|
5
|
|
5249
|
use Text::Template; |
|
|
5
|
|
|
|
|
15997
|
|
|
|
5
|
|
|
|
|
203
|
|
|
9
|
5
|
|
|
5
|
|
2741
|
use Toader::Templates::Defaults; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
13912
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Toader::Templates - This handles fetching Toader templates. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 1.0.0 |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
For information on the storage and rendering of entries, |
|
26
|
|
|
|
|
|
|
please see 'Documentation/Templates.pod'. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 new |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head3 args hash ref |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head4 dir |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This is the directory to intiate in. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head4 toader |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This is a L object. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $foo = Toader::Templates->new( \%args ); |
|
43
|
|
|
|
|
|
|
if($foo->error){ |
|
44
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new{ |
|
50
|
0
|
|
|
0
|
1
|
|
my %args; |
|
51
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
|
52
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
|
0
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $self={ |
|
56
|
|
|
|
|
|
|
error=>undef, |
|
57
|
|
|
|
|
|
|
errorString=>'', |
|
58
|
|
|
|
|
|
|
perror=>undef, |
|
59
|
|
|
|
|
|
|
isatd=>Toader::isaToaderDir->new(), |
|
60
|
|
|
|
|
|
|
dir=>undef, |
|
61
|
|
|
|
|
|
|
defaults=>Toader::Templates::Defaults->new, |
|
62
|
|
|
|
|
|
|
errorExtra=>{ |
|
63
|
|
|
|
|
|
|
flags=>{ |
|
64
|
|
|
|
|
|
|
1=>'noDirSpecified', |
|
65
|
|
|
|
|
|
|
2=>'isaToaderDirErrored', |
|
66
|
|
|
|
|
|
|
3=>'notAtoaderDir', |
|
67
|
|
|
|
|
|
|
4=>'invalidTemplateName', |
|
68
|
|
|
|
|
|
|
5=>'openTemplateFailed', |
|
69
|
|
|
|
|
|
|
6=>'noDefaultTemplate', |
|
70
|
|
|
|
|
|
|
7=>'templateFillErrored', |
|
71
|
|
|
|
|
|
|
8=>'templateStringUndef', |
|
72
|
|
|
|
|
|
|
9=>'templateNameUndef', |
|
73
|
|
|
|
|
|
|
10=>'notAtoaderObj', |
|
74
|
|
|
|
|
|
|
11=>'getVCSerrored', |
|
75
|
|
|
|
|
|
|
12=>'VCSusableErrored', |
|
76
|
|
|
|
|
|
|
13=>'noTemplateSpecified', |
|
77
|
|
|
|
|
|
|
14=>'underVCSerrored', |
|
78
|
|
|
|
|
|
|
15=>'VCSaddErrored', |
|
79
|
|
|
|
|
|
|
16=>'VCSdeleteErrored', |
|
80
|
|
|
|
|
|
|
17=>'unlinkFailed', |
|
81
|
|
|
|
|
|
|
18=>'notInDir', |
|
82
|
|
|
|
|
|
|
19=>'noToaderObj', |
|
83
|
|
|
|
|
|
|
}, |
|
84
|
|
|
|
|
|
|
}, |
|
85
|
|
|
|
|
|
|
VCSusable=>0, |
|
86
|
|
|
|
|
|
|
}; |
|
87
|
0
|
|
|
|
|
|
bless $self; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ( defined( $args{dir} ) ){ |
|
90
|
0
|
0
|
|
|
|
|
if ( ! $self->{isatd}->isaToaderDir( $args{dir} ) ){ |
|
91
|
0
|
|
|
|
|
|
$self->{perror}=1; |
|
92
|
0
|
|
|
|
|
|
$self->{error}=1, |
|
93
|
|
|
|
|
|
|
$self->{errorString}='The specified directory is not a Toader directory'; |
|
94
|
0
|
|
|
|
|
|
$self->warn; |
|
95
|
0
|
|
|
|
|
|
return $self; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
0
|
|
|
|
|
|
$self->{dir}=$args{dir}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#if we have a Toader object, reel it in |
|
101
|
0
|
0
|
|
|
|
|
if ( ! defined( $args{toader} ) ){ |
|
102
|
0
|
|
|
|
|
|
$self->{error}=19; |
|
103
|
0
|
|
|
|
|
|
$self->{perror}=1; |
|
104
|
0
|
|
|
|
|
|
$self->{errorString}='No $args{toader} specified'; |
|
105
|
0
|
|
|
|
|
|
$self->warn; |
|
106
|
0
|
|
|
|
|
|
return $self; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
0
|
0
|
|
|
|
|
if ( ref( $args{toader} ) ne "Toader" ){ |
|
109
|
0
|
|
|
|
|
|
$self->{perror}=1; |
|
110
|
0
|
|
|
|
|
|
$self->{error}=10; |
|
111
|
0
|
|
|
|
|
|
$self->{errorString}='The object specified is a "'.ref($args{toader}).'"'; |
|
112
|
0
|
|
|
|
|
|
$self->warn; |
|
113
|
0
|
|
|
|
|
|
return $self; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
0
|
|
|
|
|
|
$self->{toader}=$args{toader}; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#gets the Toader::VCS object |
|
118
|
0
|
|
|
|
|
|
$self->{vcs}=$self->{toader}->getVCS; |
|
119
|
0
|
0
|
|
|
|
|
if ( $self->{toader}->error ){ |
|
120
|
0
|
|
|
|
|
|
$self->{perror}=1; |
|
121
|
0
|
|
|
|
|
|
$self->{error}=11; |
|
122
|
0
|
|
|
|
|
|
$self->{errorString}='Toader->getVCS errored. error="'. |
|
123
|
|
|
|
|
|
|
$self->{toader}->error.'" errorString="'.$self->{toader}->errorString.'"'; |
|
124
|
0
|
|
|
|
|
|
$self->warn; |
|
125
|
0
|
|
|
|
|
|
return $self; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
#checks if VCS is usable |
|
129
|
0
|
|
|
|
|
|
$self->{VCSusable}=$self->{vcs}->usable; |
|
130
|
0
|
0
|
|
|
|
|
if ( $self->{vcs}->error ){ |
|
131
|
0
|
|
|
|
|
|
$self->{perror}=1; |
|
132
|
0
|
|
|
|
|
|
$self->{error}=12; |
|
133
|
0
|
|
|
|
|
|
$self->{errorString}='Toader::VCS->usable errored. error="'. |
|
134
|
|
|
|
|
|
|
$self->{toader}->error.'" errorString="'.$self->{toader}->errorString.'"'; |
|
135
|
0
|
|
|
|
|
|
$self->warn; |
|
136
|
0
|
|
|
|
|
|
return $self; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return $self; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 dirGet |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This gets L directory this entry is associated with. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This will only error if a permanent error is set. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my $dir=$foo->dirGet; |
|
149
|
|
|
|
|
|
|
if($foo->error){ |
|
150
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub dirGet{ |
|
156
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
159
|
0
|
|
|
|
|
|
return undef; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return $self->{dir}; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 dirSet |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This sets L directory this entry is associated with. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
One argument is taken and it is the L directory to set it to. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$foo->dirSet($toaderDirectory); |
|
172
|
|
|
|
|
|
|
if($foo->error){ |
|
173
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub dirSet{ |
|
179
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
180
|
0
|
|
|
|
|
|
my $dir=$_[1]; |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
183
|
0
|
|
|
|
|
|
return undef; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#checks if the directory is Toader directory or not |
|
187
|
0
|
|
|
|
|
|
my $returned=$self->{isatd}->isaToaderDir($dir); |
|
188
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
189
|
0
|
|
|
|
|
|
$self->{error}=1; |
|
190
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$dir.'" is not a Toader directory'; |
|
191
|
0
|
|
|
|
|
|
$self->warn; |
|
192
|
0
|
|
|
|
|
|
return undef; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
$self->{dir}=$dir; |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
return 1; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 fill_in |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This fills in a template that has been passed to it. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Two arguments are taken. The first is the template name. |
|
205
|
|
|
|
|
|
|
The second is a hash reference. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The returned string is the filled out template. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
my $rendered=$foo->fill_in( $templateName, \%hash ); |
|
210
|
|
|
|
|
|
|
if ( $foo->error ){ |
|
211
|
|
|
|
|
|
|
warn( 'Error:'.$foo->error.': '.$foo->errorString ); |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub fill_in{ |
|
217
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
218
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
219
|
0
|
|
|
|
|
|
my $hash=$_[2]; |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
0
|
|
|
|
|
if( ! $self->errorblank ){ |
|
222
|
0
|
|
|
|
|
|
return undef; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
#make sure a template name is specified |
|
226
|
0
|
0
|
|
|
|
|
if ( ! defined( $name ) ){ |
|
227
|
0
|
|
|
|
|
|
$self->{error}=9; |
|
228
|
0
|
|
|
|
|
|
$self->{errorString}='No template name specified'; |
|
229
|
0
|
|
|
|
|
|
$self->warn; |
|
230
|
0
|
|
|
|
|
|
return undef; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
#gets the template |
|
234
|
0
|
|
|
|
|
|
my $template=$self->getTemplate( $name ); |
|
235
|
0
|
0
|
|
|
|
|
if ( $self->error ){ |
|
236
|
0
|
|
|
|
|
|
return undef; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
return $self->fill_in_string( $template, $hash ); |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head2 fill_in_string |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This fills in a template that has been passed to it. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Two arguments are required and the first is the template string to use and |
|
247
|
|
|
|
|
|
|
second it is the hash to pass to it. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
The returned string is the filled out template. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
my $rendered=$foo->fill_in_string( $templateString, \%hash ); |
|
252
|
|
|
|
|
|
|
if ( $foo->error ){ |
|
253
|
|
|
|
|
|
|
warn( 'Error:'.$foo->error.': '.$foo->errorString ); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=cut |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub fill_in_string{ |
|
259
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
260
|
0
|
|
|
|
|
|
my $string=$_[1]; |
|
261
|
0
|
|
|
|
|
|
my $hash=$_[2]; |
|
262
|
|
|
|
|
|
|
|
|
263
|
0
|
0
|
|
|
|
|
if( ! $self->errorblank ){ |
|
264
|
0
|
|
|
|
|
|
return undef; |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
0
|
0
|
|
|
|
|
if ( ! defined( $string ) ){ |
|
268
|
0
|
|
|
|
|
|
$self->{error}=8; |
|
269
|
0
|
|
|
|
|
|
$self->{errorString}='No template string specified'; |
|
270
|
0
|
|
|
|
|
|
$self->warn; |
|
271
|
0
|
|
|
|
|
|
return undef; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
my $template = Text::Template->new( |
|
275
|
|
|
|
|
|
|
TYPE => 'STRING', |
|
276
|
|
|
|
|
|
|
SOURCE => $string, |
|
277
|
|
|
|
|
|
|
DELIMITERS=>[ '[==', '==]' ], |
|
278
|
|
|
|
|
|
|
); |
|
279
|
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my $rendered=$template->fill_in( |
|
281
|
|
|
|
|
|
|
HASH=>$hash, |
|
282
|
|
|
|
|
|
|
); |
|
283
|
|
|
|
|
|
|
|
|
284
|
0
|
0
|
|
|
|
|
if ( ! defined ( $rendered ) ){ |
|
285
|
0
|
|
|
|
|
|
$self->{error}=7; |
|
286
|
0
|
|
|
|
|
|
$self->{errorString}='Error encountered filling in the template'; |
|
287
|
0
|
|
|
|
|
|
$self->warn; |
|
288
|
0
|
|
|
|
|
|
return undef; |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
|
|
291
|
0
|
|
|
|
|
|
return $rendered; |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head2 findTemplate |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
This finds a specified template. |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
One arguement is taken and it is the name of the template. |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
A return of undef can mean either a error or it was not found. |
|
301
|
|
|
|
|
|
|
If there was an error, the method error will return true. |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
my $templateFile=$foo->findTemplate($templateName); |
|
304
|
|
|
|
|
|
|
if( !defined( $templateFile ) ){ |
|
305
|
|
|
|
|
|
|
if($foo->error){ |
|
306
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
307
|
|
|
|
|
|
|
}else{ |
|
308
|
|
|
|
|
|
|
print("Not found\n"); |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
}else{ |
|
311
|
|
|
|
|
|
|
print $templateFile."\n"; |
|
312
|
|
|
|
|
|
|
} |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
sub findTemplate{ |
|
317
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
318
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
319
|
|
|
|
|
|
|
|
|
320
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
321
|
0
|
|
|
|
|
|
return undef; |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
#make sure a directory has been set |
|
325
|
0
|
0
|
|
|
|
|
if (!defined( $self->{dir} )) { |
|
326
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
327
|
0
|
|
|
|
|
|
$self->{errorString}='No directory has been set yet'; |
|
328
|
0
|
|
|
|
|
|
$self->warn; |
|
329
|
0
|
|
|
|
|
|
return undef; |
|
330
|
|
|
|
|
|
|
} |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
#checks if the name is valid |
|
333
|
0
|
|
|
|
|
|
my $returned=$self->templateNameCheck($name); |
|
334
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
335
|
0
|
|
|
|
|
|
$self->{error}=4; |
|
336
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$name.'" is not a valid template name'; |
|
337
|
0
|
|
|
|
|
|
$self->warn; |
|
338
|
0
|
|
|
|
|
|
return undef; |
|
339
|
|
|
|
|
|
|
} |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
#checks if the directory is Toader directory or not |
|
342
|
0
|
|
|
|
|
|
$returned=$self->{isatd}->isaToaderDir( $self->{dir} ); |
|
343
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
344
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
345
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$self->{dir}.'" is no longer a Toader directory'; |
|
346
|
0
|
|
|
|
|
|
$self->warn; |
|
347
|
0
|
|
|
|
|
|
return undef; |
|
348
|
|
|
|
|
|
|
} |
|
349
|
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
#initial stuff to check |
|
351
|
0
|
|
|
|
|
|
my $dir=$self->{dir}; |
|
352
|
0
|
|
|
|
|
|
my $template=$dir.'/.toader/templates/'.$name; |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
#checks if the template exists |
|
355
|
0
|
0
|
|
|
|
|
if (-f $template) { |
|
356
|
0
|
|
|
|
|
|
return $template; |
|
357
|
|
|
|
|
|
|
} |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
#recurse down trying to find the last one |
|
360
|
0
|
|
|
|
|
|
$dir=abs_path($dir.'/..'); |
|
361
|
|
|
|
|
|
|
#we will always find something below so it is just set to 1 |
|
362
|
0
|
|
|
|
|
|
while (1) { |
|
363
|
|
|
|
|
|
|
#we hit the FS root... |
|
364
|
|
|
|
|
|
|
#if he hit this, something is definitely wrong |
|
365
|
0
|
0
|
|
|
|
|
if ($dir eq '/') { |
|
366
|
0
|
|
|
|
|
|
return undef; |
|
367
|
|
|
|
|
|
|
} |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
#make sure |
|
370
|
0
|
|
|
|
|
|
$returned=$self->{isatd}->isaToaderDir($dir); |
|
371
|
0
|
0
|
|
|
|
|
if (!$returned) { |
|
372
|
0
|
|
|
|
|
|
return undef; |
|
373
|
|
|
|
|
|
|
} |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
#check if it exists |
|
376
|
0
|
|
|
|
|
|
$template=$dir.'/.toader/templates/'.$name; |
|
377
|
0
|
0
|
|
|
|
|
if (-f $template) { |
|
378
|
0
|
|
|
|
|
|
return $template; |
|
379
|
|
|
|
|
|
|
} |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
#check the next directory |
|
382
|
0
|
|
|
|
|
|
$dir=abs_path($dir.'/..'); |
|
383
|
|
|
|
|
|
|
} |
|
384
|
|
|
|
|
|
|
} |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
=head2 getTemplate |
|
387
|
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
This finds a template and then returns it. |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
The method findTemplate will be used and if that fails the default |
|
391
|
|
|
|
|
|
|
template will be returned. |
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
One arguement is required and it is the template name. |
|
394
|
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
my $template=$foo->getTemplate($templateName); |
|
396
|
|
|
|
|
|
|
if($foo->error){ |
|
397
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
398
|
|
|
|
|
|
|
} |
|
399
|
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=cut |
|
401
|
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
sub getTemplate{ |
|
403
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
404
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
405
|
|
|
|
|
|
|
|
|
406
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
407
|
0
|
|
|
|
|
|
return undef; |
|
408
|
|
|
|
|
|
|
} |
|
409
|
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
#make sure a template name is specified |
|
411
|
0
|
0
|
|
|
|
|
if ( ! defined( $name ) ){ |
|
412
|
0
|
|
|
|
|
|
$self->{error}=9; |
|
413
|
0
|
|
|
|
|
|
$self->{errorString}='No template name specified'; |
|
414
|
0
|
|
|
|
|
|
$self->warn; |
|
415
|
0
|
|
|
|
|
|
return undef; |
|
416
|
|
|
|
|
|
|
} |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
#try to find it as a file |
|
419
|
|
|
|
|
|
|
#also allow this to do the error checking as it is the same |
|
420
|
0
|
|
|
|
|
|
my $file=$self->findTemplate($name); |
|
421
|
0
|
0
|
|
|
|
|
if ($self->error) { |
|
422
|
0
|
|
|
|
|
|
$self->warnString('findTemplate errored'); |
|
423
|
0
|
|
|
|
|
|
return undef; |
|
424
|
|
|
|
|
|
|
} |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
#the contents of the template to be returned |
|
427
|
0
|
|
|
|
|
|
my $template; |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
#if we found a file, read it and return it |
|
430
|
0
|
0
|
|
|
|
|
if (defined($file)) { |
|
431
|
0
|
|
|
|
|
|
my $fh; |
|
432
|
0
|
0
|
|
|
|
|
if ( ! open( $fh, '<', $file ) ) { |
|
433
|
0
|
|
|
|
|
|
$self->{error}=5; |
|
434
|
0
|
|
|
|
|
|
$self->{errorString}="Unable to open '".$file."'"; |
|
435
|
0
|
|
|
|
|
|
$self->warn; |
|
436
|
0
|
|
|
|
|
|
return undef; |
|
437
|
|
|
|
|
|
|
} |
|
438
|
0
|
|
|
|
|
|
$template=join('',<$fh>); |
|
439
|
0
|
|
|
|
|
|
close $fh; |
|
440
|
0
|
|
|
|
|
|
return $template; |
|
441
|
|
|
|
|
|
|
} |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
#tries to fetch the default template |
|
444
|
0
|
|
|
|
|
|
$template=$self->{defaults}->getTemplate($name); |
|
445
|
0
|
0
|
|
|
|
|
if ( ! defined( $template ) ) { |
|
446
|
0
|
|
|
|
|
|
$self->{error}=6; |
|
447
|
0
|
|
|
|
|
|
$self->{errorString}='No default template'; |
|
448
|
0
|
|
|
|
|
|
$self->warn; |
|
449
|
0
|
|
|
|
|
|
return undef; |
|
450
|
|
|
|
|
|
|
} |
|
451
|
|
|
|
|
|
|
|
|
452
|
0
|
|
|
|
|
|
return $template; |
|
453
|
|
|
|
|
|
|
} |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
=head2 getTemplateDefault |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
This finds a default template and then returns it. |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
One arguement is required and it is the template name. |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
my $template=$foo->getTemplate($templateName); |
|
462
|
|
|
|
|
|
|
if($foo->error){ |
|
463
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
464
|
|
|
|
|
|
|
} |
|
465
|
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
=cut |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
sub getTemplateDefault{ |
|
469
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
470
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
471
|
|
|
|
|
|
|
|
|
472
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
473
|
0
|
|
|
|
|
|
return undef; |
|
474
|
|
|
|
|
|
|
} |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
#make sure a template name is specified |
|
477
|
0
|
0
|
|
|
|
|
if ( ! defined( $name ) ){ |
|
478
|
0
|
|
|
|
|
|
$self->{error}=9; |
|
479
|
0
|
|
|
|
|
|
$self->{errorString}='No template name specified'; |
|
480
|
0
|
|
|
|
|
|
$self->warn; |
|
481
|
0
|
|
|
|
|
|
return undef; |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
#tries to fetch the default template |
|
485
|
0
|
|
|
|
|
|
my $template=$self->{defaults}->getTemplate($name); |
|
486
|
0
|
0
|
|
|
|
|
if ( ! defined( $template ) ) { |
|
487
|
0
|
|
|
|
|
|
$self->{error}=6; |
|
488
|
0
|
|
|
|
|
|
$self->{errorString}='No default template'; |
|
489
|
0
|
|
|
|
|
|
$self->warn; |
|
490
|
0
|
|
|
|
|
|
return undef; |
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
|
|
493
|
0
|
|
|
|
|
|
return $template; |
|
494
|
|
|
|
|
|
|
} |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
=head2 listTemplates |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
This lists the various templates in the directory. |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
my @templates=$foo->listTemplates; |
|
501
|
|
|
|
|
|
|
if($foo->error){ |
|
502
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
503
|
|
|
|
|
|
|
} |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=cut |
|
506
|
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
sub listTemplates{ |
|
508
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
509
|
|
|
|
|
|
|
|
|
510
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
511
|
0
|
|
|
|
|
|
return undef; |
|
512
|
|
|
|
|
|
|
} |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
#make sure a directory has been set |
|
515
|
0
|
0
|
|
|
|
|
if (!defined( $self->{dir} )) { |
|
516
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
517
|
0
|
|
|
|
|
|
$self->{errorString}='No directory has been set yet'; |
|
518
|
0
|
|
|
|
|
|
$self->warn; |
|
519
|
0
|
|
|
|
|
|
return undef; |
|
520
|
|
|
|
|
|
|
} |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
#checks if the directory is Toader directory or not |
|
523
|
0
|
|
|
|
|
|
my $returned=$self->{isatd}->isaToaderDir( $self->{dir} ); |
|
524
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
525
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
526
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$self->{dir}.'" is no longer a Toader directory'; |
|
527
|
0
|
|
|
|
|
|
$self->warn; |
|
528
|
0
|
|
|
|
|
|
return undef; |
|
529
|
|
|
|
|
|
|
} |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
#the directory to list |
|
532
|
0
|
|
|
|
|
|
my $dir=$self->{dir}.'/.toader/templates/'; |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
#makes sure the template exists and if it does not, return only having the default |
|
535
|
0
|
0
|
|
|
|
|
if (! -d $dir) { |
|
536
|
0
|
|
|
|
|
|
return; |
|
537
|
|
|
|
|
|
|
} |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
#lists each theme |
|
540
|
0
|
|
|
|
|
|
my $dh; |
|
541
|
0
|
0
|
|
|
|
|
if (opendir($dh, $dir )) { |
|
542
|
0
|
|
|
|
|
|
$self->{error}='4'; |
|
543
|
0
|
|
|
|
|
|
$self->{errorString}='Failed to open the directory "'.$dir.'"'; |
|
544
|
0
|
|
|
|
|
|
$self->warn; |
|
545
|
0
|
|
|
|
|
|
return undef; |
|
546
|
|
|
|
|
|
|
} |
|
547
|
0
|
|
|
|
|
|
my @templates=grep( { -f $dir.'/'.$_ } readdir($dh) ); |
|
|
0
|
|
|
|
|
|
|
|
548
|
0
|
|
|
|
|
|
close($dh); |
|
549
|
|
|
|
|
|
|
|
|
550
|
0
|
|
|
|
|
|
return \@templates; |
|
551
|
|
|
|
|
|
|
} |
|
552
|
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=head2 listDefaultTemplates |
|
554
|
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
This lists the various templates in the directory. |
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
my @templates=$foo->listTemplates; |
|
558
|
|
|
|
|
|
|
if($foo->error){ |
|
559
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
560
|
|
|
|
|
|
|
} |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=cut |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
sub listDefaultTemplates{ |
|
565
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
566
|
|
|
|
|
|
|
|
|
567
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
568
|
0
|
|
|
|
|
|
return undef; |
|
569
|
|
|
|
|
|
|
} |
|
570
|
|
|
|
|
|
|
|
|
571
|
0
|
|
|
|
|
|
return $self->{defaults}->listTemplates; |
|
572
|
|
|
|
|
|
|
} |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
=head2 remove |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
This removes a template from the current directory. |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
One argument is required and that is the name of the template. |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
$foo->remove( $name ); |
|
581
|
|
|
|
|
|
|
if($foo->error){ |
|
582
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
583
|
|
|
|
|
|
|
} |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=cut |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
sub remove{ |
|
588
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
589
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
590
|
|
|
|
|
|
|
|
|
591
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
592
|
0
|
|
|
|
|
|
return undef; |
|
593
|
|
|
|
|
|
|
} |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
#make sure a directory has been set |
|
596
|
0
|
0
|
|
|
|
|
if (!defined( $self->{dir} )) { |
|
597
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
598
|
0
|
|
|
|
|
|
$self->{errorString}='No directory has been set yet'; |
|
599
|
0
|
|
|
|
|
|
$self->warn; |
|
600
|
0
|
|
|
|
|
|
return undef; |
|
601
|
|
|
|
|
|
|
} |
|
602
|
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
#make sure a template name is specified |
|
604
|
0
|
0
|
|
|
|
|
if ( ! defined( $name ) ){ |
|
605
|
0
|
|
|
|
|
|
$self->{error}=9; |
|
606
|
0
|
|
|
|
|
|
$self->{errorString}='No template name specified'; |
|
607
|
0
|
|
|
|
|
|
$self->warn; |
|
608
|
0
|
|
|
|
|
|
return undef; |
|
609
|
|
|
|
|
|
|
} |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
#checks if the name is valid |
|
612
|
0
|
|
|
|
|
|
my $returned=$self->templateNameCheck($name); |
|
613
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
614
|
0
|
|
|
|
|
|
$self->{error}=4; |
|
615
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$name.'" is not a valid template name'; |
|
616
|
0
|
|
|
|
|
|
$self->warn; |
|
617
|
0
|
|
|
|
|
|
return undef; |
|
618
|
|
|
|
|
|
|
} |
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
#make sure the template is in this directory |
|
621
|
0
|
0
|
|
|
|
|
if ( ! $self->templateInDir( $name ) ){ |
|
622
|
0
|
|
|
|
|
|
$self->{error}=18; |
|
623
|
0
|
|
|
|
|
|
$self->{errorString}='Template "'.$name.'" is not in "'. |
|
624
|
|
|
|
|
|
|
$self->{dir}.'"'; |
|
625
|
0
|
|
|
|
|
|
$self->warn; |
|
626
|
0
|
|
|
|
|
|
return undef; |
|
627
|
|
|
|
|
|
|
} |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
#the file in question |
|
630
|
0
|
|
|
|
|
|
my $file=$self->{dir}.'/.toader/templates/'.$name; |
|
631
|
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
#try to unlink the file |
|
633
|
0
|
0
|
|
|
|
|
if ( ! unlink( $file ) ) { |
|
634
|
0
|
|
|
|
|
|
$self->{error}=17; |
|
635
|
0
|
|
|
|
|
|
$self->{errorString}='Unlink of "'.$file.'" failed'; |
|
636
|
0
|
|
|
|
|
|
$self->warn; |
|
637
|
0
|
|
|
|
|
|
return undef; |
|
638
|
|
|
|
|
|
|
} |
|
639
|
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
#if VCS is not usable, return here |
|
641
|
0
|
0
|
|
|
|
|
if ( ! $self->{VCSusable} ){ |
|
642
|
0
|
|
|
|
|
|
return 1; |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
#if it is not under VCS, we have nothing to do |
|
646
|
0
|
|
|
|
|
|
my $underVCS=$self->{vcs}->underVCS($file); |
|
647
|
0
|
0
|
|
|
|
|
if ( $self->{vcs}->error ){ |
|
648
|
0
|
|
|
|
|
|
$self->{error}=14; |
|
649
|
0
|
|
|
|
|
|
$self->{errorString}='Toader::VCS->underVCS errored. error="'. |
|
650
|
|
|
|
|
|
|
$self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; |
|
651
|
0
|
|
|
|
|
|
$self->warn; |
|
652
|
0
|
|
|
|
|
|
return undef; |
|
653
|
|
|
|
|
|
|
} |
|
654
|
0
|
0
|
|
|
|
|
if ( $underVCS ){ |
|
655
|
0
|
|
|
|
|
|
return 1; |
|
656
|
|
|
|
|
|
|
} |
|
657
|
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
#delete it as if we reach here it is not under VCS and VCS is being used |
|
659
|
0
|
|
|
|
|
|
$self->{vcs}->delete( $file ); |
|
660
|
0
|
0
|
|
|
|
|
if ( $self->{vcs}->error ){ |
|
661
|
0
|
|
|
|
|
|
$self->{error}=16; |
|
662
|
0
|
|
|
|
|
|
$self->{errorString}='Toader::VCS->delete errored. error="'. |
|
663
|
|
|
|
|
|
|
$self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; |
|
664
|
0
|
|
|
|
|
|
$self->warn; |
|
665
|
0
|
|
|
|
|
|
return undef; |
|
666
|
|
|
|
|
|
|
} |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
|
|
669
|
0
|
|
|
|
|
|
return 1; |
|
670
|
|
|
|
|
|
|
} |
|
671
|
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
=head2 set |
|
673
|
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
This sets a template in the current directory. |
|
675
|
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
Two arguments are required and those in order are the name |
|
677
|
|
|
|
|
|
|
template and the template. |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
$foo->set( $name, $template ); |
|
680
|
|
|
|
|
|
|
if($foo->error){ |
|
681
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
682
|
|
|
|
|
|
|
} |
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
=cut |
|
685
|
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
sub set{ |
|
687
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
688
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
689
|
0
|
|
|
|
|
|
my $template=$_[2]; |
|
690
|
|
|
|
|
|
|
|
|
691
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
692
|
0
|
|
|
|
|
|
return undef; |
|
693
|
|
|
|
|
|
|
} |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
#make sure a directory has been set |
|
696
|
0
|
0
|
|
|
|
|
if (!defined( $self->{dir} )) { |
|
697
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
698
|
0
|
|
|
|
|
|
$self->{errorString}='No directory has been set yet'; |
|
699
|
0
|
|
|
|
|
|
$self->warn; |
|
700
|
0
|
|
|
|
|
|
return undef; |
|
701
|
|
|
|
|
|
|
} |
|
702
|
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
#make sure a template name is specified |
|
704
|
0
|
0
|
|
|
|
|
if ( ! defined( $name ) ){ |
|
705
|
0
|
|
|
|
|
|
$self->{error}=9; |
|
706
|
0
|
|
|
|
|
|
$self->{errorString}='No template name specified'; |
|
707
|
0
|
|
|
|
|
|
$self->warn; |
|
708
|
0
|
|
|
|
|
|
return undef; |
|
709
|
|
|
|
|
|
|
} |
|
710
|
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
#checks if the name is valid |
|
712
|
0
|
|
|
|
|
|
my $returned=$self->templateNameCheck($name); |
|
713
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
714
|
0
|
|
|
|
|
|
$self->{error}=4; |
|
715
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$name.'" is not a valid template name'; |
|
716
|
0
|
|
|
|
|
|
$self->warn; |
|
717
|
0
|
|
|
|
|
|
return undef; |
|
718
|
|
|
|
|
|
|
} |
|
719
|
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
#make sure a template name is specified |
|
721
|
0
|
0
|
|
|
|
|
if ( ! defined( $template ) ){ |
|
722
|
0
|
|
|
|
|
|
$self->{error}=13; |
|
723
|
0
|
|
|
|
|
|
$self->{errorString}='No template specified'; |
|
724
|
0
|
|
|
|
|
|
$self->warn; |
|
725
|
0
|
|
|
|
|
|
return undef; |
|
726
|
|
|
|
|
|
|
} |
|
727
|
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
#the file in question |
|
729
|
0
|
|
|
|
|
|
my $file=$self->{dir}.'/.toader/templates/'.$name; |
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
#write the template out |
|
732
|
0
|
|
|
|
|
|
my $fh; |
|
733
|
0
|
0
|
|
|
|
|
if ( ! open( $fh, '>', $file ) ){ |
|
734
|
0
|
|
|
|
|
|
$self->{error}=5; |
|
735
|
0
|
|
|
|
|
|
$self->{errorString}='Unable to open "'.$file.'" for writing'; |
|
736
|
0
|
|
|
|
|
|
$self->warn; |
|
737
|
0
|
|
|
|
|
|
return undef; |
|
738
|
|
|
|
|
|
|
} |
|
739
|
0
|
|
|
|
|
|
print $fh $template; |
|
740
|
0
|
|
|
|
|
|
close $fh; |
|
741
|
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
#if VCS is not usable, return here |
|
743
|
0
|
0
|
|
|
|
|
if ( ! $self->{VCSusable} ){ |
|
744
|
0
|
|
|
|
|
|
return 1; |
|
745
|
|
|
|
|
|
|
} |
|
746
|
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
#if it is not under VCS, we have nothing to do |
|
748
|
0
|
|
|
|
|
|
my $underVCS=$self->{vcs}->underVCS($file); |
|
749
|
0
|
0
|
|
|
|
|
if ( $self->{vcs}->error ){ |
|
750
|
0
|
|
|
|
|
|
$self->{error}=14; |
|
751
|
0
|
|
|
|
|
|
$self->{errorString}='Toader::VCS->underVCS errored. error="'. |
|
752
|
|
|
|
|
|
|
$self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; |
|
753
|
0
|
|
|
|
|
|
$self->warn; |
|
754
|
0
|
|
|
|
|
|
return undef; |
|
755
|
|
|
|
|
|
|
} |
|
756
|
0
|
0
|
|
|
|
|
if ( $underVCS ){ |
|
757
|
0
|
|
|
|
|
|
return 1; |
|
758
|
|
|
|
|
|
|
} |
|
759
|
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
#add it as if we reach here it is not under VCS and VCS is being used |
|
761
|
0
|
|
|
|
|
|
$self->{vcs}->add( $file ); |
|
762
|
0
|
0
|
|
|
|
|
if ( $self->{vcs}->error ){ |
|
763
|
0
|
|
|
|
|
|
$self->{error}=15; |
|
764
|
0
|
|
|
|
|
|
$self->{errorString}='Toader::VCS->add errored. error="'. |
|
765
|
|
|
|
|
|
|
$self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; |
|
766
|
0
|
|
|
|
|
|
$self->warn; |
|
767
|
0
|
|
|
|
|
|
return undef; |
|
768
|
|
|
|
|
|
|
} |
|
769
|
|
|
|
|
|
|
|
|
770
|
0
|
|
|
|
|
|
return 1; |
|
771
|
|
|
|
|
|
|
} |
|
772
|
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
=head2 templateInDir |
|
774
|
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
This checks if the template is in the current directory. |
|
776
|
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
One argument is required and that is the name of the template. |
|
778
|
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
$foo->templateInDir( $name ); |
|
780
|
|
|
|
|
|
|
if($foo->error){ |
|
781
|
|
|
|
|
|
|
warn('Error:'.$foo->error.': '.$foo->errorString); |
|
782
|
|
|
|
|
|
|
} |
|
783
|
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
=cut |
|
785
|
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
sub templateInDir{ |
|
787
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
788
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
789
|
|
|
|
|
|
|
|
|
790
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
791
|
0
|
|
|
|
|
|
return undef; |
|
792
|
|
|
|
|
|
|
} |
|
793
|
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
#make sure a directory has been set |
|
795
|
0
|
0
|
|
|
|
|
if (!defined( $self->{dir} )) { |
|
796
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
797
|
0
|
|
|
|
|
|
$self->{errorString}='No directory has been set yet'; |
|
798
|
0
|
|
|
|
|
|
$self->warn; |
|
799
|
0
|
|
|
|
|
|
return undef; |
|
800
|
|
|
|
|
|
|
} |
|
801
|
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
#make sure a template name is specified |
|
803
|
0
|
0
|
|
|
|
|
if ( ! defined( $name ) ){ |
|
804
|
0
|
|
|
|
|
|
$self->{error}=9; |
|
805
|
0
|
|
|
|
|
|
$self->{errorString}='No template name specified'; |
|
806
|
0
|
|
|
|
|
|
$self->warn; |
|
807
|
0
|
|
|
|
|
|
return undef; |
|
808
|
|
|
|
|
|
|
} |
|
809
|
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
#checks if the name is valid |
|
811
|
0
|
|
|
|
|
|
my $returned=$self->templateNameCheck($name); |
|
812
|
0
|
0
|
|
|
|
|
if (! $returned ) { |
|
813
|
0
|
|
|
|
|
|
$self->{error}=4; |
|
814
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$name.'" is not a valid template name'; |
|
815
|
0
|
|
|
|
|
|
$self->warn; |
|
816
|
0
|
|
|
|
|
|
return undef; |
|
817
|
|
|
|
|
|
|
} |
|
818
|
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
#the file in question |
|
820
|
0
|
|
|
|
|
|
my $file=$self->{dir}.'/.toader/templates/'.$name; |
|
821
|
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
#checks if it exists |
|
823
|
0
|
0
|
|
|
|
|
if ( -f $file ){ |
|
824
|
0
|
|
|
|
|
|
return 1; |
|
825
|
|
|
|
|
|
|
} |
|
826
|
|
|
|
|
|
|
|
|
827
|
0
|
|
|
|
|
|
return 0; |
|
828
|
|
|
|
|
|
|
} |
|
829
|
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
=head2 templateNameCheck |
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
This makes sure checks to make sure a template name is valid. |
|
833
|
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
my $returned=$foo->templateNameCheck($name); |
|
835
|
|
|
|
|
|
|
if ($returned){ |
|
836
|
|
|
|
|
|
|
print "Valid\n"; |
|
837
|
|
|
|
|
|
|
} |
|
838
|
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
=cut |
|
840
|
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
sub templateNameCheck{ |
|
842
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
843
|
0
|
|
|
|
|
|
my $name=$_[1]; |
|
844
|
|
|
|
|
|
|
|
|
845
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
|
846
|
0
|
|
|
|
|
|
return undef; |
|
847
|
|
|
|
|
|
|
} |
|
848
|
|
|
|
|
|
|
|
|
849
|
0
|
0
|
|
|
|
|
if (!defined($name)) { |
|
850
|
0
|
|
|
|
|
|
return 0; |
|
851
|
|
|
|
|
|
|
} |
|
852
|
0
|
0
|
|
|
|
|
if ($name =~ /^ /) { |
|
853
|
0
|
|
|
|
|
|
return 0; |
|
854
|
|
|
|
|
|
|
} |
|
855
|
0
|
0
|
|
|
|
|
if ($name =~ /\t/) { |
|
856
|
0
|
|
|
|
|
|
return 0; |
|
857
|
|
|
|
|
|
|
} |
|
858
|
0
|
0
|
|
|
|
|
if ($name =~ /\n/) { |
|
859
|
0
|
|
|
|
|
|
return 0; |
|
860
|
|
|
|
|
|
|
} |
|
861
|
0
|
0
|
|
|
|
|
if ($name =~ / $/) { |
|
862
|
0
|
|
|
|
|
|
return 0; |
|
863
|
|
|
|
|
|
|
} |
|
864
|
|
|
|
|
|
|
|
|
865
|
0
|
|
|
|
|
|
return 1; |
|
866
|
|
|
|
|
|
|
} |
|
867
|
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
=head1 ERROR CODES |
|
869
|
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
=head2 1, noDirSpecified |
|
871
|
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
The specified directory is not a L directory. |
|
873
|
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
=head2 2, isaToaderDirErrored |
|
875
|
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
No directory has been specified yet. |
|
877
|
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
=head2 3, notAtoaderDir |
|
879
|
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
The directory in question is no longer a toader directory. |
|
881
|
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
=head2 4, invalidTemplateName |
|
883
|
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
Not a valid template name. |
|
885
|
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
=head2 5, openTemplateFailed |
|
887
|
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
Unable to open the template file. |
|
889
|
|
|
|
|
|
|
|
|
890
|
|
|
|
|
|
|
=head2 6, noDefaultTemplate |
|
891
|
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
Unable to fetch the default template. It does not exist. |
|
893
|
|
|
|
|
|
|
|
|
894
|
|
|
|
|
|
|
=head2 7, templateFillErrored |
|
895
|
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
Errored filling out the template string. |
|
897
|
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
=head2 8, templateStringUndef |
|
899
|
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
Nothing specified for the template string. |
|
901
|
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
=head2 9, templateNameUndef |
|
903
|
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
Template name is not defined. |
|
905
|
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
=head2 10, notAtoaderObj |
|
907
|
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
The object in question is not a Toader object. |
|
909
|
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
=head2 11, getVCSerrored |
|
911
|
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
L->getVCS errored. |
|
913
|
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
=head2 12, VCSusableErrored |
|
915
|
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
L->usable errored. |
|
917
|
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
=head2 13, noTemplateSpecified |
|
919
|
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
Nothing specified for the data for a template. |
|
921
|
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
=head2 14, underVCSerrored |
|
923
|
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
L->underVCS errored. |
|
925
|
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
=head2 15, VCSaddErrored |
|
927
|
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
L->add errored. |
|
929
|
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
=head2 16, VCSdeleteErrored |
|
931
|
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
L->delete errored. |
|
933
|
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
=head2 17, unlinkFailed |
|
935
|
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
Failed to unlink the template. |
|
937
|
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
=head2 18, notInDir |
|
939
|
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
The requested template is not in this Toader dir. |
|
941
|
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
=head2 19, noToaderObj |
|
943
|
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
No L object is given. |
|
945
|
|
|
|
|
|
|
|
|
946
|
|
|
|
|
|
|
=head1 AUTHOR |
|
947
|
|
|
|
|
|
|
|
|
948
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
|
949
|
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
=head1 BUGS |
|
951
|
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
953
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
954
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
955
|
|
|
|
|
|
|
|
|
956
|
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
=head1 SUPPORT |
|
960
|
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
962
|
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
perldoc Toader::Templates |
|
964
|
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
You can also look for information at: |
|
967
|
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
=over 4 |
|
969
|
|
|
|
|
|
|
|
|
970
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
971
|
|
|
|
|
|
|
|
|
972
|
|
|
|
|
|
|
L |
|
973
|
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
975
|
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
L |
|
977
|
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
979
|
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
L |
|
981
|
|
|
|
|
|
|
|
|
982
|
|
|
|
|
|
|
=item * Search CPAN |
|
983
|
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
L |
|
985
|
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
=back |
|
987
|
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
|
|
989
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
990
|
|
|
|
|
|
|
|
|
991
|
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
993
|
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
Copyright 2013 Zane C. Bowers-Hadley. |
|
995
|
|
|
|
|
|
|
|
|
996
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
997
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
998
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
999
|
|
|
|
|
|
|
|
|
1000
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
1001
|
|
|
|
|
|
|
|
|
1002
|
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
=cut |
|
1004
|
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
1; # End of Toader::Templates |