line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Preprocessor::TTML::CmdLineProc; |
2
|
|
|
|
|
|
|
$Template::Preprocessor::TTML::CmdLineProc::VERSION = '0.0105'; |
3
|
2
|
|
|
2
|
|
69530
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
54
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use base 'Template::Preprocessor::TTML::Base'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
621
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Template::Preprocessor::TTML::CmdLineProc::Results; |
10
|
|
|
|
|
|
|
$Template::Preprocessor::TTML::CmdLineProc::Results::VERSION = '0.0105'; |
11
|
2
|
|
|
2
|
|
15
|
use base 'Template::Preprocessor::TTML::Base'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3136
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( |
14
|
|
|
|
|
|
|
defines |
15
|
|
|
|
|
|
|
include_files |
16
|
|
|
|
|
|
|
include_path |
17
|
|
|
|
|
|
|
input_filename |
18
|
|
|
|
|
|
|
output_to_stdout |
19
|
|
|
|
|
|
|
output_filename |
20
|
|
|
|
|
|
|
run_mode |
21
|
|
|
|
|
|
|
)); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub initialize |
24
|
|
|
|
|
|
|
{ |
25
|
37
|
|
|
37
|
|
67
|
my $self = shift; |
26
|
37
|
|
|
|
|
122
|
$self->output_to_stdout(1); |
27
|
37
|
|
|
|
|
456
|
$self->include_path([]); |
28
|
37
|
|
|
|
|
411
|
$self->defines(+{}); |
29
|
37
|
|
|
|
|
397
|
$self->include_files([]); |
30
|
37
|
|
|
|
|
398
|
$self->run_mode("regular"); |
31
|
37
|
|
|
|
|
346
|
return 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub add_to_inc |
35
|
|
|
|
|
|
|
{ |
36
|
14
|
|
|
14
|
|
139
|
my $self = shift; |
37
|
14
|
|
|
|
|
24
|
my $path = shift; |
38
|
14
|
|
|
|
|
24
|
push @{$self->include_path()}, $path; |
|
14
|
|
|
|
|
63
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_to_defs |
42
|
|
|
|
|
|
|
{ |
43
|
19
|
|
|
19
|
|
199
|
my ($self, $k, $v) = @_; |
44
|
19
|
|
|
|
|
46
|
$self->defines()->{$k} = $v; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub add_include_file |
48
|
|
|
|
|
|
|
{ |
49
|
4
|
|
|
4
|
|
39
|
my $self = shift; |
50
|
4
|
|
|
|
|
10
|
my $path = shift; |
51
|
4
|
|
|
|
|
9
|
push @{$self->include_files()}, $path; |
|
4
|
|
|
|
|
23
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
package Template::Preprocessor::TTML::CmdLineProc; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( |
57
|
|
|
|
|
|
|
argv |
58
|
|
|
|
|
|
|
result |
59
|
|
|
|
|
|
|
)); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub initialize |
63
|
|
|
|
|
|
|
{ |
64
|
37
|
|
|
37
|
1
|
69
|
my $self = shift; |
65
|
37
|
|
|
|
|
102
|
my (%args) = @_; |
66
|
37
|
|
|
|
|
143
|
$self->argv($args{argv}); |
67
|
|
|
|
|
|
|
|
68
|
37
|
|
|
|
|
544
|
$self->result(Template::Preprocessor::TTML::CmdLineProc::Results->new()); |
69
|
37
|
|
|
|
|
366
|
return 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _get_next_arg |
73
|
|
|
|
|
|
|
{ |
74
|
122
|
|
|
122
|
|
1151
|
my $self = shift; |
75
|
122
|
|
|
|
|
178
|
return shift(@{$self->argv()}); |
|
122
|
|
|
|
|
237
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _no_args_left |
79
|
|
|
|
|
|
|
{ |
80
|
85
|
|
|
85
|
|
134
|
my $self = shift; |
81
|
85
|
|
|
|
|
153
|
return (@{$self->argv()} == 0); |
|
85
|
|
|
|
|
172
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _get_run_mode_opts_map |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
return |
87
|
|
|
|
|
|
|
{ |
88
|
65
|
|
|
65
|
|
346
|
"--version" => "version", |
89
|
|
|
|
|
|
|
"-V" => "version", |
90
|
|
|
|
|
|
|
"--help" => "help", |
91
|
|
|
|
|
|
|
"-h" => "help", |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _get_arged_longs_opts_map |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
return |
98
|
|
|
|
|
|
|
{ |
99
|
18
|
|
|
18
|
|
57
|
"include" => "_process_include_path_opt", |
100
|
|
|
|
|
|
|
"includefile" => "_process_add_includefile_opt", |
101
|
|
|
|
|
|
|
"define" => "_process_define_opt", |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _handle_middle_run_mode_opt |
106
|
|
|
|
|
|
|
{ |
107
|
49
|
|
|
49
|
|
100
|
my ($self, $arg) = @_; |
108
|
49
|
100
|
|
|
|
108
|
if (exists($self->_get_run_mode_opts_map()->{$arg})) |
109
|
|
|
|
|
|
|
{ |
110
|
4
|
|
|
|
|
43
|
die "Option \"$arg\" was specified in the middle of the command line. It should be a standalone option."; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _handle_long_option |
115
|
|
|
|
|
|
|
{ |
116
|
21
|
|
|
21
|
|
45
|
my $self = shift; |
117
|
21
|
|
|
|
|
36
|
my $arg_orig = shift; |
118
|
21
|
100
|
|
|
|
53
|
if ($arg_orig eq "--") |
119
|
|
|
|
|
|
|
{ |
120
|
1
|
|
|
|
|
4
|
return $self->_handle_no_more_options(); |
121
|
|
|
|
|
|
|
} |
122
|
20
|
|
|
|
|
55
|
$self->_handle_middle_run_mode_opt($arg_orig); |
123
|
18
|
|
|
|
|
49
|
my $arg = $arg_orig; |
124
|
18
|
|
|
|
|
63
|
$arg =~ s!^--!!; |
125
|
18
|
|
|
|
|
44
|
my $map = $self->_get_arged_longs_opts_map(); |
126
|
18
|
|
|
|
|
63
|
$arg =~ m{^([^=]*)}; |
127
|
18
|
|
|
|
|
45
|
my $option = $1; |
128
|
18
|
100
|
|
|
|
48
|
if (exists($map->{$option})) |
129
|
|
|
|
|
|
|
{ |
130
|
17
|
|
|
|
|
60
|
my $sub = $self->can($map->{$option}); |
131
|
17
|
100
|
|
|
|
50
|
if (length($arg) eq length($option)) |
132
|
|
|
|
|
|
|
{ |
133
|
10
|
50
|
|
|
|
22
|
if ($self->_no_args_left()) |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
0
|
die "An argument should be specified after \"$arg_orig\""; |
136
|
|
|
|
|
|
|
} |
137
|
10
|
|
|
|
|
117
|
return $sub->( |
138
|
|
|
|
|
|
|
$self, $self->_get_next_arg() |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else |
142
|
|
|
|
|
|
|
{ |
143
|
7
|
|
|
|
|
25
|
return $sub->( |
144
|
|
|
|
|
|
|
$self, substr($arg, length($option)+1) |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
1
|
|
|
|
|
11
|
die "Unknown option!"; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _handle_no_more_options |
152
|
|
|
|
|
|
|
{ |
153
|
1
|
|
|
1
|
|
4
|
my $self = shift; |
154
|
1
|
|
|
|
|
3
|
$self->_assign_filename($self->_get_next_arg()); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _get_arged_short_opts_map |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
return |
160
|
|
|
|
|
|
|
{ |
161
|
27
|
|
|
27
|
|
88
|
"o" => "_process_output_short_opt", |
162
|
|
|
|
|
|
|
"I" => "_process_include_path_opt", |
163
|
|
|
|
|
|
|
"D" => "_process_define_opt", |
164
|
|
|
|
|
|
|
}; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _handle_short_option |
168
|
|
|
|
|
|
|
{ |
169
|
29
|
|
|
29
|
|
51
|
my $self = shift; |
170
|
29
|
|
|
|
|
47
|
my $arg_orig = shift; |
171
|
|
|
|
|
|
|
|
172
|
29
|
|
|
|
|
82
|
$self->_handle_middle_run_mode_opt($arg_orig); |
173
|
|
|
|
|
|
|
|
174
|
27
|
|
|
|
|
76
|
my $arg = $arg_orig; |
175
|
27
|
|
|
|
|
95
|
$arg =~ s!^-!!; |
176
|
27
|
|
|
|
|
68
|
my $map = $self->_get_arged_short_opts_map(); |
177
|
27
|
|
|
|
|
64
|
my $first_char = substr($arg, 0, 1); |
178
|
27
|
50
|
|
|
|
73
|
if (exists($map->{$first_char})) |
179
|
|
|
|
|
|
|
{ |
180
|
27
|
|
|
|
|
101
|
my $sub = $self->can($map->{$first_char}); |
181
|
27
|
100
|
|
|
|
67
|
if (length($arg) > 1) |
182
|
|
|
|
|
|
|
{ |
183
|
14
|
|
|
|
|
44
|
return $sub->( |
184
|
|
|
|
|
|
|
$self, substr($arg, 1) |
185
|
|
|
|
|
|
|
); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
else |
188
|
|
|
|
|
|
|
{ |
189
|
13
|
50
|
|
|
|
30
|
if ($self->_no_args_left()) |
190
|
|
|
|
|
|
|
{ |
191
|
0
|
|
|
|
|
0
|
die "An argument should be specified after \"$arg_orig\""; |
192
|
|
|
|
|
|
|
} |
193
|
13
|
|
|
|
|
151
|
return $sub->( |
194
|
|
|
|
|
|
|
$self, $self->_get_next_arg() |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
0
|
|
|
|
|
0
|
die "Unknown option \"$arg_orig\"!"; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub _process_output_short_opt |
202
|
|
|
|
|
|
|
{ |
203
|
7
|
|
|
7
|
|
68
|
my $self = shift; |
204
|
7
|
|
|
|
|
14
|
my $filename = shift; |
205
|
7
|
|
|
|
|
17
|
$self->result()->output_to_stdout(0); |
206
|
7
|
|
|
|
|
124
|
$self->result()->output_filename($filename); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _process_include_path_opt |
210
|
|
|
|
|
|
|
{ |
211
|
14
|
|
|
14
|
|
83
|
my $self = shift; |
212
|
14
|
|
|
|
|
67
|
my $path = shift; |
213
|
14
|
|
|
|
|
35
|
$self->result()->add_to_inc($path); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _process_add_includefile_opt |
217
|
|
|
|
|
|
|
{ |
218
|
4
|
|
|
4
|
|
26
|
my $self = shift; |
219
|
4
|
|
|
|
|
10
|
my $file = shift; |
220
|
4
|
|
|
|
|
11
|
$self->result()->add_include_file($file); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _process_define_opt |
224
|
|
|
|
|
|
|
{ |
225
|
19
|
|
|
19
|
|
87
|
my $self = shift; |
226
|
19
|
|
|
|
|
44
|
my $def = shift; |
227
|
19
|
50
|
|
|
|
93
|
if ($def !~ m{^([^=]+)=(.*)$}) |
228
|
|
|
|
|
|
|
{ |
229
|
0
|
|
|
|
|
0
|
die "Variable definition should contain a \"=\", but instead it is \"$def\"!"; |
230
|
|
|
|
|
|
|
} |
231
|
19
|
|
|
|
|
66
|
my ($var, $value) = ($1, $2); |
232
|
19
|
|
|
|
|
49
|
$self->result()->add_to_defs($var, $value); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub _assign_filename |
236
|
|
|
|
|
|
|
{ |
237
|
25
|
|
|
25
|
|
69
|
my ($self, $arg) = @_; |
238
|
25
|
100
|
|
|
|
47
|
if (! $self->_no_args_left()) |
239
|
|
|
|
|
|
|
{ |
240
|
1
|
|
|
|
|
18
|
die "Junk after filename"; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
else |
243
|
|
|
|
|
|
|
{ |
244
|
24
|
|
|
|
|
260
|
$self->result()->input_filename($arg); |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub _handle_exclusive_run_mode_opt |
249
|
|
|
|
|
|
|
{ |
250
|
36
|
|
|
36
|
|
63
|
my $self = shift; |
251
|
36
|
100
|
|
|
|
61
|
if ((@{$self->argv()} == 1)) |
|
36
|
|
|
|
|
70
|
|
252
|
|
|
|
|
|
|
{ |
253
|
10
|
|
|
|
|
106
|
my $opt = $self->argv()->[0]; |
254
|
10
|
100
|
|
|
|
100
|
if (exists($self->_get_run_mode_opts_map()->{$opt})) |
255
|
|
|
|
|
|
|
{ |
256
|
|
|
|
|
|
|
$self->result()->run_mode( |
257
|
6
|
|
|
|
|
19
|
$self->_get_run_mode_opts_map()->{$opt} |
258
|
|
|
|
|
|
|
); |
259
|
6
|
|
|
|
|
89
|
return 1; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
} |
262
|
30
|
|
|
|
|
283
|
return 0; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub get_result |
267
|
|
|
|
|
|
|
{ |
268
|
37
|
|
|
37
|
1
|
104
|
my $self = shift; |
269
|
|
|
|
|
|
|
|
270
|
37
|
100
|
|
|
|
82
|
if ($self->_no_args_left()) |
271
|
|
|
|
|
|
|
{ |
272
|
1
|
|
|
|
|
34
|
die "Incorrect usage: you need to specify a filename"; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
36
|
100
|
|
|
|
442
|
if (! $self->_handle_exclusive_run_mode_opt()) |
276
|
|
|
|
|
|
|
{ |
277
|
30
|
|
|
|
|
68
|
while (defined(my $arg = $self->_get_next_arg())) |
278
|
|
|
|
|
|
|
{ |
279
|
74
|
100
|
|
|
|
878
|
if ($arg =~ m{^-}) |
280
|
|
|
|
|
|
|
{ |
281
|
50
|
100
|
|
|
|
129
|
if ($arg =~ m{^--}) |
282
|
|
|
|
|
|
|
{ |
283
|
21
|
|
|
|
|
53
|
$self->_handle_long_option($arg); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
else |
286
|
|
|
|
|
|
|
{ |
287
|
29
|
|
|
|
|
67
|
$self->_handle_short_option($arg); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
else |
291
|
|
|
|
|
|
|
{ |
292
|
24
|
|
|
|
|
50
|
$self->_assign_filename($arg); |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
} |
296
|
30
|
|
|
|
|
281
|
return $self->result(); |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
1; |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
__END__ |