PML.pm

filter: Statementstmt 81.8% 1002 / 1224 Branchbran 62.1% 338 / 544 Conditioncond 47.7% 119 / 249 MC/DCmcdc 18.0% 27 / 150 Subroutinesub 94.0% 127 / 135 Podpod 14.2% 8 / 56 totaltotal 68.7% 1621 / 2358 CC 387 SCAR 36.1
CC
387
Cov
72%
token_set
258.2
replace_variable
76.5
parse_one_line
51.9
CRAP 36.8
↑ Summary PML/File.pm »
1 ################################################################################
2 #
3 # PML.pm (PML Markup Language)
4 #
5 ################################################################################
6 #
7 # Copyright (C) 1999-2000 Peter J Jones (pjones@cpan.org)
8 # All Rights Reserved
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 #
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. Neither the name of the Author nor the names of its contributors
20 # may be used to endorse or promote products derived from this software
21 # without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
24 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
33 # DAMAGE.
34 #
35 ################################################################################
36 #
37 # POD
38 #
39 ################################################################################
40  
41 =pod
42  
43 =head1 NAME
44  
45 PML (PML Markup Lanuage)
46  
47 =head1 SYNOPSIS
48  
49 use PML;
50  
51 my $parser = new PML;
52  
53 $parser->parse('/path/to/somefile');
54  
55 my $output = $parser->execute;
56  
57 =head1 DESCRIPTION
58  
59 PML is a powerful text preprocessor. It supports such things as
60 variables, flow control and macros. After preprocessing a text file
61 it returns the result to your Perl script. The power comes from
62 the fact that you can even embed Perl code into the file that is
63 getting processed.
64  
65 PML was originaly designed to seperate a Perl CGI script and the
66 HTML that it generates. What sets PML apart from other similar
67 solutions is that it is not just a web solution using mod_perl.
68 You can parse PML files from the command line using the supplied
69 pml script or from within your Perl scripts using the PML Perl
70 module.
71  
72 If you do have mod_perl, you can use the supplied mod_pml Apache
73 module to parse PML files from within the Apache web server.
74  
75 =head1 EXAMPLE PML FILE
76  
77 <html>
78 <head>
79 <title>${title}</title>
80 </head>
81 <body>
82 @if(${title}) {
83 <h1>${title}</h1>
84 }
85 </body>
86 </html>
87  
88 =head1 DOCUMENTATION
89  
90 Documentation is supplied with this module, in the doc directory.
91  
92 language.html: describes the language.
93  
94 pml-modules.html: tells you how to write a PML module
95  
96 pml-custom-app.html: tells you how to extend PML from
97 within your application.
98  
99 =head1 USAGE
100  
101 The following is an overview of the PML API
102  
103 =cut
104 ################################################################################
105 #
106 # Package Definition
107 #
108 ################################################################################
109 package PML; {
110 package PML::Token;
111 18 ▶ use base PML;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 }
113 ################################################################################
114 #
115 # Includes
116 #
117 ################################################################################
118 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 18 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 18 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 18 ▶use Cwd qw(cwd chdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
123 ################################################################################
124 #
125 # Constants
126 #
127 ################################################################################
128 18 ▶use constant ID => '$Id: PML.pm,v 1.29 2000/07/31 20:39:50 pjones Exp $';
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 18 ▶use constant PML_V => 0; # pml variables
Subroutine BEGIN: called CC=1 SCAR=0.0
131 18 ▶use constant PML_LINE => 1; # current line number
Subroutine BEGIN: called CC=1 SCAR=0.0
132 18 ▶use constant PML_LINE_STR => 2; # line string
Subroutine BEGIN: called CC=1 SCAR=0.0
133 18 ▶use constant PML_TOKENS => 3; # tokens array
Subroutine BEGIN: called CC=1 SCAR=0.0
134 18 ▶use constant PML_TC => 4; # the token counter
Subroutine BEGIN: called CC=1 SCAR=0.0
135 18 ▶use constant PML_LINES => 5; # list of lines
Subroutine BEGIN: called CC=1 SCAR=0.0
136 18 ▶use constant PML_W => 6; # warnings flag
Subroutine BEGIN: called CC=1 SCAR=0.0
137 18 ▶use constant PML_PEEK => 7; # peek flag
Subroutine BEGIN: called CC=1 SCAR=0.0
138 18 ▶use constant PML_FILE => 8; # file name element
Subroutine BEGIN: called CC=1 SCAR=0.0
139 18 ▶use constant PML_MAGIC => 9; # use magic flag
Subroutine BEGIN: called CC=1 SCAR=0.0
140 18 ▶use constant PML_MAGIC_NEWLINE => 10; # magic newline flag
Subroutine BEGIN: called CC=1 SCAR=0.0
141 18 ▶use constant PML_MAGIC_TAB => 11; # magic tab flag
Subroutine BEGIN: called CC=1 SCAR=0.0
142 18 ▶use constant PML_COLLECTOR => 12; # collect the output from a execute
Subroutine BEGIN: called CC=1 SCAR=0.0
143 18 ▶use constant PML_MACROS => 13; # hash of macro tokens
Subroutine BEGIN: called CC=1 SCAR=0.0
144 18 ▶use constant PML_INCLUDES => 14; # hash of filenames for includes
Subroutine BEGIN: called CC=1 SCAR=0.0
145 18 ▶use constant PML_USE_STDERR => 15; # flag; allow errors to STDERR
Subroutine BEGIN: called CC=1 SCAR=0.0
146 18 ▶use constant PML_PARSE_AFTER => 16; # parse after flag
Subroutine BEGIN: called CC=1 SCAR=0.0
147 18 ▶use constant PML_RECURSIVE_MAX => 17; # max times to allow recurse
Subroutine BEGIN: called CC=1 SCAR=0.0
148 18 ▶use constant PML_RECURSIVE_COUNT => 18; # current number of recurse
Subroutine BEGIN: called CC=1 SCAR=0.0
149 18 ▶use constant PML_NEED_LIST => 19; # list of needed modules
Subroutine BEGIN: called CC=1 SCAR=0.0
150 18 ▶use constant PML_OBJ_DIR => 20; # dir to store object
Subroutine BEGIN: called CC=1 SCAR=0.0
151 18 ▶use constant PML_LOOP_COUNTERS => 21; # are we in a loop flags
Subroutine BEGIN: called CC=1 SCAR=0.0
152 18 ▶use constant PML_DIE_MESSAGE => 22; # message given durring a die
Subroutine BEGIN: called CC=1 SCAR=0.0
153 18 ▶use constant PML_PCALLBACKS => 23; # object specific parser callbacks
Subroutine BEGIN: called CC=1 SCAR=0.0
154 18 ▶use constant PML_TCALLBACKS => 24; # object specific token callbacks
Subroutine BEGIN: called CC=1 SCAR=0.0
155  
156 18 ▶use constant PML_TOKEN_ID => 0; # store the token id
Subroutine BEGIN: called CC=1 SCAR=0.0
157 18 ▶use constant PML_TOKEN_CONTEXT => 1; # the context that the token is called in
Subroutine BEGIN: called CC=1 SCAR=0.0
158 18 ▶use constant PML_TOKEN_FILE_LOC => 2; # arg; block; file
Subroutine BEGIN: called CC=1 SCAR=0.0
159 18 ▶use constant PML_TOKEN_LABEL => 3; # label name if we have one
Subroutine BEGIN: called CC=1 SCAR=0.0
160 18 ▶use constant PML_TOKEN_DATA => 4; # the actual token data
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 18 ▶use constant CONTEXT_SCALAR => 1; # scalar context
Subroutine BEGIN: called CC=1 SCAR=0.0
163 18 ▶use constant CONTEXT_LIST => 2; # list context
Subroutine BEGIN: called CC=1 SCAR=0.0
164  
165 18 ▶use constant FILE_LOC_FILE => 0; # token within file scope
Subroutine BEGIN: called CC=1 SCAR=0.0
166 18 ▶use constant FILE_LOC_ARG => 1; # token within arg list
Subroutine BEGIN: called CC=1 SCAR=0.0
167 18 ▶use constant FILE_LOC_BLOCK => 2; # token within block
Subroutine BEGIN: called CC=1 SCAR=0.0
168  
169 18 ▶use constant TOKEN_IF => 1; # if function token
Subroutine BEGIN: called CC=1 SCAR=0.0
170 18 ▶use constant TOKEN_NOT => 2; # unless function
Subroutine BEGIN: called CC=1 SCAR=0.0
171 18 ▶use constant TOKEN_EVAL => 3; # eval internal token
Subroutine BEGIN: called CC=1 SCAR=0.0
172 18 ▶use constant TOKEN_PERL => 4; # perl function token
Subroutine BEGIN: called CC=1 SCAR=0.0
173 18 ▶use constant TOKEN_SET => 5; # set function token
Subroutine BEGIN: called CC=1 SCAR=0.0
174 18 ▶use constant TOKEN_INCLUDE => 6; # include function token
Subroutine BEGIN: called CC=1 SCAR=0.0
175 18 ▶use constant TOKEN_MACRO => 7; # macro function token
Subroutine BEGIN: called CC=1 SCAR=0.0
176 18 ▶use constant TOKEN_VARIABLE => 8; # allows the expansion of a variable outside a string
Subroutine BEGIN: called CC=1 SCAR=0.0
177 18 ▶use constant TOKEN_FOREACH => 9; # foreach function token
Subroutine BEGIN: called CC=1 SCAR=0.0
178 18 ▶use constant TOKEN_WHILE => 10; # while and until loop token
Subroutine BEGIN: called CC=1 SCAR=0.0
179 18 ▶use constant TOKEN_SKIP => 11; # skip function
Subroutine BEGIN: called CC=1 SCAR=0.0
180 18 ▶use constant TOKEN_WRAP => 12; # wrap function
Subroutine BEGIN: called CC=1 SCAR=0.0
181 18 ▶use constant TOKEN_RIB => 13; # replace if blank function
Subroutine BEGIN: called CC=1 SCAR=0.0
182 18 ▶use constant TOKEN_MAGIC_MACRO => 14; # call a unknown macro
Subroutine BEGIN: called CC=1 SCAR=0.0
183 18 ▶use constant TOKEN_LOOP_INT => 15; # next, redo, last functions
Subroutine BEGIN: called CC=1 SCAR=0.0
184  
185 18 ▶use constant TOKEN_SET_SET => 1; # set sub tokens
Subroutine BEGIN: called CC=1 SCAR=0.0
186 18 ▶use constant TOKEN_SET_IF => 2; # |
Subroutine BEGIN: called CC=1 SCAR=0.0
187 18 ▶use constant TOKEN_SET_APPEND => 3; # |
Subroutine BEGIN: called CC=1 SCAR=0.0
188 18 ▶use constant TOKEN_SET_PREPEND => 4; # |
Subroutine BEGIN: called CC=1 SCAR=0.0
189 18 ▶use constant TOKEN_SET_CONCAT => 5; # |
Subroutine BEGIN: called CC=1 SCAR=0.0
190  
191 18 ▶use constant TOKEN_START_AVAL => 1001;# what token id to start at for others
Subroutine BEGIN: called CC=1 SCAR=0.0
192 18 ▶use constant ARG_BLOCK => 1; # function with arguments and a block
Subroutine BEGIN: called CC=1 SCAR=0.0
193 18 ▶use constant ARG_ONLY => 2; # function with only arguments, no block
Subroutine BEGIN: called CC=1 SCAR=0.0
194 18 ▶use constant BLOCK_ONLY => 3; # function with only a block, no arguments
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 18 ▶use constant G_MARKER => '@';
Subroutine BEGIN: called CC=1 SCAR=0.0
197 18 ▶use constant G_RE_IF => qr/^\@(elsif|else)/o;
Subroutine BEGIN: called CC=1 SCAR=0.0
198 ################################################################################
199 #
200 # Global Variables and Default Settings
201 #
202 ################################################################################
203 18 ▶use vars qw($VERSION $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
204 18 $VERSION = '0.4.1';
205  
206 18 my %function_arg_block = (
207 'if' => \&parse_if,
208 'unless' => [\&parse_if, 1],
209 'macro' => \&parse_macro,
210 'foreach' => \&parse_foreach,
211 'while' => \&parse_while,
212 'until' => [\&parse_while, 1],
213 'wrap' => \&parse_wrap,
214 'rib' => \&parse_rib,
215 );
216  
217 18 my %function_arg_only = (
218 'set' => [\&parse_set, TOKEN_SET_SET],
219 'setif' => [\&parse_set, TOKEN_SET_IF],
220 'append' => [\&parse_set, TOKEN_SET_APPEND],
221 'prepend' => [\&parse_set, TOKEN_SET_PREPEND],
222 'concat' => [\&parse_set, TOKEN_SET_CONCAT],
223 'include' => \&parse_include,
224 'warning' => \&parse_warning,
225 'need' => \&parse_need,
226 'next' => [\&parse_loop_int, 'next'],
227 'redo' => [\&parse_loop_int, 'redo'],
228 'last' => [\&parse_loop_int, 'last'],
229 );
230  
231 18 my %function_block_only = (
232 );
233  
234 18 my %function_block_no_parse = (
235 'perl' => \&parse_perl,
236 'skip' => \&parse_skip,
237 );
238  
239 18 my %allow_remove_tabs = (
240 'set' => 1,
241 'setif' => 1,
242 'append' => 1,
243 'prepend' => 1,
244 'concat' => 1,
245 'include' => 1,
246 'need' => 1,
247 'if' => 1,
248 'unless' => 1,
249 'macro' => 1,
250 'foreach' => 1,
251 'while' => 1,
252 'until' => 1,
253 'rib' => 1,
254 );
255  
256 18 my %allow_remove_newline = (
257 'macro' => 1,
258 'set' => 1,
259 'setif' => 1,
260 'append' => 1,
261 'prepend' => 1,
262 'concat' => 1,
263 'include' => 1,
264 'need' => 1,
265 'if' => 1,
266 'unless' => 1,
267 'while' => 1,
268 'until' => 1,
269 'skip' => 1,
270 'perl' => 1,
271 'rib' => 1,
272 'wrap' => 1,
273 );
274  
275 18 my %loop_functions = (
276 'foreach' => 1,
277 'while' => 1,
278 'until' => 1,
279 );
280  
281 18 my %tokens = (
282 TOKEN_IF() => \&token_if,
283 TOKEN_NOT() => \&token_not,
284 TOKEN_EVAL() => \&token_eval,
285 TOKEN_PERL() => \&token_perl,
286 TOKEN_SET() => \&token_set,
287 TOKEN_INCLUDE() => \&token_include,
288 TOKEN_MACRO() => \&token_macro,
289 TOKEN_VARIABLE() => \&token_variable,
290 TOKEN_FOREACH() => \&token_foreach,
291 TOKEN_WHILE() => \&token_while,
292 TOKEN_SKIP() => \&token_skip,
293 TOKEN_WRAP() => \&token_wrap,
294 TOKEN_RIB() => \&token_rib,
295 TOKEN_MAGIC_MACRO() => \&token_magic_macro,
296 TOKEN_LOOP_INT() => \&token_loop_int,
297 );
298  
299 18 my @invalid_functions;
300 18 my $next_token = TOKEN_START_AVAL;
301  
302 18 my @inc = (
303 '.',
304 '..',
305 '../include',
306 '/usr/local/share/pml',
307 '/usr/local/pml/include',
308 );
309  
310 18 my $RE_NAME = qr/(?:(?:[A-Za-z_]|\$\{)(?:\w|\$|(?<=\$)\{|\}|::|\.|-|[\[\]])*)/o;
311 18 my $RE_VAR = qr/(?:[A-Za-z_\$](?:\w|::|\.|-|\[|\]|\{|\}|\$)*)|\./o;
312 18 my $RE_VAR_TEST = qr/([^\$]*)(?<!\\)\$(?=\{)/o;
313 18 my $RE_FUNCTION = '^([^' . G_MARKER() . ']*)(?<!\\\\)' . G_MARKER() . "($RE_NAME)";
314 18 my $RE_LOOP_INT = qr/^(next|last|redo):(\w+)?/o;
315 18 my $RE_LABEL = qr/([A-Z0-9]+):\s*$/o;
316  
317 18 ▶use vars qw($DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
318 18 $DEBUG = 0;
319 ################################################################################
320 #------------------------------------------------------------------------------#
321  
322 =pod
323  
324 =head2 METHOD new
325  
326  
327 Arguments:
328 1) Class or PML Object to clone
329 2) Hash Reference (Optional)
330  
331 Returns:
332 1) A PML Object
333  
334 Description:
335 new creates a new PML Object and returns the object
336 to the caller. You can optionaly pass in a hash
337 refernece, where the keys are PML variables to set
338 and the values are the values to set those variables
339 to.
340  
341 =cut
342  
343 #------------------------------------------------------------------------------#
344 ################################################################################
345 sub new
346 333 ▶{
Subroutine new: called CC=9 SCAR=22.0
Pod documented
347 333 my $ref = shift;
348 333 ▶ my $class = ref($ref) || $ref;
Condition66%2/3
ref $ref || $ref
l!l&&r!l&&!r
23310
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table66%2/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
349 333 my $v = shift;
350 333 my $self = [];
351
352 # check to see if the is a PML::Token object
353 333 ▶ if ($class eq 'PML::Token') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "PML::Token") 311 22 333
354 311 my $self = [];
355 311 $self->[PML_TOKEN_ID] = undef;
356 311 $self->[PML_TOKEN_CONTEXT] = CONTEXT_SCALAR;
357 311 $self->[PML_TOKEN_FILE_LOC] = FILE_LOC_FILE;
358 311 $self->[PML_TOKEN_DATA] = undef;
359
360 311 ▶ _token_id($self, $v) if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 311 0 311
361 311 return bless $self, $class;
362 }
363
364 22 ▶ if (not ref $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $ref) { } 20 2 22
365 # create new PML Object and set some variables
366 20 $self->[PML_V] = {PMLVERSION => $VERSION};
367 20 $self->[PML_W] = 0;
368 20 $self->[PML_LINE] = 0;
369 20 $self->[PML_LINE_STR] = 'on Line 1';
370 20 $self->[PML_TOKENS] = [];
371 20 $self->[PML_PEEK] = 0;
372 20 $self->[PML_FILE] = 'input stream';
373 20 $self->[PML_MAGIC] = 1;
374 20 $self->[PML_MAGIC_NEWLINE] = 1;
375 20 $self->[PML_MAGIC_TAB] = 0;
376 20 $self->[PML_COLLECTOR] = '';
377 20 $self->[PML_MACROS] = {};
378 20 $self->[PML_INCLUDES] = {};
379 20 $self->[PML_USE_STDERR] = 1;
380 20 $self->[PML_PARSE_AFTER] = 0;
381 20 $self->[PML_RECURSIVE_MAX] = 1000;
382 20 $self->[PML_RECURSIVE_COUNT] = 0;
383 20 $self->[PML_NEED_LIST] = [];
384 20 $self->[PML_OBJ_DIR] = '/tmp';
385 20 $self->[PML_LOOP_COUNTERS] = {};
386 20 $self->[PML_DIE_MESSAGE] = '';
387 20 $self->[PML_TCALLBACKS] = {};
388 20 $self->[PML_PCALLBACKS] = {
389 'function_arg_block' => {},
390 'function_arg_only' => {},
391 'function_block_only' => {},
392 'function_block_no_parse' => {},
393 };
394  
395 # Set up the loop counters
396 20 $self->[PML_LOOP_COUNTERS]{$_} = 0 foreach keys %loop_functions;
397 } else { # we need to clone an existsing object
398 2 ▶ eval {require Storable} or # make sure Storable is avaliable
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Storable } } or croak("can't call new as a method unless you install the Storable module") 2 0 2
399 croak "can't call new as a method unless you install the Storable module";
400  
401 2 $self->[PML_V] = Storable::dclone($ref->[PML_V]);
402 2 $self->[PML_W] = $ref->[PML_W];
403 2 $self->[PML_LINE] = $ref->[PML_LINE];
404 2 $self->[PML_LINE_STR] = $ref->[PML_LINE_STR];
405 2 $self->[PML_TOKENS] = Storable::dclone($ref->[PML_TOKENS]);
406 2 $self->[PML_PEEK] = $ref->[PML_PEEK];
407 2 $self->[PML_FILE] = $ref->[PML_FILE];
408 2 $self->[PML_MAGIC] = $ref->[PML_MAGIC];
409 2 $self->[PML_MAGIC_NEWLINE] = $ref->[PML_MAGIC_NEWLINE];
410 2 $self->[PML_MAGIC_TAB] = $ref->[PML_MAGIC_TAB];
411 2 $self->[PML_COLLECTOR] = $ref->[PML_COLLECTOR];
412 2 $self->[PML_MACROS] = Storable::dclone($ref->[PML_MACROS]);
413 2 $self->[PML_INCLUDES] = Storable::dclone($ref->[PML_INCLUDES]);
414 2 $self->[PML_USE_STDERR] = $ref->[PML_USE_STDERR];
415 2 $self->[PML_PARSE_AFTER] = $ref->[PML_PARSE_AFTER];
416 2 $self->[PML_RECURSIVE_MAX] = $ref->[PML_RECURSIVE_MAX];
417 2 $self->[PML_RECURSIVE_COUNT]= $ref->[PML_RECURSIVE_COUNT];
418 2 $self->[PML_NEED_LIST] = Storable::dclone($ref->[PML_NEED_LIST]);
419 2 $self->[PML_OBJ_DIR] = $ref->[PML_OBJ_DIR];
420 2 $self->[PML_LOOP_COUNTERS] = Storable::dclone($ref->[PML_LOOP_COUNTERS]);
421 2 $self->[PML_DIE_MESSAGE] = $ref->[PML_DIE_MESSAGE];
422 2 $self->[PML_TCALLBACKS] = {%{$ref->[PML_TCALLBACKS]}};
423 2 $self->[PML_PCALLBACKS] = {};
424
425 # clone the callback holders
426 2 foreach my $key (keys %{$ref->[PML_PCALLBACKS]}) {
427 8 $self->[PML_PCALLBACKS]{$key} = {%{$ref->[PML_PCALLBACKS]{$key}}};
428 };
429 }
430  
431 # Set some other variables if passed into this sub
432 22 ▶ %{$self->[PML_V]} = (%{$self->[PML_V]}, %$v) if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 1 21 22
433
434 # Bless and return this new object
435 22 bless $self, $class;
436 } # <-- End new -->
437 ################################################################################
438 #
439 # ==== ready ==== ##############################################################
440 #
441 # Arguments:
442 # 1) A PML Object
443 # 2) A String (filename) or A reference to an array
444 #
445 # Returns:
446 # None
447 #
448 # Description:
449 # Gets the PML Object ready to parse
450 #
451 ################################################################################
452 sub ready
453 19 ▶{
Subroutine ready: called CC=5 SCAR=16.6
Pod undocumented
454 19 my ($self, $x) = @_;
455
456 #
457 # check the arguments
458 #
459 19 ▶ croak("Usage: ready(pml_object, lines_string|lines_arrayref)")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $x 0 19 19
Condition33%1/3
defined $self and defined $x
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $self and defined $x
defined $self defined $x
Truth table33%1/3
A and B
A= defined $selfB= defined $x
ABresult
0X0
100
111
460 unless defined $self and defined $x;
461
462 #
463 # setup the lines array ref
464 #
465 19 ▶ if ((ref $x) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x eq 'ARRAY') { } 18 1 19
466 {
467 18 $self->[PML_LINES] = $x;
468 }
469 else
470 {
471 1 ▶ open(SOURCE, $x) || die "cannot open file \"$x\": $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open SOURCE, $x or die qq[cannot open file "$x": $!\n] 1 0 1
472 1 @{$self->[PML_LINES]} = <SOURCE>;
473 1 close SOURCE;
474 1 $self->[PML_FILE] = $x;
475 }
476 } # <-- End ready -->
477 ################################################################################
478 #------------------------------------------------------------------------------#
479  
480 =pod
481  
482 =head2 METHOD parse
483  
484  
485 Arguments:
486 1) PML Object
487 2) Filename or a reference to an array of lines
488  
489 Returns:
490 1) True if parse was successful
491  
492 Description:
493 parse will parse the file or array that you give
494 it. If there is an error, such as a syntax error,
495 parse will throw an exception via die. Therefore
496 if you want to catch the exception you should wrap
497 the call to parse in an eval block and check $@.
498 If $@ is true there was and error and the error
499 message can be found in $@.
500  
501 =cut
502  
503 #------------------------------------------------------------------------------#
504 ################################################################################
505 sub parse
506 19 ▶{
Subroutine parse: called CC=14 SCAR=30.0
Pod documented
507 19 my ($self, $x) = @_;
508 19 my ($cwd);
509
510 # check the arguments
511 19 ▶ croak("Usage: parse(pml_object, lines_string|lines_arrayref)")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $x 0 19 19
Condition33%1/3
defined $self and defined $x
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $self and defined $x
defined $self defined $x
Truth table33%1/3
A and B
A= defined $selfB= defined $x
ABresult
0X0
100
111
512 unless defined $self and defined $x;
513
514 # call ready to prep the pml object
515 19 $self->ready($x);
516
517
518 # if we were given the filename to parse then chdir
519 # to where that file lives before we parse it
520 19 $cwd = cwd;
521
522 19 ▶ if (not ref $x) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $x) 1 18 19
523 1 my $dir = dirname $x;
524
525 1 ▶ unless (chdir $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (PML::chdir($dir)) 0 1 1
526 0 print STDERR "A error occured while trying to change directroies to parse the file \"$x\": $!\n";
527 0 die "$!\n";
528 }
529 }
530
531 # now parse all the lines
532 19 my ($line, @tokens);
533  
534 19 while (1) {
535 176 ▶ $line = $self->next_line unless defined $line and length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and length $line 158 18 176
Condition100%3/3
defined $line and length $line
!ll&&!rl&&r
1913918
MC/DC100%2/2
defined $line and length $line
defined $line length $line
Truth table100%3/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
536 176 ▶ defined $line or last;
Branch: 1 branch
BranchTrueFalseTotal
defined $line or last 158 18 176
537
538 158 ▶ if ($self->[PML_PARSE_AFTER]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[16]) 0 158 158
539 0 ▶ if ($line =~ $self->[PML_PARSE_AFTER]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$self->[16]/) 0 0 0
540 0 $self->[PML_PARSE_AFTER] = 0;
541 }
542
543 0 $line = '';
544 0 next;
545 }
546
547 158 @tokens = $self->parse_one_line(\$line);
548 157 ▶ push(@{$self->[PML_TOKENS]}, @tokens) if @tokens;
Branch: 1 branch
BranchTrueFalseTotal
if @tokens 149 8 157
549 }
550
551 18 foreach my $invalid_function (@invalid_functions) {
552 2 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->[13]{$invalid_function->[0]} and defined $self->[13]{$invalid_function->[0]}) 0 2 2
Condition33%1/3
exists $self->[13]{$invalid_function->[0]} and defined $self->[13]{$invalid_function->[0]}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $self->[13]{$invalid_function->[0]} and defined $self->[13]{$invalid_function->[0]}
exists $self->[13]{$invalid_function->[0]} defined $self->[13]{$invalid_function->[0]}
Truth table33%1/3
A and B
A= exists $self->[13]{$invalid_function->[0]}B= defined $self->[13]{$invalid_function->[0]}
ABresult
0X0
100
111
553 exists $self->[PML_MACROS]{$invalid_function->[0]}
554 and defined $self->[PML_MACROS]{$invalid_function->[0]}
555 ) {
556 0 $self->error_syntax("$invalid_function->[1], the macro or function \"$invalid_function->[0]\" is not defined.");
557 }
558 }
559
560 # now that we are done parsing we can
561 # move back to the dir where we started
562 18 chdir $cwd;
563  
564 18 return 1;
565 } # <-- End parse -->
566 ################################################################################
567 #------------------------------------------------------------------------------#
568  
569 =pod
570  
571 =head2 METHOD execute
572  
573  
574 Arguments:
575 1) PML Object
576 2) A Hash Reference (Optional)
577  
578 Returns:
579 1) The text in the file after processing it
580  
581 Description:
582 execute will process the file and return the
583 post-processed text. You can optionaly pass in a
584 reference to a hash, where the keys are PML variables
585 to set and the values are the value to set them
586 to. This is a good way so talk to your text file.
587  
588 You can call execute as many times as you wish.
589 Each call will start afresh at the top of the parsed
590 file.
591  
592 =cut
593  
594 #------------------------------------------------------------------------------#
595 ################################################################################
596 sub execute
597 18 ▶{
Subroutine execute: called CC=11 SCAR=32.6
Pod documented
598 18 my ($self, $v) = @_;
599 18 my ($tmp);
600
601 #
602 # check arguments
603 #
604 18 ▶ croak("Usage: execute(pml_object, hash_ref_optional)") unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 18 18
605
606 #
607 # make sure that there are tokens
608 #
609 18 ▶ unless ($self->[PML_TOKENS])
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[3]) 0 18 18
610 {
611 0 croak("There were no tokens to process, maybe you did not call parse or maybe the file was empty");
612 }
613
614 #
615 # Clean out the collector if we need to
616 #
617 18 undef $self->[PML_COLLECTOR];
618
619 #
620 # set any variables
621 #
622 18 $self->[PML_V]{$_} = $v->{$_} foreach keys %$v;
623
624 #
625 # set some default values
626 #
627 18 $self->[PML_TC] = 0;
628
629 #
630 # now walk the token list and execute tokens
631 #
632 18 ▶ while ($#{$self->[PML_TOKENS]} >= $self->[PML_TC])
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self[3];} >= $self->[4]) 148 18 166
633 {
634 148 $tmp = $self->tokens_execute (
635 $self->[PML_TOKENS][$self->[PML_TC]]
636 );
637  
638 148 ▶ $self->[PML_COLLECTOR] .= $tmp if defined $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tmp 148 0 148
639
640 # check to see if it died
641 148 ▶ if ($self->[PML_DIE_MESSAGE]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22]) 0 148 148
642 # see if it is ours
643 0 ▶ if ($self->[PML_DIE_MESSAGE] =~ /$RE_LOOP_INT/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22] =~ /$RE_LOOP_INT/o) { } 0 0 0
644 # do stuff
645 0 ▶ if ($1 eq 'next') {
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq 'next') { } 0 0 0
elsif ($1 eq 'redo') { } 0 0 0
elsif ($1 eq 'last') { } 0 0 0
646 0 $self->[PML_TC]++;
647 0 next;
648 } elsif ($1 eq 'redo') {
649 0 redo;
650 } elsif ($1 eq 'last') {
651 0 last;
652 }
653 } else { # it's not ours
654 0 die $self->[PML_DIE_MESSAGE];
655 }
656 }
657
658 148 $self->[PML_TC]++;
659 }
660
661 18 return $self->[PML_COLLECTOR];
662 } # <-- End execute -->
663 ################################################################################
664 #------------------------------------------------------------------------------#
665  
666 =pod
667  
668 =head2 METHOD v
669  
670  
671 Arguments:
672 1) PML Object
673  
674 -- or --
675
676 2) Variable Name
677  
678 -- or --
679  
680 2) Variable Name
681 3) New Value
682  
683 -- or --
684  
685 2) Hash Reference
686  
687 Returns:
688 1) Depends on Arguments, see below.
689  
690 Description:
691 The v method allows you to get and set PML variables.
692 There are a few different ways to use v, and we
693 will cover them all.
694  
695 Arguments:
696 1) PML Object
697  
698 In this case, you call v with only the object, no
699 arguments. This will return an array of variable
700 names. This is so you can see what variables are
701 defined.
702  
703 Arguments:
704 1) PML Object
705 2) Variable Name
706  
707 This time you give a name of a variable. The v
708 method will return the current value of that
709 variable, or undef if it is not set.
710  
711 Arguments:
712 1) PML Object
713 2) Variable Name
714 3) Value
715  
716 Here, you give a variable name and the value to
717 set it to. The v method will then set the give
718 variable to the value you gave it. It should return
719 the same value.
720  
721 Arguments:
722 1) PML Object
723 2) Hash Reference
724  
725 To limit method calls, you can give a hash reference
726 where the keys are the variable to set and the
727 values are the value to set those variables to.
728 Returns 1.
729  
730 =cut
731  
732 #------------------------------------------------------------------------------#
733 ################################################################################
734 sub v
735 2 ▶{
Subroutine v: called CC=6 SCAR=24.7
Pod documented
736 2 my ($self, $variable, $value) = @_;
737
738 2 ▶ unless ($self) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self) 0 2 2
739 0 carp "Usage: v(PML, [Variable, [Value]])";
740 0 return undef;
741 }
742
743 2 ▶ unless ($variable) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($variable) 0 2 2
744 0 return %{$self->[PML_V]};
745 }
746  
747 2 ▶ if (ref $variable eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $variable eq "HASH") 0 2 2
748 0 foreach my $key (keys %$variable) {
749 0 $self->[PML_V]{$key} = $variable->{$key};
750 }
751 0 return 1;
752 }
753
754 2 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 2 2
755 0 $self->[PML_V]{$variable} = $value;
756 }
757
758 2 return $self->[PML_V]{$variable};
759 } # <-- End v -->
760 ################################################################################
761 #------------------------------------------------------------------------------#
762  
763 =pod
764  
765 =head2 METHOD parse_after
766  
767  
768 Arguments:
769 1) PML Object
770 2) Regular Expression String or Object
771  
772 Returns:
773 1) Nothing
774  
775 Description:
776 Used before the call to parse, this method will
777 effect when parsing will start. When you call the
778 parse method, it will search for the given regex,
779 when that regex matches, parsing will begin on the
780 NEXT line.
781  
782 =cut
783  
784 #------------------------------------------------------------------------------#
785 ################################################################################
786 sub parse_after
787 0 ▶{
Subroutine parse_after: not called CC=2 SCAR=17.9
Pod documented
788 0 my ($self, $regex) = @_;
789
790 0 ▶ $regex = qr/$regex/ unless ref $regex eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $regex eq "Regexp" 0 0 0
791 0 $self->[PML_PARSE_AFTER] = $regex;
792 } # <-- End parse_after -->
793 ################################################################################
794 #------------------------------------------------------------------------------#
795  
796 =pod
797  
798 =head2 CLASS METHOD register
799  
800  
801 Arguments:
802 1) Class ie PML->register(...)
803 2) A Hash, keys are described below
804  
805 Returns:
806 1) An ID number to refer to your token
807  
808 Description:
809 The register function is used to extend the PML
810 syntax. You register a callback for a new PML
811 function. When parsing the text, PML will call your
812 parser-callback to assist parsing. When executing,
813 PML will call your token-callback to process the
814 token created by your parser-callback.
815  
816 Here is what you should pass to register:
817  
818 parse => A callback. Defaults to using the
819 builtin autoparser
820 token => A callback. You must give this.
821 name => The name of the new PML function to add.
822 type => See Types below
823
824 Callbacks:
825  
826 A callback is a reference to a subroutine like this:
827 \&myfunc -- or -- sub{}
828  
829 It can also be a reference to an array,
830 where the first element is a reference to
831 a subroutine and the remaining elements
832 are passed to the subroutine as arguemnts
833 after the standard arguments.
834  
835 Types:
836  
837 The types are constants in PML.pm.
838  
839 PML->ARG_ONLY This means that your new
840 function will only take
841 arguments, just like the
842 builtin @set function.
843  
844 PML->BLOCK_ONLY This means that your new
845 function only takes a block
846 just like the builtin @perl
847 function.
848  
849 PML->ARG_BLOCK This means that your new
850 function takes arguments
851 and a block, just like the
852 builtin @if function.
853  
854 =cut
855  
856 #------------------------------------------------------------------------------#
857 ################################################################################
858 sub register
859 8 ▶{
Subroutine register: called CC=17 SCAR=31.6
Pod documented
860 8 my $ref = shift;
861 8 my $table;
862 8 my %options = (
863 parse => undef,
864 token => undef,
865 name => undef,
866 type => ARG_ONLY,
867 id => undef,
868
869 @_,
870 );
871
872 8 ▶ unless (defined $options{token} and defined $options{name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{"token"} and defined $options{"name"}) 0 8 8
Condition33%1/3
defined $options{"token"} and defined $options{"name"}
!ll&&!rl&&r
008
MC/DC0%0/2
defined $options{"token"} and defined $options{"name"}
defined $options{"token"} defined $options{"name"}
Truth table33%1/3
A and B
A= defined $options{"token"}B= defined $options{"name"}
ABresult
0X0
100
111
873 0 croak "You must, at a minimum, give token sub and name arguments to PML->register";
874 }
875
876 8 foreach ('token', 'parse') {
877 16 ▶ next unless defined $options{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{$_} 8 8 16
878 8 ▶ unless (ref($options{$_}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $options{$_} eq "CODE") 0 8 8
879 0 ▶ unless (ref($options{$_}) eq 'ARRAY' and ref($options{$_}->[0]) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $options{$_} eq "ARRAY" and ref $options{$_}[0] eq "CODE") 0 0 0
Condition0%0/3
ref $options{$_} eq "ARRAY" and ref $options{$_}[0] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $options{$_} eq "ARRAY" and ref $options{$_}[0] eq "CODE"
ref $options{$_} eq "ARRAY" ref $options{$_}[0] eq "CODE"
Truth table0%0/3
A and B
A= ref $options{$_} eq "ARRAY"B= ref $options{$_}[0] eq "CODE"
ABresult
0X0
100
111
880 0 croak "callback must be a ref to a sub or a ref to an array who's first elemnt is a ref to a sub";
881 }
882 }
883 }
884
885 8 ▶ if ($options{type} == ARG_BLOCK) {
Branch: 3 branches
BranchTrueFalseTotal
if ($options{'type'} == 1) { } 2 6 8
elsif ($options{'type'} == 2) { } 4 2 6
elsif ($options{'type'} == 3) { } 2 0 2
886 2 ▶ if (ref $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) { } 1 1 2
887 1 $table = $ref->[PML_PCALLBACKS]{'function_arg_block'};
888 } else {
889 1 $table = \%function_arg_block;
890 }
891 } elsif ($options{type} == ARG_ONLY) {
892 4 ▶ if (ref $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) { } 1 3 4
893 1 $table = $ref->[PML_PCALLBACKS]{'function_arg_only'};
894 } else {
895 3 $table = \%function_arg_only;
896 }
897 } elsif ($options{type} == BLOCK_ONLY) {
898 2 ▶ if (ref $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) { } 1 1 2
899 1 $table = $ref->[PML_PCALLBACKS]{'function_block_only'};
900 } else {
901 1 $table = \%function_block_only;
902 }
903 } else {
904 0 croak "Bad type argument to register, what is type \"$options{type}\"?";
905 }
906
907 8 ▶ $options{id} ||= $next_token++;
Condition33%1/3
$options{"id"} ||= $next_token++
l!l&&r!l&&!r
080
MC/DC0%0/2
$options{"id"} ||= $next_token++
$options{"id"} $next_token++
Truth table33%1/3
A ||= B
A= $options{"id"}B= $next_token++
ABresult
1X1
011
000
908 8 ▶ if (ref $ref) { # this is a method call
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) { } 3 5 8
909 3 $ref->[PML_TCALLBACKS]{$options{id}} = $options{token};
910 } else { # this is a class call
911 5 $tokens{$options{id}} = $options{token};
912 }
913 8 ▶ $table->{$options{name}} = $options{parse} || [\&auto_parse, \%options];
Condition50%1/2
$options{'parse'} || [\&PML::auto_parse, \%options]
l!l
08
MC/DC0%0/1
$options{'parse'} || [\&PML::auto_parse, \%options]
$options{'parse'}
Truth table50%1/2
A
A= $options{'parse'}
Aresult
11
00
914
915 8 return $options{id};
916 } # <-- End register -->
917 ################################################################################
918 #
919 # ==== execute_callback ==== ###################################################
920 #
921 # Arguments:
922 # 1) A callback Object
923 # 2) All the args to send to the callback
924 #
925 # Returns:
926 # What ever the callback returns
927 #
928 # Description:
929 # Calls the callback
930 #
931 ################################################################################
932 sub execute_callback
933 418 ▶{
Subroutine execute_callback: called CC=4 SCAR=17.9
Pod undocumented
934 418 my ($callback, @args) = @_;
935
936 418 ▶ if (ref($callback) eq 'CODE')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $callback eq 'CODE') { } 382 36 418
elsif (ref $callback eq 'ARRAY' and ref $callback->[0] eq 'CODE') { } 36 0 36
937 {
938 382 return $callback->(@args);
939 }
940 ▶ elsif (ref($callback) eq 'ARRAY' and ref($callback->[0]) eq 'CODE')
Condition33%1/3
ref $callback eq "ARRAY" and ref $callback->[0] eq "CODE"
!ll&&!rl&&r
0036
MC/DC0%0/2
ref $callback eq "ARRAY" and ref $callback->[0] eq "CODE"
ref $callback eq "ARRAY" ref $callback->[0] eq "CODE"
Truth table33%1/3
A and B
A= ref $callback eq "ARRAY"B= ref $callback->[0] eq "CODE"
ABresult
0X0
100
111
941 {
942 36 return $callback->[0]->(@args, @$callback[1 .. $#{$callback}]);
943 }
944 else
945 {
946 0 print STDERR 'Internal error, bad callback object ';
947 0 print STDERR "\"ref(callback) = ";
948 0 print STDERR scalar ref($callback);
949 0 print STDERR "\", sorry but you found a bug. ";
950 0 print STDERR caller, "\n";
951 0 exit 1;
952 }
953 } # <-- End execute_callback -->
954 ################################################################################
955 #------------------------------------------------------------------------------#
956  
957 =pod
958  
959 =head2 METHOD warning
960  
961  
962 Arguments:
963 1) PML Object
964 2) Boolean Flag (Optional)
965  
966 Returns:
967 1) Current Warning Flag
968  
969 Description:
970 The warning method will set the warning flag to
971 the one given, if one was given. It always returns
972 the current value. If the flag is true, PML will
973 print warnings to STDERR.
974  
975 =cut
976  
977 #------------------------------------------------------------------------------#
978 ################################################################################
979 sub warning
980 2 ▶{
Subroutine warning: called CC=3 SCAR=11.4
Pod documented
981 2 my ($self, $flag) = @_;
982
983 2 ▶ croak "Usage: warning(pml_object, [flag])" unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 2 2
984
985 2 ▶ $self->[PML_W] = $flag if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 2 0 2
986 2 return $self->[PML_W];
987 } # <-- End warning -->
988 ################################################################################
989 #------------------------------------------------------------------------------#
990  
991 =pod
992  
993 =head2 METHOD use_stderr
994  
995 Arguments:
996 1) PML Object
997 2) True to allow use of stderr, false to disallow
998  
999 Returns:
1000 1) Nothing
1001  
1002 Description:
1003 Sets the use_stderr flag for this object
1004  
1005 =cut
1006  
1007 #------------------------------------------------------------------------------#
1008 ################################################################################
1009 sub use_stderr ($$)
1010 1 ▶{
Subroutine use_stderr: called CC=1 SCAR=0.0
Pod documented
1011 1 my ($self, $flag) = @_;
1012 1 $self->[PML_USE_STDERR] = $flag;
1013 } #<-- End: use_stderr -->
1014 ################################################################################
1015 #
1016 # ==== tokens_execute ==== #####################################################
1017 #
1018 # Arguments:
1019 # 1) A PML Object
1020 # 2) A reference to an array of tokens
1021 #
1022 # Returns:
1023 # The results of the tokens
1024 #
1025 # Description:
1026 # runs through the tokens and returns the results
1027 #
1028 ################################################################################
1029 sub tokens_execute
1030 329 ▶{
Subroutine tokens_execute: called CC=13 SCAR=26.0
Pod undocumented
1031 329 my ($self, @tokens) = @_;
1032 329 my ($token, @rv, $callback);
1033
1034 # check arguments
1035 329 ▶ croak("Usage: tokens_execute(pml_object, tokens)")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 329 329
1036 unless defined $self;
1037
1038 # reset the die message
1039 329 $self->[PML_DIE_MESSAGE] = '';
1040
1041 # return an empty list if there are no tokens
1042 329 ▶ return () unless @tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 329 329
1043
1044 # check to see if there is only one token and
1045 # if that token is realy a array ref to a token
1046 329 ▶ if (@tokens == 1 and ref($tokens[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens == 1 and ref $tokens[0] eq "ARRAY") 65 264 329
Condition100%3/3
@tokens == 1 and ref $tokens[0] eq "ARRAY"
!ll&&!rl&&r
326165
MC/DC100%2/2
@tokens == 1 and ref $tokens[0] eq "ARRAY"
@tokens == 1 ref $tokens[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @tokens == 1B= ref $tokens[0] eq "ARRAY"
ABresult
0X0
100
111
1047 65 @tokens = @{$tokens[0]};
1048 }
1049
1050 # process the tokens
1051 329 foreach $token (@tokens) {
1052 # skip this token unless it is defined
1053 346 ▶ next unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 1 345 346
1054
1055 # check for an array of tokens
1056 345 ▶ if (ref $token eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token eq "ARRAY") 0 345 345
1057 0 push @rv, scalar $self->tokens_execute(@$token);
1058 0 next;
1059 }
1060
1061 # if this is not a token just add it to the result
1062 345 ▶ unless (ref $token eq 'PML::Token') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $token eq "PML::Token") 2 343 345
1063 2 push @rv, $token;
1064 2 next;
1065 }
1066
1067 # check to see if the token exists
1068 343 ▶ if (exists $self->[PML_TCALLBACKS]{$token->id}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->[24]{$token->id}) { } 3 340 343
elsif (exists $tokens{$token->id}) { } 340 0 340
1069 3 $callback = $self->[PML_TCALLBACKS]{$token->id};
1070 } elsif (exists $tokens{$token->id}) {
1071 340 $callback = $tokens{$token->id};
1072 } else {
1073 0 die("Hmmm... bad token id '$token->[0]', you found a bug in PML");
1074 }
1075
1076 # we wrap the next line in an eval because
1077 # if we come across a @next, @redo or @last
1078 # they will call die
1079 343 eval {
1080 # call the token and record it's return value
1081 343 push @rv, execute_callback($callback, $self, $token);
1082 };
1083
1084 # check to see if we died
1085 343 ▶ if ($@) {$self->[PML_DIE_MESSAGE]=$@; last}
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 342 343
1086 }
1087
1088 # why in the heck am i getting
1089 # `Use of uninitialized value at ...'
1090 329 local ($^W)=0; #FIXME
1091
1092 # now check the calling context
1093 329 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 67 262 329
1094 67 return @rv;
1095 } else {
1096 262 return join '', @rv;
1097 }
1098 } # <-- End tokens_execute -->
1099 ################################################################################
1100 #
1101 # ==== parse_one_line ==== #####################################################
1102 #
1103 # Arguments:
1104 # 1) A PML Object
1105 # 2) A line of text
1106 # 3) A ref to an array of lines (Optional, default is $self->[PML_LINES])
1107 #
1108 # Returns:
1109 # A List of PML_TOKENS to add to the token array
1110 #
1111 # Description:
1112 # Parses the line, getting more lines from $self->[PML_LINES] if necessary
1113 # then returns entries to the tokens array
1114 #
1115 ################################################################################
1116 sub parse_one_line
1117 203 ▶{
Subroutine parse_one_line: called CC=44 SCAR=39.5
Pod undocumented
1118 203 my ($self, $line_ref, $lines) = @_;
1119 203 my (@tokens, $func, @arguments, @block);
1120 203 my ($token, $pre_text, $label, $callback);
1121
1122 # check arguments
1123 203 ▶ croak("Usage: parse_one_line(pml_object, lines)") unless defined $self and defined $line_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $line_ref 0 203 203
Condition33%1/3
defined $self and defined $line_ref
!ll&&!rl&&r
00203
MC/DC0%0/2
defined $self and defined $line_ref
defined $self defined $line_ref
Truth table33%1/3
A and B
A= defined $selfB= defined $line_ref
ABresult
0X0
100
111
1124 203 ▶ croak("PML object is missing the lines array") if not $lines and not defined $self->[PML_LINES];
Branch: 1 branch
BranchTrueFalseTotal
unless $lines or defined $self->[5] 0 203 203
Condition66%2/3
$lines or defined $self->[5]
l!l&&r!l&&!r
451580
MC/DC0%0/2
$lines or defined $self->[5]
$lines defined $self->[5]
Truth table66%2/3
A or B
A= $linesB= defined $self->[5]
ABresult
1X1
011
000
1125
1126 # set lines to self PML_LINES if not already set
1127 203 ▶ $lines ||= $self->[PML_LINES];
Condition66%2/3
$lines ||= $self->[5]
l!l&&r!l&&!r
451580
MC/DC0%0/2
$lines ||= $self->[5]
$lines $self->[5]
Truth table66%2/3
A ||= B
A= $linesB= $self->[5]
ABresult
1X1
011
000
1128
1129 # now check to see if there is a call to a built-in function
1130 # or a call to a macro
1131 203 ▶ if ($$line_ref =~ s/$RE_FUNCTION//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$line_ref =~ s/$RE_FUNCTION//o) { } 82 121 203
1132 # store the removed text
1133 82 $pre_text = $1; $func = $2;
1134
1135 # is the pretext a Label?
1136 82 ▶ if ($loop_functions{$func} and $pre_text =~ s/$RE_LABEL//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop_functions{$func} and $pre_text =~ s/$RE_LABEL//o) 1 81 82
Condition100%3/3
$loop_functions{$func} and $pre_text =~ s/$RE_LABEL//o
!ll&&!rl&&r
7741
MC/DC100%2/2
$loop_functions{$func} and $pre_text =~ s/$RE_LABEL//o
$loop_functions{$func} $pre_text =~ s/$RE_LABEL//o
Truth table100%3/3
A and B
A= $loop_functions{$func}B= $pre_text =~ s/$RE_LABEL//o
ABresult
0X0
100
111
1137 1 $label = $1;
1138 }
1139
1140 # Remove pre_text if it only contains tabs and
1141 # we want magic and it is allowed for this func
1142 82 ▶ if ($pre_text and $self->[PML_MAGIC]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_text and $self->[9]) 4 78 82
Condition66%2/3
$pre_text and $self->[9]
!ll&&!rl&&r
7804
MC/DC50%1/2
$pre_text and $self->[9]
$pre_text $self->[9]
Truth table66%2/3
A and B
A= $pre_textB= $self->[9]
ABresult
0X0
100
111
1143 4 $pre_text =~ s/^\s+$//o;
1144 }
1145
1146 # Put the pretext into a token so that it is not lost
1147 82 ▶ if ($pre_text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_text) 4 78 82
1148 4 $token = new PML::Token TOKEN_EVAL;
1149 4 $token->data($pre_text);
1150 4 push @tokens, $token;
1151 }
1152
1153 82 ▶ if (
Branch: 4 branches
BranchTrueFalseTotal
if (exists $function_arg_only{$func} or exists $self->[23]{'function_arg_only'}{$func}) { } 32 50 82
elsif (exists $function_arg_block{$func} or exists $self->[23]{'function_arg_block'}{$func}) { } 32 18 50
elsif (exists $function_block_no_parse{$func} or exists $self->[23]{'function_block_no_parse'}{$func}) { } 9 9 18
elsif (exists $function_block_only{$func} or exists $self->[23]{'function_block_only'}{$func}) { } 2 7 9
Condition100%3/3
exists $function_arg_only{$func} or exists $self->[23]{"function_arg_only"}{$func}
l!l&&r!l&&!r
31150
MC/DC100%2/2
exists $function_arg_only{$func} or exists $self->[23]{"function_arg_only"}{$func}
exists $function_arg_only{$func} exists $self->[23]{"function_arg_only"}{$func}
Truth table100%3/3
A or B
A= exists $function_arg_only{$func}B= exists $self->[23]{"function_arg_only"}{$func}
ABresult
1X1
011
000
1154 exists $function_arg_only{$func} or
1155 exists $self->[PML_PCALLBACKS]{'function_arg_only'}{$func} ){
1156 # these type have args with no blocks
1157 32 ▶ if (exists $self->[PML_PCALLBACKS]{'function_arg_only'}{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->[23]{'function_arg_only'}{$func}) { } 1 31 32
1158 1 $callback = $self->[PML_PCALLBACKS]{'function_arg_only'}{$func};
1159 } else { #build in parser or register-class parser
1160 31 $callback = $function_arg_only{$func};
1161 }
1162 32 @arguments = $self->parse_arguments($line_ref, $lines);
1163 32 $token = execute_callback($callback, $self, [@arguments], undef, $line_ref, $lines);
1164 0 ▶ if ($token and $label) {$token->label($label)}
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $label) 0 32 32
Condition66%2/3
$token and $label
!ll&&!rl&&r
3290
MC/DC0%0/2
$token and $label
$token $label
Truth table66%2/3
A and B
A= $tokenB= $label
ABresult
0X0
100
111
1165 32 ▶ if ($token) {push @tokens, $token};
Branch: 1 branch
BranchTrueFalseTotal
if ($token) 29 3 32
1166 ▶ } elsif (
Condition100%3/3
exists $function_arg_block{$func} or exists $self->[23]{"function_arg_block"}{$func}
l!l&&r!l&&!r
31118
MC/DC100%2/2
exists $function_arg_block{$func} or exists $self->[23]{"function_arg_block"}{$func}
exists $function_arg_block{$func} exists $self->[23]{"function_arg_block"}{$func}
Truth table100%3/3
A or B
A= exists $function_arg_block{$func}B= exists $self->[23]{"function_arg_block"}{$func}
ABresult
1X1
011
000
1167 exists $function_arg_block{$func} or
1168 exists $self->[PML_PCALLBACKS]{'function_arg_block'}{$func} ){
1169 # these functions have args and blocks
1170 32 ▶ if (exists $self->[PML_PCALLBACKS]{'function_arg_block'}{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->[23]{'function_arg_block'}{$func}) { } 1 31 32
1171 1 $callback = $self->[PML_PCALLBACKS]{'function_arg_block'}{$func};
1172 } else {
1173 31 $callback = $function_arg_block{$func};
1174 }
1175 32 @arguments = $self->parse_arguments($line_ref, $lines);
1176 32 @block = $self->parse_block($line_ref, $lines);
1177 # call the built in and store the tokens that it returns
1178 32 $token = execute_callback($callback, $self, [@arguments], [@block], $line_ref, $lines);
1179 32 ▶ if ($token and $label) {$token->label($label)}
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $label) 1 31 32
Condition100%3/3
$token and $label
!ll&&!rl&&r
5261
MC/DC100%2/2
$token and $label
$token $label
Truth table100%3/3
A and B
A= $tokenB= $label
ABresult
0X0
100
111
1180 32 ▶ if ($token) {push @tokens, $token};
Branch: 1 branch
BranchTrueFalseTotal
if ($token) 27 5 32
1181 ▶ } elsif (
Condition66%2/3
exists $function_block_no_parse{$func} or exists $self->[23]{"function_block_no_parse"}{$func}
l!l&&r!l&&!r
909
MC/DC50%1/2
exists $function_block_no_parse{$func} or exists $self->[23]{"function_block_no_parse"}{$func}
exists $function_block_no_parse{$func} exists $self->[23]{"function_block_no_parse"}{$func}
Truth table66%2/3
A or B
A= exists $function_block_no_parse{$func}B= exists $self->[23]{"function_block_no_parse"}{$func}
ABresult
1X1
011
000
1182 exists $function_block_no_parse{$func} or
1183 exists $self->[PML_PCALLBACKS]{'function_block_no_parse'}{$func} ){
1184 # these are fuctions that need to parse their own blocks
1185 # we just grab whats between the { and } and give them the rest
1186 9 ▶ if (exists $self->[PML_PCALLBACKS]{'function_block_no_parse'}{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->[23]{'function_block_no_parse'}{$func}) { } 0 9 9
1187 0 $callback = $self->[PML_PCALLBACKS]{'function_block_no_parse'}{$func};
1188 } else {
1189 9 $callback = $function_block_no_parse{$func};
1190 }
1191 9 $self->magic_newline($line_ref, $lines);
1192 9 $token = execute_callback (
1193 $callback,
1194 $self,
1195 $self->gut('{', '}', $line_ref, $lines, 1)
1196 );
1197 0 ▶ if ($token and $label) {$token->label($label)}
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $label) 0 9 9
Condition33%1/3
$token and $label
!ll&&!rl&&r
090
MC/DC0%0/2
$token and $label
$token $label
Truth table33%1/3
A and B
A= $tokenB= $label
ABresult
0X0
100
111
1198 9 ▶ if ($token) {push @tokens, $token};
Branch: 1 branch
BranchTrueFalseTotal
if ($token) 9 0 9
1199 ▶ } elsif (
Condition100%3/3
exists $function_block_only{$func} or exists $self->[23]{"function_block_only"}{$func}
l!l&&r!l&&!r
117
MC/DC100%2/2
exists $function_block_only{$func} or exists $self->[23]{"function_block_only"}{$func}
exists $function_block_only{$func} exists $self->[23]{"function_block_only"}{$func}
Truth table100%3/3
A or B
A= exists $function_block_only{$func}B= exists $self->[23]{"function_block_only"}{$func}
ABresult
1X1
011
000
1200 exists $function_block_only{$func} or
1201 exists $self->[PML_PCALLBACKS]{'function_block_only'}{$func} ){
1202 # these are functins that only have a block
1203 2 ▶ if (exists $self->[PML_PCALLBACKS]{'function_block_only'}{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->[23]{'function_block_only'}{$func}) { } 1 1 2
1204 1 $callback = $self->[PML_PCALLBACKS]{'function_block_only'}{$func};
1205 } else {
1206 1 $callback = $function_block_only{$func};
1207 }
1208 2 @block = $self->parse_block($line_ref, $lines);
1209 2 $token = execute_callback($callback, $self, undef, [@block], $line_ref, $lines);
1210 0 ▶ if ($token and $label) {$token->label($label)}
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $label) 0 2 2
Condition33%1/3
$token and $label
!ll&&!rl&&r
020
MC/DC0%0/2
$token and $label
$token $label
Truth table33%1/3
A and B
A= $tokenB= $label
ABresult
0X0
100
111
1211 2 ▶ if ($token) {push @tokens, $token};
Branch: 1 branch
BranchTrueFalseTotal
if ($token) 2 0 2
1212 } else {
1213 # these are macros or functions that are not defined
1214 # we need to see if the macro has a variable in it's name
1215 7 ▶ if ($func =~ /$RE_VAR_TEST/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func =~ /$RE_VAR_TEST/o) { } 1 6 7
1216 1 $token = new PML::Token TOKEN_MAGIC_MACRO;
1217 } else { # this is just a normal macro call
1218 6 $token = new PML::Token TOKEN_MACRO;
1219 }
1220 7 $token->data([$func, $self->parse_arguments($line_ref, $lines)]);
1221 0 ▶ if ($token and $label) {$token->label($label)}
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $label) 0 7 7
Condition33%1/3
$token and $label
!ll&&!rl&&r
070
MC/DC0%0/2
$token and $label
$token $label
Truth table33%1/3
A and B
A= $tokenB= $label
ABresult
0X0
100
111
1222 7 ▶ if ($token) {push @tokens, $token}
Branch: 1 branch
BranchTrueFalseTotal
if ($token) 7 0 7
1223
1224 7 ▶ if ($self->peek(qr/^{/o, $line_ref, $lines)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->peek(qr/^{/o, $line_ref, $lines)) 1 6 7
1225 1 $self->error_syntax
1226 ("there is no such function called '$func'");
1227 }
1228 6 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->id == 14 or exists $self->[13]{$func}) 3 3 6
Condition100%3/3
$token->id == 14 or exists $self->[13]{$func}
l!l&&r!l&&!r
123
MC/DC100%2/2
$token->id == 14 or exists $self->[13]{$func}
$token->id == 14 exists $self->[13]{$func}
Truth table100%3/3
A or B
A= $token->id == 14B= exists $self->[13]{$func}
ABresult
1X1
011
000
1229 $token->id == TOKEN_MAGIC_MACRO or
1230 exists $self->[PML_MACROS]{$func} ){
1231 3 push @invalid_functions,
1232 [$func, $self->[PML_LINE_STR]];
1233 }
1234 }
1235
1236 # Check to see if we are allowed to remove the trailing
1237 # spaces and newline
1238 81 ▶ if ($allow_remove_newline{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_remove_newline{$func}) 62 19 81
1239 62 $$line_ref =~ s/^\s*\n//o;
1240 }
1241
1242 } else {
1243 # if there were no calls to a built-in then this
1244 # line will only contain variables and/or text
1245 # so we add the line with the EVAL token
1246 121 $token = new PML::Token TOKEN_EVAL;
1247 121 $token->data($$line_ref);
1248 121 push @tokens, $token;
1249 121 $$line_ref = ''; # we took the whole line
1250 }
1251
1252 202 return @tokens;
1253 } # <-- End parse_one_line -->
1254 ################################################################################
1255 #
1256 # ==== parse_arguments ==== ####################################################
1257 #
1258 # Arguments:
1259 # 1) A PML Object
1260 # 2) A reference to a line to cut up
1261 # 3) A ref to an array of lines (Optional, defaults to self->[PML_LINES]
1262 #
1263 # Returns:
1264 # A list of tokens that make up the arguments to the function call
1265 #
1266 # Description:
1267 # Looks in the line for the arguments to the function call
1268 #
1269 ################################################################################
1270 sub parse_arguments
1271 75 ▶{
Subroutine parse_arguments: called CC=24 SCAR=36.1
Pod undocumented
1272 75 my ($self, $line_ref, $lines) = @_;
1273 75 my (@tokens, $guts, @args, $x, $y, @queue);
1274 75 my ($token, $stoken);
1275 75 my $M = G_MARKER();
1276
1277 # check arguments
1278 75 ▶ croak("Usage: parse_arguments(pml_object, line_reference)") unless defined $self and defined $line_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $line_ref 0 75 75
Condition33%1/3
defined $self and defined $line_ref
!ll&&!rl&&r
0075
MC/DC0%0/2
defined $self and defined $line_ref
defined $self defined $line_ref
Truth table33%1/3
A and B
A= defined $selfB= defined $line_ref
ABresult
0X0
100
111
1279
1280 # set lines to self PML_LINES if not already set
1281 75 ▶ $lines ||= $self->[PML_LINES];
Condition33%1/3
$lines ||= $self->[5]
l!l&&r!l&&!r
7500
MC/DC0%0/2
$lines ||= $self->[5]
$lines $self->[5]
Truth table33%1/3
A ||= B
A= $linesB= $self->[5]
ABresult
1X1
011
000
1282
1283 # Remove any space and newlines that might apear before the arguments
1284 75 $self->magic_newline($line_ref, $lines);
1285
1286 # check to see if the first char is an expected character
1287 75 $x = substr $$line_ref, 0, 1;
1288 75 ▶ if (not defined $x or $x ne '(') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $x or $x ne "(") 0 75 75
Condition33%1/3
not defined $x or $x ne "("
l!l&&r!l&&!r
0075
MC/DC0%0/2
not defined $x or $x ne "("
not defined $x $x ne "("
Truth table33%1/3
not(A) or B
A= not defined $xB= $x ne "("
ABresult
1X1
011
000
1289 0 $self->error_syntax("expected a '(' but found '$x' instead");
1290 }
1291  
1292 # get the guts between the '(' and the ')'
1293 75 $guts = $self->gut('(', ')', $line_ref, $lines);
1294
1295 # return a empty list if there are no guts
1296 75 ▶ return () unless length $guts;
Branch: 1 branch
BranchTrueFalseTotal
unless length $guts 4 71 75
1297
1298 # clean up the arg list
1299 71 $guts =~ s/\n+//ogs;
1300 71 $guts =~ s/^\s+//os;
1301 71 $guts =~ s/\s+$//os;
1302
1303 # now break up the line
1304 71 ▶ while ($guts =~ /\S/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guts =~ /\S/o) 103 71 174
1305 103 $x = substr($guts, 0, 1);
1306
1307 103 ▶ if ($x eq '"' or $x eq "'") {
Branch: 3 branches
BranchTrueFalseTotal
if ($x eq '"' or $x eq q[']) { } 27 76 103
elsif ($guts =~ s/^(\${$RE_VAR})\s*(?=,|=>|$)//o) { } 9 67 76
elsif ($guts =~ s/^((?:\d+)(?:\.\d+)?)\s*(?=,|=>|$)//o) { } 35 32 67
Condition100%3/3
$x eq "\"" or $x eq "'"
l!l&&r!l&&!r
171076
MC/DC100%2/2
$x eq "\"" or $x eq "'"
$x eq "\"" $x eq "'"
Truth table100%3/3
A or B
A= $x eq "\""B= $x eq "'"
ABresult
1X1
011
000
1308 27 $y = $self->gut($x, $x, \$guts, []);
1309 27 ▶ while ($y =~ /$RE_FUNCTION/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y =~ /$RE_FUNCTION/o) 0 27 27
1310 0 push @queue,
1311 $self->parse_one_line(\$y, []);
1312 }
1313
1314 27 ▶ if (length $y) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $y) 27 0 27
1315 27 $token = new PML::Token TOKEN_EVAL;
1316 27 $token->data($y);
1317 27 push @queue, $token;
1318 }
1319 } elsif ($guts =~ s/^(\${$RE_VAR})\s*(?=,|=>|$)//o) {
1320 9 $token = new PML::Token TOKEN_VARIABLE;
1321 9 $token->data($y = $1);
1322 9 push @queue, $token;
1323 } elsif ($guts =~ s/^((?:\d+)(?:\.\d+)?)\s*(?=,|=>|$)//o) {
1324 35 $token = new PML::Token TOKEN_EVAL;
1325 35 $token->data($y = $1);
1326 35 push @queue, $token;
1327 } else {
1328 32 ▶ if ($guts =~ /^[^,]*?(?<!\\)$M/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guts =~ /^[^,]*?(?<!\\)$M/o) { } 3 29 32
1329 3 push @queue,
1330 $self->parse_one_line(\$guts, []);
1331 } else {
1332 29 $guts =~ s/^([^,]+)//o;
1333 29 ($y = $1) =~ s/\s+$//o;
1334 29 ▶ if (length $y) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $y) 29 0 29
1335 29 $token = new PML::Token TOKEN_EVAL;
1336 29 $token->data($y);
1337 29 push @queue, $token;
1338 }
1339 }
1340 }
1341
1342 # did we run out of arguments or should we move
1343 # on to the next one?
1344 103 ▶ if ($guts =~ s/^\s*(?:(?:,\s*)|(?:=>\s*)|$)//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guts =~ s/^\s*(?:(?:,\s*)|(?:=>\s*)|$)//o) 103 0 103
1345 103 ▶ if (@queue > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue > 1) { } 0 103 103
1346 0 push @tokens, [@queue];
1347 0 @queue = ();
1348 } else {
1349 103 ▶ push @tokens, shift @queue if @queue;
Branch: 1 branch
BranchTrueFalseTotal
if @queue 103 0 103
1350 }
1351 }
1352 }
1353
1354 # now just make sure that the queue is empty
1355 71 ▶ if (@queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 0 71 71
1356 0 ▶ if (@queue > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue > 1) { } 0 0 0
1357 0 push @tokens, [@queue];
1358 } else {
1359 0 push @tokens, shift @queue;
1360 }
1361 }
1362
1363 # set some token flags on all the tokens
1364 71 foreach $token (@tokens) {
1365 103 ▶ if (ref $token eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token eq "ARRAY") 0 103 103
1366 0 foreach $stoken (@$token) {
1367 0 $stoken->file_loc(FILE_LOC_ARG);
1368 0 $stoken->context(CONTEXT_LIST);
1369 0 } next;
1370 }
1371
1372 103 $token->file_loc(FILE_LOC_ARG);
1373 103 $token->context(CONTEXT_LIST);
1374 }
1375
1376 # return the tokens that we collected
1377 71 return @tokens;
1378 } # <-- End parse_arguments -->
1379 ################################################################################
1380 #
1381 # ==== parse_block ==== ########################################################
1382 #
1383 # Arguments:
1384 # 1) A PML Object
1385 # 2) A Reference to a line
1386 # 3) A ref to an array of lines (Optional, defaults to self->[PML_LINES])
1387 #
1388 # Returns:
1389 # A List of tokens for the block
1390 #
1391 # Description:
1392 # tries to get the block following the function call
1393 #
1394 ################################################################################
1395 sub parse_block
1396 44 ▶{
Subroutine parse_block: called CC=7 SCAR=20.4
Pod undocumented
1397 44 my ($self, $line_ref, $lines) = @_;
1398 44 my ($x, @tokens, $guts, $token);
1399
1400 # check arguments
1401 44 ▶ croak("Usage: parse_block(pml_object, line_reference")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $line_ref 0 44 44
Condition33%1/3
defined $self and defined $line_ref
!ll&&!rl&&r
0044
MC/DC0%0/2
defined $self and defined $line_ref
defined $self defined $line_ref
Truth table33%1/3
A and B
A= defined $selfB= defined $line_ref
ABresult
0X0
100
111
1402 unless defined $self and defined $line_ref;
1403
1404 # set lines to self PML_LINES if not already set
1405 44 ▶ $lines ||= $self->[PML_LINES];
Condition33%1/3
$lines ||= $self->[5]
l!l&&r!l&&!r
4400
MC/DC0%0/2
$lines ||= $self->[5]
$lines $self->[5]
Truth table33%1/3
A ||= B
A= $linesB= $self->[5]
ABresult
1X1
011
000
1406
1407 # Remove any spaces or newlines
1408 44 $self->magic_newline($line_ref, $lines);
1409
1410 # check to see if the first char is an expected character
1411 44 $x = substr $$line_ref, 0, 1;
1412
1413 44 ▶ unless ($x eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($x eq "{") 0 44 44
1414 0 $self->error_syntax (
1415 "can't find opening brace, saw '$x' instead"
1416 );
1417 }
1418
1419 # get the guts between the '{' and the '}'
1420 44 $guts = $self->gut('{', '}', $line_ref, $lines, 1);
1421 44 $self->magic_newline_gut(\$guts);
1422 44 $self->magic_tab(\$guts);
1423
1424 # parse the text in the block
1425 44 ▶ while (length $guts) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $guts) 42 44 86
1426 42 push @tokens, $self->parse_one_line(\$guts, []);
1427 }
1428
1429 # set some token flags
1430 44 foreach $token (@tokens) {
1431 45 $token->context(CONTEXT_SCALAR);
1432 45 $token->file_loc(FILE_LOC_BLOCK);
1433 }
1434
1435 44 return @tokens;
1436 } # <-- End parse_block -->
1437 ################################################################################
1438 #
1439 # ==== magic_newline ==== ######################################################
1440 #
1441 # Arguments:
1442 # 1) A PML Object
1443 # 2) A reference to a string
1444 # 3) A reference to a array of strings (optional)
1445 #
1446 # Returns:
1447 # None
1448 #
1449 # Description:
1450 # Removes all spaces and newlines from the front of arg 2.
1451 # pulls another string off arg3 if necessary
1452 #
1453 ################################################################################
1454 sub magic_newline
1455 138 ▶{
Subroutine magic_newline: called CC=8 SCAR=22.1
Pod undocumented
1456 138 my ($self, $line_ref, $lines) = @_;
1457 138 my $line_num = $self->[PML_LINE];
1458  
1459 138 ▶ return unless $self->[PML_MAGIC] and $self->[PML_MAGIC_NEWLINE];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[9] and $self->[10] 0 138 138
Condition33%1/3
$self->[9] and $self->[10]
!ll&&!rl&&r
00138
MC/DC0%0/2
$self->[9] and $self->[10]
$self->[9] $self->[10]
Truth table33%1/3
A and B
A= $self->[9]B= $self->[10]
ABresult
0X0
100
111
1460
1461 138 while (1)
1462 {
1463 173 ▶ last unless length($$line_ref) or @{$lines};
Branch: 1 branch
BranchTrueFalseTotal
unless length $$line_ref or @{$lines;} 0 173 173
Condition66%2/3
length $$line_ref or @{$lines;}
l!l&&r!l&&!r
138350
MC/DC0%0/2
length $$line_ref or @{$lines;}
length $$line_ref @{$lines;}
Truth table66%2/3
A or B
A= length $$line_refB= @{$lines;}
ABresult
1X1
011
000
1464 173 ▶ $$line_ref = $self->next_line($lines) unless length($$line_ref);
Branch: 1 branch
BranchTrueFalseTotal
unless length $$line_ref 35 138 173
1465 173 $$line_ref =~ s/^(\s|\n)+//og;
1466 173 ▶ last if length $$line_ref;
Branch: 1 branch
BranchTrueFalseTotal
if length $$line_ref 138 35 173
1467 }
1468
1469 138 ▶ unless (length $$line_ref)
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$line_ref) 0 138 138
1470 {
1471 0 $self->warn_error("did not expect EOF, was looking for a char starting from line $line_num");
1472 }
1473 } # <-- End magic_newline -->
1474 ################################################################################
1475 #
1476 # ==== magic_newline_gut ==== ##################################################
1477 #
1478 # Arguments:
1479 # 1) A PML Object
1480 # 2) A reference to a string
1481 #
1482 # Returns:
1483 # None
1484 #
1485 # Description:
1486 # Removes prefixing and trail spaces and newline
1487 #
1488 ################################################################################
1489 sub magic_newline_gut
1490 44 ▶{
Subroutine magic_newline_gut: called CC=3 SCAR=12.0
Pod undocumented
1491 44 my ($self, $line_ref) = @_;
1492
1493 44 ▶ return unless $self->[PML_MAGIC] and $self->[PML_MAGIC_NEWLINE];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[9] and $self->[10] 0 44 44
Condition33%1/3
$self->[9] and $self->[10]
!ll&&!rl&&r
0044
MC/DC0%0/2
$self->[9] and $self->[10]
$self->[9] $self->[10]
Truth table33%1/3
A and B
A= $self->[9]B= $self->[10]
ABresult
0X0
100
111
1494
1495 44 $$line_ref =~ s/^\s*\n//os;
1496 44 $$line_ref =~ s/\n\s*$//os;
1497 } # <-- End magic_newline_gut -->
1498 ################################################################################
1499 #
1500 # ==== magic_tab ==== ##########################################################
1501 #
1502 # Arguments:
1503 # 1) A PML Object
1504 # 2) A reference to a string
1505 #
1506 # Returns:
1507 # None
1508 #
1509 # Description:
1510 # Removes one tab from the begining of each line
1511 #
1512 ################################################################################
1513 sub magic_tab
1514 44 ▶{
Subroutine magic_tab: called CC=3 SCAR=14.2
Pod undocumented
1515 44 my ($self, $line_ref) = @_;
1516
1517 44 ▶ return unless $self->[PML_MAGIC] and $self->[PML_MAGIC_TAB];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[9] and $self->[11] 44 0 44
Condition33%1/3
$self->[9] and $self->[11]
!ll&&!rl&&r
0440
MC/DC0%0/2
$self->[9] and $self->[11]
$self->[9] $self->[11]
Truth table33%1/3
A and B
A= $self->[9]B= $self->[11]
ABresult
0X0
100
111
1518 0 $$line_ref =~ s/^\t//mog;
1519 } # <-- End magic_tab -->
1520 ################################################################################
1521 #
1522 # ==== gut ==== ################################################################
1523 #
1524 # Arguments:
1525 # 1) A PML Object
1526 # 2) A starting delimiter
1527 # 3) An ending delimiter
1528 # 4) A ref to a string
1529 # 5) A ref to an array to get more lines (optional)
1530 # 6) A flag (true means don't sub gut for ('|")) (optioal)
1531 #
1532 # Returns:
1533 # An array of lines that are in between the delimiters
1534 #
1535 # Description:
1536 # This is a replacement for the orignial gut. It will do a charater by
1537 # charter look instead of using regexs
1538 #
1539 ################################################################################
1540 sub gut
1541 256 ▶{
Subroutine gut: called CC=28 SCAR=34.9
Pod undocumented
1542 256 my ($self, $od, $cd, $line_ref, $lines, $sflag) = @_;
1543 256 my (@repository, @gut, $result);
1544 256 my ($got_od, $last_char, $last_real_char, $char, $count, $ds);
1545 256 my (@sub_gut, @pre_sg, @post_sg);
1546 256 my $sub_gut_regex = qr/:=:\((\d+)\):=:/;
1547
1548 256 @pre_sg = (':', '=', ':', '(');
1549 256 @post_sg = (')', ':', '=', ':');
1550
1551 256 ▶ $lines ||= $self->[PML_LINES];
Condition33%1/3
$lines ||= $self->[5]
l!l&&r!l&&!r
25600
MC/DC0%0/2
$lines ||= $self->[5]
$lines $self->[5]
Truth table33%1/3
A ||= B
A= $linesB= $self->[5]
ABresult
1X1
011
000
1552 256 $last_char = $last_real_char = '';
1553 256 $ds = 0; # do we have a double back slash condition?
1554
1555 256 while (1)
1556 {
1557 1941 ▶ unless (@repository) # fill the repository
Branch: 1 branch
BranchTrueFalseTotal
unless (@repository) 374 1567 1941
1558 {
1559 374 ▶ last unless length($$line_ref) or @{$lines};
Branch: 1 branch
BranchTrueFalseTotal
unless length $$line_ref or @{$lines;} 0 374 374
Condition66%2/3
length $$line_ref or @{$lines;}
l!l&&r!l&&!r
287870
MC/DC0%0/2
length $$line_ref or @{$lines;}
length $$line_ref @{$lines;}
Truth table66%2/3
A or B
A= length $$line_refB= @{$lines;}
ABresult
1X1
011
000
1560 374 ▶ $$line_ref = $self->next_line($lines)
Branch: 1 branch
BranchTrueFalseTotal
unless length $$line_ref 87 287 374
1561 unless length $$line_ref;
1562 374 ▶ length $$line_ref or next;
Branch: 1 branch
BranchTrueFalseTotal
length $$line_ref or next 374 0 374
1563 374 push @repository, split(//, $$line_ref);
1564 374 $$line_ref = '';
1565 }
1566
1567 1941 $char = shift @repository;
1568 1941 ▶ defined $char or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $char or next 1941 0 1941
1569
1570 1941 ▶ unless ($got_od)
Branch: 1 branch
BranchTrueFalseTotal
unless ($got_od) 256 1685 1941
1571 {
1572 256 ▶ unless ($char eq $od) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $od) { } 256 0 256
1573 0 $self->error_syntax (
1574 "looking for open delimiter '$od' ".
1575 "but found '$char' instead, near '$char".
1576 join('', @repository) .
1577 "'"
1578 );
1579 } else {
1580 256 $got_od = 1;
1581 256 $count++;
1582 256 next;
1583 }
1584 }
1585
1586 1685 ▶ if ($last_real_char ne '\\' and $char =~ /^(['"])/o and $od ne $1 and not $sflag)
Branch: 1 branch
BranchTrueFalseTotal
if ($last_real_char ne "\\" and $char =~ /^(['"])/o and $od ne $1 and not $sflag) 31 1654 1685
Condition88%8/9
$last_real_char ne "\\" and $char =~ /^(['"])/o and $od ne $1 and not $sflag
!ll&&!rl&&r
16401431
$last_real_char ne "\\" and $char =~ /^(['"])/o and $od ne $1
!ll&&!rl&&r
15825845
$last_real_char ne "\\" and $char =~ /^(['"])/o
!ll&&!rl&&r
01582103
MC/DC75%3/4
$last_real_char ne "\\" and $char =~ /^(['"])/o and $od ne $1 and not $sflag
$last_real_char ne "\\" $char =~ /^(['"])/o $od ne $1 not $sflag
Truth table80%4/5
A and B and C and not(D)
A= $last_real_char ne "\\"B= $char =~ /^(['"])/oC= $od ne $1D= not $sflag
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1587 {
1588 31 my $tmp = join '', $1, @repository; undef @repository;
1589 31 push @gut, $1, @pre_sg, scalar @sub_gut, @post_sg, $1;
1590 31 push @sub_gut, $self->gut($1, $1, \$tmp, $lines);
1591 31 $$line_ref = $tmp;
1592 31 next;
1593 }
1594
1595 1654 ▶ if ($char eq $od and ($last_real_char ne '\\' or $ds))
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $od and $last_real_char ne "\\" || $ds) 91 1563 1654
Condition50%3/6
$char eq $od and $last_real_char ne "\\" || $ds
!ll&&!rl&&r
1563091
$last_real_char ne "\\" or $ds
l!l&&r!l&&!r
9100
MC/DC33%1/3
$char eq $od and $last_real_char ne "\\" || $ds
$char eq $od $last_real_char ne "\\" $ds
Truth table50%2/4
A and B or C
A= $char eq $odB= $last_real_char ne "\\"C= $ds
ABCresult
0XX0
1000
11X1
1011
1596 {
1597 91 ▶ $count++ unless $od eq $cd;
Branch: 1 branch
BranchTrueFalseTotal
unless $od eq $cd 33 58 91
1598 }
1599
1600 1654 ▶ if ($char eq $cd and ($last_real_char ne '\\' or $ds))
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $cd and $last_real_char ne "\\" || $ds) 289 1365 1654
Condition50%3/6
$char eq $cd and $last_real_char ne "\\" || $ds
!ll&&!rl&&r
13650289
$last_real_char ne "\\" or $ds
l!l&&r!l&&!r
28900
MC/DC33%1/3
$char eq $cd and $last_real_char ne "\\" || $ds
$char eq $cd $last_real_char ne "\\" $ds
Truth table50%2/4
A and B or C
A= $char eq $cdB= $last_real_char ne "\\"C= $ds
ABCresult
0XX0
1000
11X1
1011
1601 {
1602 289 $count--;
1603 289 ▶ last unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 256 33 289
1604 }
1605
1606 1398 push @gut, $char;
1607
1608 1398 ▶ if ($last_real_char eq '\\' and $char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_real_char eq '\\' and $char eq '\\') { } 0 1398 1398
Condition33%1/3
$last_real_char eq "\\" and $char eq "\\"
!ll&&!rl&&r
139800
MC/DC0%0/2
$last_real_char eq "\\" and $char eq "\\"
$last_real_char eq "\\" $char eq "\\"
Truth table33%1/3
A and B
A= $last_real_char eq "\\"B= $char eq "\\"
ABresult
0X0
100
111
1609 0 $ds = 1;
1610 } else {
1611 1398 $ds = 0;
1612 }
1613
1614 1398 $last_real_char = $char;
1615 1398 ▶ $last_char = $char unless
Branch: 1 branch
BranchTrueFalseTotal
unless $char =~ /^(\s|\n|\\)/o 1117 281 1398
1616 $char =~ /^(\s|\n|\\)/o;
1617 }
1618
1619 256 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 0 256 256
1620 0 $self->error_syntax (
1621 "I can't seem to find the closing '$cd'"
1622 );
1623 }
1624
1625 256 ▶ $$line_ref = join '', @repository if @repository;
Branch: 1 branch
BranchTrueFalseTotal
if @repository 199 57 256
1626 256 $result = join '', @gut;
1627 256 ▶ $result =~ s/$sub_gut_regex/$sub_gut[$1]/gos if @sub_gut;
Branch: 1 branch
BranchTrueFalseTotal
if @sub_gut 23 233 256
1628 256 return $result;
1629 } # <-- End gut -->
1630 ################################################################################
1631 #
1632 # ==== next_line ==== ##########################################################
1633 #
1634 # Arguments:
1635 # 1) PML Object
1636 # 2) An Arrary Reference of Lines
1637 #
1638 # Returns:
1639 # 1) A line from the Array
1640 # -- or --
1641 # 2) undef if no more lines
1642 #
1643 # Description:
1644 # goes through the array of lines trying to find one that we can return.
1645 # lines that beging with a pound signare skipped. Lines that
1646 # end with a backslash are joined with the line that follows it.
1647 #
1648 ################################################################################
1649 sub next_line
1650 280 ▶{
Subroutine next_line: called CC=9 SCAR=22.9
Pod undocumented
1651 280 my ($self, $lines) = @_;
1652 280 my ($line);
1653
1654 # Check to make sure that we got the correct number of arguments
1655 280 ▶ $lines ||= $self->[PML_LINES] || undef;
Condition60%3/5
$lines ||= $self->[5] || undef
l!l&&r!l&&!r
1221580
$self->[5] || undef
l!l
1580
MC/DC0%0/2
$lines ||= $self->[5] || undef
$lines $self->[5]
Truth table66%2/3
A ||= B
A= $linesB= $self->[5]
ABresult
1X1
011
000
1656 280 ▶ croak("Usage: next_line(pml_object, array_ref)") unless defined $self and defined $lines;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $lines 0 280 280
Condition33%1/3
defined $self and defined $lines
!ll&&!rl&&r
00280
MC/DC0%0/2
defined $self and defined $lines
defined $self defined $lines
Truth table33%1/3
A and B
A= defined $selfB= defined $lines
ABresult
0X0
100
111
1657
1658 # Now we loop pulling out lines
1659 280 ▶ while (@{$lines}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$lines;}) 318 18 336
1660 # Get a fresh line to work with
1661 318 $line = shift @$lines;
1662
1663 # update the line counter
1664 318 ▶ if ($lines == $self->[PML_LINES]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines == $self->[5]) 318 0 318
1665 318 $self->[PML_LINE_STR] = 'on line ' . ++$self->[PML_LINE];
1666 318 $self->[PML_LINE_STR] .= " from " . $self->[PML_FILE];
1667 }
1668
1669 # reasons to check next line
1670 318 ▶ defined $line or next; # this line needs to have something on it
Branch: 1 branch
BranchTrueFalseTotal
defined $line or next 318 0 318
1671 318 ▶ $line =~ /^\s*#/o and next; # skip if line is a comment
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s*#/o and next 56 262 318
1672 #length($line) or next;
1673
1674 262 return $line;
1675 }
1676  
1677 18 return undef;
1678 } # <-- End next_line -->
1679 ################################################################################
1680 #
1681 # ==== peek ==== ###############################################################
1682 #
1683 # Arguments:
1684 # 1) PML Object
1685 # 2) A Regular Expression that you are looking for
1686 # 3) A ref to a string (current line)
1687 # 4) Array Reference (Optional if $self->[PML_LINES] exists)
1688 #
1689 # Returns:
1690 # True if that patter will be found; False otherwise
1691 #
1692 # Description:
1693 # Scans through the array of lines looking for the first charater
1694 # that is not space or newline and the tries to match the regular
1695 # expression on the remaining string.
1696 #
1697 ################################################################################
1698 sub peek
1699 27 ▶{
Subroutine peek: called CC=6 SCAR=17.9
Pod undocumented
1700 27 my ($self, $regex, $line_ref, $lines) = @_;
1701 27 my ($i);
1702
1703 27 ▶ if ($$line_ref =~ /(\S+)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$line_ref =~ /(\S+)/o) 9 18 27
1704 9 ▶ return $1 =~ $regex ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$1 =~ /$regex/ ? : 8 1 9
1705 }
1706
1707 18 ▶ for ($i=0; $i<=$#{$lines}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$lines;}) 28 1 29
1708 28 ▶ next unless $lines->[$i] =~ /(\S+)/o;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines->[$i] =~ /(\S+)/o 11 17 28
1709 17 ▶ return $1 =~ $regex ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$1 =~ /$regex/ ? : 3 14 17
1710 }
1711 } # <-- End peek -->
1712 ################################################################################
1713 #
1714 # ==== replace_variable ==== ###################################################
1715 #
1716 # Arguments:
1717 # 1) A PML Object
1718 # 2) The name of the variable
1719 #
1720 # Returns:
1721 # A String
1722 #
1723 # Description:
1724 # Returns a string with the value of the varable
1725 #
1726 ################################################################################
1727 sub replace_variable
1728 70 ▶{
Subroutine replace_variable: called CC=23 SCAR=43.4
Pod undocumented
1729 70 my ($self, $vref) = @_;
1730 70 my ($index, $v, $x);
1731
1732 # get the inside of the variable
1733 70 $v = $self->gut('{', '}', $vref, []);
1734
1735 # does this match a variable regex?
1736 70 ▶ unless ($v =~ /^$RE_VAR/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /^$RE_VAR/o) 0 70 70
1737 0 return "\${$v}";
1738 }
1739
1740 # keep from deep recursion
1741 70 $self->_in;
1742  
1743 # look for another variable inside this one
1744 70 ▶ while ($v =~ s/^$RE_VAR_TEST//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^$RE_VAR_TEST//o) 7 70 77
1745 7 ▶ $x .= $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 4 3 7
1746 7 $x .= $self->replace_variable(\$v);
1747 }
1748
1749 # set x back to v if v did not have a variable
1750 70 ▶ $x .= $v if length $v;
Branch: 1 branch
BranchTrueFalseTotal
if length $v 68 2 70
1751
1752 # no longer going to call myself!
1753 70 $self->_out;
1754
1755 # now, check once more for allowed charaters
1756 70 ▶ ($v = $x) =~ /$RE_VAR/o or return $v;
Branch: 1 branch
BranchTrueFalseTotal
($v = $x) =~ /$RE_VAR/o or return $v 70 0 70
1757
1758
1759 # now look to see if this is an array index
1760 70 ▶ if ($v =~ /^(.*?)\[(\d+)\]$/o) {
Branch: 4 branches
BranchTrueFalseTotal
if ($v =~ /^(.*?)\[(\d+)\]$/o) { } 6 64 70
elsif ($v =~ /^([^\.]+)\.([^\.]+)$/o) { } 4 60 64
elsif (ref $self->[0]{$v} eq 'ARRAY') { } 1 59 60
elsif (ref $self->[0]{$v} eq 'HASH') { } 0 59 59
1761 6 $index = $2;
1762 6 $v = $1;
1763
1764 6 ▶ unless (ref($self->[PML_V]{$v}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->[0]{$v} eq "ARRAY") 0 6 6
1765 0 ▶ print STDERR "Variable $v is not an array but you used the index operator on it, the result is a blank string.\n" if $self->[PML_W];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[6] 0 0 0
1766 0 ▶ return '' unless wantarray; return ();
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
1767 }
1768
1769 6 ▶ if (defined $self->[PML_V]{$v}[$index]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{$v}[$index]) { } 6 0 6
1770 6 return $self->[PML_V]{$v}[$index];
1771 } else {
1772 0 ▶ print STDERR "the index '$index' to the variable '$v' was used when it had no value\n" if $self->[PML_W];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[6] 0 0 0
1773 0 return '';
1774 }
1775 } elsif ($v =~ /^([^\.]+)\.([^\.]+)$/o) { # Hash index?
1776 4 $index = $2;
1777 4 $v = $1;
1778
1779 4 ▶ unless (ref($self->[PML_V]{$v}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->[0]{$v} eq "HASH") 0 4 4
1780 0 ▶ print STDERR "variable '$v' is not a hash, but you used it as one. the result is a blank value\n" if $self->[PML_W];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[6] 0 0 0
1781 0 return '';
1782 }
1783
1784 4 ▶ if (defined $self->[PML_V]{$v}{$index}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{$v}{$index}) { } 4 0 4
1785 4 return $self->[PML_V]{$v}{$index};
1786 } else {
1787 0 ▶ print STDERR "the hash key '$index' to the hash '$v' was not set, the result is a blank value\n" if $self->[PML_W];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[6] 0 0 0
1788 0 return '';
1789 }
1790 } elsif (ref ($self->[PML_V]{$v}) eq 'ARRAY') { # whole array?
1791 1 ▶ return @{$self->[PML_V]{$v}} if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 0 1
1792 0 return join ' ', @{$self->[PML_V]{$v}};
1793 } elsif (ref ($self->[PML_V]{$v}) eq 'HASH') { # whole hash?
1794 0 ▶ return values %{$self->[PML_V]{$v}} if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
1795 0 return join ' ', values %{$self->[PML_V]{$v}};
1796 } else { # normal variable
1797 59 ▶ if (defined $self->[PML_V]{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{$v}) { } 59 0 59
1798 59 return $self->[PML_V]{$v};
1799 } else {
1800 0 ▶ print STDERR "the variable '$v' was used before it was set, the result is a blank value\n" if $self->[PML_W];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[6] 0 0 0
1801 0 return '';
1802 }
1803 }
1804 } # <-- End replace_variable -->
1805 ################################################################################
1806 #
1807 # ==== rel2abs ==== ############################################################
1808 #
1809 # Arguments:
1810 # 1) A relative path to a file
1811 # 2) Full path to a starting directory [Optional]
1812 #
1813 # Returns:
1814 # The full path to that file based on arg2 or cwd
1815 #
1816 # Description:
1817 # Removes the ./ and ../ from the path
1818 #
1819 ################################################################################
1820 sub rel2abs
1821 0 ▶{
Subroutine rel2abs: not called CC=6 SCAR=37.4
Pod undocumented
1822 0 my ($path, $base) = @_;
1823 0 my @path_parts = split(/\//, $path);
1824 0 my (@base_parts, $current_part);
1825
1826 0 ▶ $base ||= cwd;
Condition0%0/3
$base ||= cwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$base ||= cwd()
$base cwd()
Truth table0%0/3
A ||= B
A= $baseB= cwd()
ABresult
1X1
011
000
1827
1828 0 @base_parts = split(/\//, $base);
1829
1830 0 ▶ while ($current_part = shift @path_parts)
Branch: 1 branch
BranchTrueFalseTotal
if ($current_part = shift @path_parts) 0 0 0
1831 {
1832 0 ▶ next if $current_part eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $current_part eq "." 0 0 0
1833 0 ▶ pop @base_parts if $current_part eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $current_part eq ".." 0 0 0
1834 0 ▶ push @base_parts, $current_part unless $current_part eq '..';
Branch: 1 branch
BranchTrueFalseTotal
unless $current_part eq ".." 0 0 0
1835 }
1836
1837 0 return '/' . join '/', @base_parts;
1838 } # <-- End rel2abs -->
1839 ################################################################################
1840 #
1841 # ==== error ==== ##############################################################
1842 #
1843 # Arguments:
1844 # 1) A PML Object
1845 # 2) A String
1846 #
1847 # Returns:
1848 # None
1849 #
1850 # Description:
1851 # Prints an error message and exit 1
1852 #
1853 ################################################################################
1854 sub error
1855 0 ▶{
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
1856 0 my ($self, $string) = @_;
1857
1858 0 print STDERR "PML error on line $self->[PML_LINE] from $self->[PML_FILE]: $string\n";
1859 0 exit 1;
1860 } # <-- End error -->
1861 ################################################################################
1862 #
1863 # ==== warn_error ==== #########################################################
1864 #
1865 # Arguments:
1866 # 1) A PML Object
1867 # 2) A String
1868 #
1869 # Returns:
1870 # None
1871 #
1872 # Description:
1873 # Prints an error and returns
1874 #
1875 ################################################################################
1876 sub warn_error
1877 0 ▶{
Subroutine warn_error: not called CC=1 SCAR=6.9
Pod undocumented
1878 0 my ($self, $string) = @_;
1879
1880 0 print STDERR "PML error on line $self->[PML_LINE] from $self->[PML_FILE]: $string\n";
1881 } # <-- End warn_error -->
1882 ################################################################################
1883 #
1884 # ==== error_syntax ==== #######################################################
1885 #
1886 # Arguments:
1887 # 1) A PML Object
1888 # 2) An Description of the syntax error
1889 #
1890 # Returns:
1891 # None
1892 #
1893 # Description:
1894 # Reports an error then dies
1895 #
1896 ################################################################################
1897 sub error_syntax
1898 1 ▶{
Subroutine error_syntax: called CC=2 SCAR=7.1
Pod undocumented
1899 1 my ($self, $message) = @_;
1900 1 my ($text);
1901
1902 1 $text = "PML Syntax Error " . $self->[PML_LINE_STR] . "\n";
1903 1 $text .= "$message\n";
1904
1905 1 ▶ if ($self->[PML_USE_STDERR]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[15]) 0 1 1
1906 0 print STDERR $text;
1907 }
1908
1909 1 die $text;
1910 } # <-- End error_syntax -->
1911 ################################################################################
1912 #
1913 # ==== _in ==== ################################################################
1914 #
1915 # Arguments:
1916 # 1) A PML Object
1917 #
1918 # Returns:
1919 # None
1920 #
1921 # Description:
1922 # Increments the current Recurse count and check to see if we
1923 # went over the max.
1924 #
1925 ################################################################################
1926 sub _in
1927 77 ▶{
Subroutine _in: called CC=2 SCAR=9.2
1928 77 my $self = shift;
1929
1930 77 $self->[PML_RECURSIVE_COUNT]++;
1931
1932 77 ▶ if ($self->[PML_RECURSIVE_COUNT] > $self->[PML_RECURSIVE_MAX]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[18] > $self->[17]) 0 77 77
1933 0 print STDERR "deep recursion detected.\n";
1934 0 print STDERR "max recursion set to "
1935 . $self->[PML_RECURSIVE_MAX] . "\n";
1936 0 croak("recurse error");
1937 }
1938 } # <-- End _in -->
1939 ################################################################################
1940 #
1941 # ==== _out ==== ###############################################################
1942 #
1943 # Arguments:
1944 # 1) PML Object
1945 #
1946 # Returns:
1947 # None
1948 #
1949 # Description:
1950 # Lowers the recurse count
1951 #
1952 ################################################################################
1953 sub _out
1954 77 ▶{
Subroutine _out: called CC=1 SCAR=0.0
1955 77 $_[0]->[PML_RECURSIVE_COUNT]--;
1956 } # <-- End _out -->
1957 ################################################################################
1958 #
1959 # ==== append ==== #############################################################
1960 #
1961 # Arguments:
1962 # 1) PML Object
1963 # 2) PML Object to append to object in arg 1
1964 #
1965 # Returns:
1966 # None
1967 #
1968 # Description:
1969 # Appends PML Object 2 to PML Object 1, PML Object 1 takes priority
1970 # does not append TOKENS though
1971 #
1972 ################################################################################
1973 sub append
1974 1 ▶{
Subroutine append: called CC=1 SCAR=0.0
Pod undocumented
1975 1 my ($self, $append) = @_;
1976
1977 1 %{$self->[PML_INCLUDES]} = (
1978 1 %{$self->[PML_INCLUDES]},
1979 1 %{$append->[PML_INCLUDES]}
1980 );
1981
1982 1 %{$self->[PML_MACROS]} = (
1983 1 %{$self->[PML_MACROS]},
1984 1 %{$append->[PML_MACROS]}
1985 );
1986
1987 1 %{$self->[PML_V]} = (
1988 1 %{$self->[PML_V]},
1989 1 %{$append->[PML_V]}
1990 );
1991  
1992 1 return $self;
1993 } # <-- End append -->
1994 ################################################################################
1995 #
1996 # ==== _token_id ==== ##########################################################
1997 #
1998 # Arguments:
1999 # 1) PML::Token Object
2000 # 2) New Token ID (Optional)
2001 #
2002 # Returns:
2003 # The Current Token ID
2004 #
2005 # Description:
2006 # Sets the Token ID to the one given, if any, then returns the ID.
2007 #
2008 ################################################################################
2009 sub _token_id
2010 1344 ▶{
Subroutine _token_id: called CC=2 SCAR=6.9
2011 1344 my ($token, $id) = @_;
2012
2013 1344 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 312 1032 1344
2014 312 $token->[PML_TOKEN_ID] = $id;
2015 }
2016
2017 1344 return $token->[PML_TOKEN_ID];
2018 } # <-- End _token_id -->
2019 ################################################################################
2020 #
2021 # ==== _token_context ==== #####################################################
2022 #
2023 # Arguments:
2024 # 1) PML::Token Object
2025 # 2) New Context ID (Optional)
2026 #
2027 # Returns:
2028 # Current Context ID
2029 #
2030 # Description:
2031 # Sets the Context ID if given, then returns the context ID
2032 #
2033 ################################################################################
2034 sub _token_context
2035 191 ▶{
Subroutine _token_context: called CC=5 SCAR=17.5
2036 191 my ($token, $context) = @_;
2037
2038 191 ▶ if (defined $context) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) 148 43 191
2039 148 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($context == 1 or $context == 2) 0 148 148
Condition66%2/3
$context == 1 or $context == 2
l!l&&r!l&&!r
451030
MC/DC0%0/2
$context == 1 or $context == 2
$context == 1 $context == 2
Truth table66%2/3
A or B
A= $context == 1B= $context == 2
ABresult
1X1
011
000
2040 $context == CONTEXT_SCALAR ||
2041 $context == CONTEXT_LIST
2042 ) {
2043 0 carp "context not scalar or array";
2044 0 return $token->[PML_TOKEN_CONTEXT];
2045 }
2046
2047 148 $token->[PML_TOKEN_CONTEXT] = $context;
2048 }
2049
2050 191 ▶ return $token->[PML_TOKEN_CONTEXT] || CONTEXT_SCALAR;
Condition50%1/2
$token->[1] || 1
l!l
1910
MC/DC0%0/1
$token->[1] || 1
$token->[1]
Truth table50%1/2
A
A= $token->[1]
Aresult
11
00
2051 } # <-- End _token_context -->
2052 ################################################################################
2053 #
2054 # ==== _token_file_loc ==== ####################################################
2055 #
2056 # Arguments:
2057 # 1) PML::Token Object
2058 # 2) New File Location ID (Optional)
2059 #
2060 # Returns:
2061 # File Location ID
2062 #
2063 # Description:
2064 # Sets the File Location ID if given, then returns the FLI
2065 #
2066 ################################################################################
2067 sub _token_file_loc
2068 371 ▶{
Subroutine _token_file_loc: called CC=5 SCAR=17.3
2069 371 my ($token, $fli) = @_;
2070
2071 371 ▶ if (defined $fli) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fli) 148 223 371
2072 148 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($fli == 0 or $fli == 1 or $fli == 2) 0 148 148
Condition66%4/6
$fli == 0 or $fli == 1 or $fli == 2
l!l&&r!l&&!r
103450
$fli == 0 or $fli == 1
l!l&&r!l&&!r
010345
MC/DC0%0/3
$fli == 0 or $fli == 1 or $fli == 2
$fli == 0 $fli == 1 $fli == 2
Truth table50%2/4
A or B or C
A= $fli == 0B= $fli == 1C= $fli == 2
ABCresult
1XX1
01X1
0011
0000
2073 $fli == FILE_LOC_FILE or
2074 $fli == FILE_LOC_ARG or
2075 $fli == FILE_LOC_BLOCK
2076 ) { # then
2077 0 carp "file location id is not file, arg or block";
2078 0 return $token->[PML_TOKEN_FILE_LOC];
2079 }
2080
2081 148 $token->[PML_TOKEN_FILE_LOC] = $fli;
2082 }
2083
2084 371 return $token->[PML_TOKEN_FILE_LOC];
2085 } # <-- End _token_file_loc -->
2086 ################################################################################
2087 #
2088 # ==== _token_data ==== ########################################################
2089 #
2090 # Arguments:
2091 # 1) PML::Token Object
2092 # 2) Data (optional)
2093 #
2094 # Returns:
2095 # Data
2096 #
2097 # Description:
2098 # Sets the data section to whatever you give, or returns it
2099 #
2100 ################################################################################
2101 sub _token_data
2102 656 ▶{
Subroutine _token_data: called CC=2 SCAR=6.9
2103 656 my ($token, $data) = (shift, shift);
2104
2105 656 ▶ if (defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) 312 344 656
2106 312 $token->[PML_TOKEN_DATA] = $data;
2107 }
2108
2109 656 return $token->[PML_TOKEN_DATA];
2110 } # <-- End _token_data -->
2111 ################################################################################
2112 #
2113 # ==== _token_label ==== #######################################################
2114 #
2115 # Arguments:
2116 # 1) PML::Token Object
2117 # 2) Label (optional)
2118 #
2119 # Returns:
2120 # The current label
2121 #
2122 # Description:
2123 # Sets the label if one is given, return the label
2124 #
2125 ################################################################################
2126 sub _token_label
2127 3 ▶{
Subroutine _token_label: called CC=2 SCAR=6.9
2128 3 my ($token, $label) = @_;
2129
2130 3 ▶ if (defined $label) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $label) 1 2 3
2131 1 $token->[PML_TOKEN_LABEL] = $label;
2132 }
2133
2134 3 return $token->[PML_TOKEN_LABEL];
2135 } # <-- End _token_label -->
2136 ################################################################################
2137 #
2138 # ==== object_directory ==== ###################################################
2139 #
2140 # Arguments:
2141 # 1) A PML Variable
2142 # 2) A directory to place objects (optional)
2143 #
2144 # Returns:
2145 # Current directory
2146 #
2147 # Description:
2148 # Sets the object directory if given then returns the object directory
2149 #
2150 ################################################################################
2151 sub object_directory
2152 0 ▶{
Subroutine object_directory: not called CC=4 SCAR=30.0
Pod undocumented
2153 0 my ($self, $dir) = @_;
2154
2155 0 ▶ if (defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 0 0 0
2156 0 ▶ unless (-d $dir) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $dir) { } 0 0 0
if (do { -w $dir }) { } 0 0 0
2157 0 carp "directory '$dir' does not exists\n";
2158 } elsif (-w $dir) {
2159 0 carp "you don't have permission to write into '$dir'\n";
2160 } else {
2161 0 $self->[PML_OBJ_DIR] = $dir;
2162 }
2163 }
2164
2165 0 return $self->[PML_OBJ_DIR];
2166 } # <-- End object_directory -->
2167 ################################################################################
2168 #
2169 # B U I L T -- I N -- F U N C T I O N S
2170 # ------------------------------------
2171 #
2172 #
2173 # All built in functions take the following arguments
2174 #
2175 # 1) A PML Object
2176 # 2) A Reference to an array of argument tokens
2177 # 3) A Reference to an array of block tokens
2178 # 4) A Reference to a line (if you need to get more stuff from file)
2179 # 5) A Reference to an array of lines, in case you need more data
2180 # from the file. This argument is optional and should default
2181 # to $self->[PML_LINES];
2182 #
2183 ################################################################################
2184 #
2185 # ==== auto_parse ==== #########################################################
2186 #
2187 # Arguments:
2188 # See Above, but in addition to that :
2189 # 1) The name of the function
2190 # 2) The Token ID of the function
2191 #
2192 # Returns:
2193 # A Token
2194 #
2195 # Description:
2196 # Auto Parse is a parser for function that do not provide a parser for
2197 # themselves. It just makes a generic token, no syntax checking is done.
2198 #
2199 ################################################################################
2200 sub auto_parse
2201 8 ▶{
Subroutine auto_parse: called CC=1 SCAR=0.0
Pod undocumented
2202 8 my ($self, $a, $b, $line_ref, $lines) = @_;
2203 8 my ($options, $name, $id, $token);
2204
2205 8 $options = pop @_;
2206 8 $id = $options->{id};
2207 8 $name = $options->{name};
2208
2209 8 $token = new PML::Token $id;
2210 8 $token->data([$name, $a, $b]);
2211
2212 8 return $token;
2213 } # <-- End auto_parse -->
2214 ################################################################################
2215 #
2216 # ==== parse_if ==== ###########################################################
2217 #
2218 # Arguments:
2219 # See Above
2220 #
2221 # Returns:
2222 # A List of tokens
2223 #
2224 # Description:
2225 # Builds tokens needed for an IF statement (function)
2226 # removes elsif and else statments as needed from the file
2227 #
2228 ################################################################################
2229 sub parse_if
2230 16 ▶{
Subroutine parse_if: called CC=7 SCAR=19.6
Pod undocumented
2231 16 my ($self, $a, $b, $line_ref, $lines, $unless) = @_;
2232 16 my (@tokens, $regex, $token);
2233
2234 # prepare the regex for speed
2235 16 $regex = G_RE_IF;
2236
2237 # make sure we only have one condition
2238 16 ▶ if ($#{$a} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$a;} > 1) { } 0 16 16
2239 0 $self->error_syntax
2240 ("you can only have one condition to a if function");
2241 } else {
2242 16 $a = $a->[0];
2243 }
2244
2245 # check to see if this is a @if or @unless
2246 16 ▶ if ($unless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unless) { } 3 13 16
2247 # push a unless token
2248 3 $token = new PML::Token TOKEN_NOT;
2249 3 $token->data($a);
2250 3 push @tokens, $token, $b;
2251 } else {
2252 # add the if token
2253 13 push @tokens, $a, $b;
2254 }
2255
2256 # look for else or elsif functions
2257 16 ▶ while ($self->peek($regex, $line_ref, $lines)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->peek($regex, $line_ref, $lines)) 10 10 20
2258 # remove all dead space before the @ marker
2259 10 $self->magic_newline($line_ref, $lines);
2260
2261 # remove the @ marker and either the 'else' or 'elsif'
2262 # leaving $1 set to 'else' or 'elsif'
2263 10 $$line_ref =~ s/$regex//o;
2264
2265 # handle the elsif and else
2266 10 ▶ if ($1 eq 'elsif') {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq 'elsif') { } 4 6 10
elsif ($1 eq 'else') { } 6 0 6
2267 4 my $elsif_a =
2268 [$self->parse_arguments($line_ref, $lines)];
2269 4 ▶ if (@{$elsif_a} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$elsif_a;} > 1) 0 4 4
2270 0 $self->error_syntax
2271 ("you are only allowed to give one condition to elsif");
2272 }
2273
2274 4 push @tokens,
2275 $elsif_a->[0],
2276 [$self->parse_block($line_ref, $lines)];
2277 } elsif ($1 eq 'else') {
2278 6 $token = new PML::Token TOKEN_EVAL;
2279 6 $token->data(1);
2280 6 push @tokens,
2281 $token,
2282 [$self->parse_block($line_ref, $lines)];
2283 6 last; # nothing allowed after the else
2284 }
2285 }
2286
2287 16 $token = new PML::Token TOKEN_IF;
2288 16 $token->data(\@tokens);
2289 16 return $token;
2290 } # <-- End parse_if -->
2291 ################################################################################
2292 #
2293 # ==== parse_perl ==== #########################################################
2294 #
2295 # Arguments:
2296 # 1) A PML Object
2297 # 2) The charters between the { and the } after a @perl
2298 #
2299 # Returns:
2300 # 1 Token
2301 #
2302 # Description:
2303 # Just grabs the perl code and puts it into a token.
2304 # This parse function is special because the arguments and block
2305 # are not parsed for it. Thus $a and $b are undef
2306 #
2307 ################################################################################
2308 sub parse_perl
2309 8 ▶{
Subroutine parse_perl: called CC=1 SCAR=0.0
Pod undocumented
2310 8 my ($self, $code) = @_;
2311 8 my $token = new PML::Token TOKEN_PERL;
2312
2313 8 $token->data($code);
2314 8 return $token;
2315 } # <-- End parse_perl -->
2316 ################################################################################
2317 #
2318 # ==== parse_set ==== ##########################################################
2319 #
2320 # Arguments:
2321 # See Above
2322 # A TOKEN_SET_* token id
2323 #
2324 # Returns:
2325 # A Token
2326 #
2327 # Description:
2328 # Sets the variable to the give value(s)
2329 #
2330 ################################################################################
2331 sub parse_set
2332 23 ▶{
Subroutine parse_set: called CC=2 SCAR=7.1
Pod undocumented
2333 23 my ($self, $a, $b, $line_ref, $lines, $set) = @_;
2334 23 my $token;
2335
2336 # make sure that we were given a variable name to set
2337 23 ▶ unless (defined $a->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $a->[0]) 0 23 23
2338 0 $self->error_syntax(
2339 "you must give a variable name to set"
2340 );
2341 }
2342
2343 23 $token = new PML::Token TOKEN_SET;
2344 23 $token->data([$set, @$a]);
2345 23 return $token;
2346 } # <-- End parse_set -->
2347 ################################################################################
2348 #
2349 # ==== parse_include ==== ######################################################
2350 #
2351 # Arguments:
2352 # See Above
2353 #
2354 # Returns:
2355 # Tokens
2356 #
2357 # Description:
2358 # Returns a include token after parsing a file and keeping it's tokens
2359 #
2360 ################################################################################
2361 sub parse_include
2362 1 ▶{
Subroutine parse_include: called CC=15 SCAR=37.3
Pod undocumented
2363 1 my ($self, $a, $b, $line_ref, $lines) = @_;
2364 1 my @args = $self->tokens_execute($a);
2365 1 my ($found, @tokens, $token);
2366
2367 1 ▶ unless (@args)
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 1 1
2368 {
2369 0 $self->error("syntax error, the include function needs a list of files to include.\n");
2370 }
2371
2372 1 foreach my $file (@args)
2373 {
2374 1 $found = 0;
2375
2376 1 ▶ unless ($file =~ m{^(?:\.(?:\./|/)|/)}o)
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[^(?:\.(?:\./|/)|/)]o) { } 0 1 1
2377 {
2378 1 foreach my $path (@inc)
2379 {
2380 1 ▶ if (-e "$path/$file")
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$path/$file") 1 0 1
2381 {
2382 1 $found = 1;
2383 1 $file = "$path/$file";
2384 1 last;
2385 }
2386 }
2387 }
2388 else
2389 {
2390 0 ▶ if (-e $file)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
2391 {
2392 0 $found = 1;
2393 0 ▶ $file = rel2abs($file) unless $file =~ m(^/)o;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ m[^/]o 0 0 0
2394 }
2395 }
2396
2397 1 ▶ unless ($found)
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 1 1
2398 {
2399 0 $self->error("can't find included file \"$file\". inc contains ". join(' ', @inc). "\n");
2400 }
2401
2402 1 my $inc_parser = new PML;
2403 1 $inc_parser->parse($file);
2404
2405 1 ▶ if ($DEBUG)
Branch: 1 branch
BranchTrueFalseTotal
if ($PML::DEBUG) 0 1 1
2406 {
2407 0 print STDERR "Including file $file\n";
2408 0 print STDERR "Before including $file the macro list is:\n";
2409 0 print STDERR "\t$_\n" foreach sort keys %{$self->[PML_MACROS]};
2410 0 print STDERR "Before including $file the includes list is:\n";
2411 0 print STDERR "\t$_\n" foreach sort keys %{$self->[PML_INCLUDES]};
2412 }
2413  
2414 1 $self->[PML_INCLUDES]{$file} = $inc_parser->[PML_TOKENS];
2415 1 $self->append($inc_parser);
2416
2417 1 ▶ if ($DEBUG)
Branch: 1 branch
BranchTrueFalseTotal
if ($PML::DEBUG) 0 1 1
2418 {
2419 0 print STDERR "After including $file the macro list is:\n";
2420 0 print STDERR "\t$_\n" foreach sort keys %{$self->[PML_MACROS]};
2421 0 print STDERR "After including $file the includes list is:\n";
2422 0 print STDERR "\t$_\n" foreach sort keys %{$self->[PML_INCLUDES]};
2423 }
2424
2425 1 push(@tokens, $file);
2426 }
2427
2428 1 $token = new PML::Token TOKEN_INCLUDE;
2429 1 $token->data(\@tokens);
2430 1 return $token;
2431 } # <-- End parse_include -->
2432 ################################################################################
2433 #
2434 # ==== parse_macro ==== ########################################################
2435 #
2436 # Arguments:
2437 # See Above
2438 #
2439 # Returns:
2440 # A Token
2441 #
2442 # Description:
2443 # Sets a MACRO_TOKEN
2444 #
2445 ################################################################################
2446 sub parse_macro
2447 5 ▶{
Subroutine parse_macro: called CC=4 SCAR=16.1
Pod undocumented
2448 5 my ($self, $a, $b, $line_ref, $lines) = @_;
2449
2450 5 ▶ unless (defined $a->[0])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $a->[0]) 0 5 5
2451 {
2452 0 $self->error("syntax Error, you must give the name of the macro\n");
2453 }
2454
2455 5 my $name = $self->tokens_execute(shift @$a);
2456
2457 5 ▶ if (exists $self->[PML_MACROS]{$name} and $self->[PML_W])
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->[13]{$name} and $self->[6]) 0 5 5
Condition33%1/3
exists $self->[13]{$name} and $self->[6]
!ll&&!rl&&r
500
MC/DC0%0/2
exists $self->[13]{$name} and $self->[6]
exists $self->[13]{$name} $self->[6]
Truth table33%1/3
A and B
A= exists $self->[13]{$name}B= $self->[6]
ABresult
0X0
100
111
2458 {
2459 0 print STDERR "Macro \"$name\" was redfined ", $self->[PML_LINE_STR], "\n";
2460 }
2461
2462 5 $self->[PML_MACROS]{$name} = [$a, $b];
2463 5 return undef;
2464 } # <-- End parse_macro -->
2465 ################################################################################
2466 #
2467 # ==== parse_warning ==== ######################################################
2468 #
2469 # Arguments:
2470 # See Above
2471 #
2472 # Returns:
2473 # None
2474 #
2475 # Description:
2476 # Changes the warning flag
2477 #
2478 ################################################################################
2479 sub parse_warning
2480 2 ▶{
Subroutine parse_warning: called CC=3 SCAR=12.0
Pod undocumented
2481 2 my ($self, $a, $b, $line_ref, $lines) = @_;
2482
2483 2 ▶ unless (@$a == 1)
Branch: 1 branch
BranchTrueFalseTotal
unless (@$a == 1) 0 2 2
2484 {
2485 0 $self->error("syntax error, you must give one boolean flag to the warning function.\n");
2486 }
2487
2488 2 ▶ $self->warning($self->tokens_execute($a->[0]) || 0);
Condition50%1/2
$self->tokens_execute($a->[0]) || 0
l!l
20
MC/DC0%0/1
$self->tokens_execute($a->[0]) || 0
$self->tokens_execute($a->[0])
Truth table50%1/2
A
A= $self->tokens_execute($a->[0])
Aresult
11
00
2489 2 return undef;
2490 } # <-- End parse_warning -->
2491 ################################################################################
2492 #
2493 # ==== parse_foreach ==== ######################################################
2494 #
2495 # Arguments:
2496 # See Above
2497 #
2498 # Returns:
2499 # A FOREACH_TOKEN
2500 #
2501 # Description:
2502 # Parses the foreach pml function
2503 #
2504 ################################################################################
2505 sub parse_foreach
2506 2 ▶{
Subroutine parse_foreach: called CC=2 SCAR=7.1
Pod undocumented
2507 2 my ($self, $a, $b, $line_ref, $lines) = @_;
2508 2 my $token;
2509
2510 2 ▶ unless (@$a)
Branch: 1 branch
BranchTrueFalseTotal
unless (@$a) 0 2 2
2511 {
2512 0 $self->error("syntax error, you need to give some arguments to the foreach function.\n");
2513 }
2514
2515 2 $token = new PML::Token TOKEN_FOREACH;
2516 2 $token->data([$a, $b]);
2517 2 return $token;
2518 } # <-- End parse_foreach -->
2519 ################################################################################
2520 #
2521 # ==== parse_need ==== #########################################################
2522 #
2523 # Arguments:
2524 # See Above
2525 #
2526 # Returns:
2527 # None
2528 #
2529 # Description:
2530 # Loads the modules that need to be loaded, if the are not alread loaded
2531 #
2532 ################################################################################
2533 sub parse_need
2534 1 ▶{
Subroutine parse_need: called CC=5 SCAR=17.6
Pod undocumented
2535 1 my ($self, $a, $b, $line_ref, $lines) = @_;
2536 1 my @modules = $self->tokens_execute($a);
2537
2538 1 foreach (@modules)
2539 {
2540 1 push @{$self->[PML_NEED_LIST]}, $_;
2541 1 eval "require PML::" . $_;
2542
2543 1 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
2544 {
2545 0 $self->error("error loading module \"$_\", make sure you entered it correctly");
2546 }
2547
2548 1 eval "PML::" . $_ . "->init(\$self)";
2549
2550 1 ▶ if ($DEBUG and $@)
Branch: 1 branch
BranchTrueFalseTotal
if ($PML::DEBUG and $@) 0 1 1
Condition33%1/3
$PML::DEBUG and $@
!ll&&!rl&&r
100
MC/DC0%0/2
$PML::DEBUG and $@
$PML::DEBUG $@
Truth table33%1/3
A and B
A= $PML::DEBUGB= $@
ABresult
0X0
100
111
2551 {
2552 0 print STDERR "error from PML::$_->init: $@\n";
2553 }
2554 }
2555
2556 1 return undef;
2557 } # <-- End parse_need -->
2558 ################################################################################
2559 #
2560 # ==== parse_while ==== ########################################################
2561 #
2562 # Arguments:
2563 # See Above
2564 #
2565 # Returns:
2566 # Tokens
2567 #
2568 # Description:
2569 # The while and until functions
2570 #
2571 ################################################################################
2572 sub parse_while
2573 3 ▶{
Subroutine parse_while: called CC=3 SCAR=11.0
Pod undocumented
2574 3 my ($self, $a, $b, $line_ref, $lines, $until) = @_;
2575 3 my (@tokens, $token);
2576
2577 # check to make sure there no more then one condition
2578 3 ▶ if (@{$a} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$a;} > 1) { } 0 3 3
2579 0 error_syntax("you can only supply one condition to the while/until function");
2580 } else {
2581 3 $a = $a->[0];
2582 }
2583
2584 # create the token, negate the condition if this is until
2585 3 ▶ if ($until) {
Branch: 1 branch
BranchTrueFalseTotal
if ($until) { } 1 2 3
2586 1 $token = new PML::Token TOKEN_NOT;
2587 1 $token->data($a);
2588 1 push @tokens, $token, $b;
2589 } else {
2590 2 push @tokens, $a, $b;
2591 }
2592
2593 3 $token = new PML::Token TOKEN_WHILE;
2594 3 $token->data(\@tokens);
2595 3 return $token;
2596 } # <-- End parse_while -->
2597 ################################################################################
2598 #
2599 # ==== parse_skip ==== #########################################################
2600 #
2601 # 1) A PML Object
2602 # 2) The charters between the { and the } after a @perl
2603 #
2604 # Returns:
2605 # 1 Token
2606 #
2607 # Description:
2608 # Keeps PML from parsing any text in the skip block
2609 #
2610 ################################################################################
2611 sub parse_skip
2612 1 ▶{
Subroutine parse_skip: called CC=1 SCAR=0.0
Pod undocumented
2613 1 my ($self, $skip) = @_;
2614 1 my $token = new PML::Token TOKEN_SKIP;
2615
2616 1 $token->data($skip);
2617 1 return $token;
2618 } # <-- End parse_skip -->
2619 ################################################################################
2620 #
2621 # ==== parse_wrap ==== #########################################################
2622 #
2623 # Arguments:
2624 # See Above
2625 #
2626 # Returns:
2627 # A wrap token
2628 #
2629 # Description:
2630 # Wraps text to a certain number of chars per line
2631 #
2632 ################################################################################
2633 sub parse_wrap
2634 0 ▶{
Subroutine parse_wrap: not called CC=5 SCAR=34.0
Pod undocumented
2635 0 my ($self, $a, $b, $line_ref, $lines) = @_;
2636 0 my $token = new PML::Token TOKEN_WRAP;
2637
2638 0 ▶ unless (@$a <= 3) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$a <= 3) 0 0 0
2639 0 $self->error_syntax (
2640 "wrap function only takes 3 arguments"
2641 );
2642 }
2643
2644 0 ▶ $token->data([$a->[0]||80, $a->[1]||'', $a->[2]||'', $b]);
Condition0%0/6
$a->[0] || 80
l!l
00
$a->[1] || ''
l!l
00
$a->[2] || ''
l!l
00
MC/DC0%0/1
$a->[0] || 80
$a->[0]
MC/DC0%0/1
$a->[1] || ''
$a->[1]
MC/DC0%0/1
$a->[2] || ''
$a->[2]
Truth table0%0/2
A
A= $a->[0]
Aresult
11
00
Truth table0%0/2
A
A= $a->[1]
Aresult
11
00
Truth table0%0/2
A
A= $a->[2]
Aresult
11
00
2645 0 return $token;
2646 } # <-- End parse_wrap -->
2647 ################################################################################
2648 #
2649 # ==== parse_rib ==== ##########################################################
2650 #
2651 # Arguments:
2652 # See Above
2653 #
2654 # Returns:
2655 # A rib token
2656 #
2657 # Description:
2658 # Parses the rib function
2659 #
2660 ################################################################################
2661 sub parse_rib
2662 4 ▶{
Subroutine parse_rib: called CC=2 SCAR=7.2
Pod undocumented
2663 4 my ($self, $a, $b, $line_ref, $lines) = @_;
2664 4 my $token = new PML::Token TOKEN_RIB;
2665
2666 4 ▶ unless (@$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$a == 1) 0 4 4
2667 0 $self->error_syntax (
2668 "the rib function needs one argument"
2669 );
2670 }
2671
2672 4 $token->data([$a->[0], $b]);
2673 4 return $token;
2674 } # <-- End parse_rib -->
2675 ################################################################################
2676 #
2677 # ==== parse_loop_int ==== #####################################################
2678 #
2679 # Arguments:
2680 # See Above
2681 #
2682 # Returns:
2683 # A Token
2684 #
2685 # Description:
2686 # Creates a token for @next, @last and @redo
2687 #
2688 ################################################################################
2689 sub parse_loop_int
2690 1 ▶{
Subroutine parse_loop_int: called CC=3 SCAR=11.8
Pod undocumented
2691 1 my ($self, $a, $b, $line_ref, $lines, $name) = @_;
2692 1 my $token = new PML::Token TOKEN_LOOP_INT;
2693
2694 # make sure that we are only getting one label
2695 1 ▶ if (@$a > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$a > 1) 0 1 1
2696 0 $self->error_syntax("you can only give one label to $name");
2697 }
2698
2699 # set the data to be the name (next,redo or last) and the label ($a)
2700 1 ▶ $token->data([$name, $a->[0] || '']);
Condition50%1/2
$a->[0] || ''
l!l
01
MC/DC0%0/1
$a->[0] || ''
$a->[0]
Truth table50%1/2
A
A= $a->[0]
Aresult
11
00
2701
2702 1 return $token;
2703 } # <-- End parse_loop_int -->
2704 ################################################################################
2705 #
2706 # B U I L T -- I N -- T O K E N S
2707 # ------------------------------------
2708 #
2709 #
2710 # All built in tokens take the following arguments
2711 #
2712 # 1) A PML Object
2713 # 2) A PML::Token Object
2714 #
2715 ################################################################################
2716 #
2717 # ==== token_eval ==== #########################################################
2718 #
2719 # Arguments:
2720 # See Above
2721 #
2722 # Returns:
2723 # A String
2724 #
2725 # Description:
2726 # Replaces all variables in the string and returns it
2727 #
2728 ################################################################################
2729 sub token_eval
2730 223 ▶{
Subroutine token_eval: called CC=7 SCAR=19.7
Pod undocumented
2731 223 my ($self, $token) = @_;
2732 223 my $string = $token->data;
2733 223 my $result = '';
2734
2735 # check to make sure that we have a string
2736 223 ▶ return undef unless defined $string and length($string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string and length $string 0 223 223
Condition33%1/3
defined $string and length $string
!ll&&!rl&&r
00223
MC/DC0%0/2
defined $string and length $string
defined $string length $string
Truth table33%1/3
A and B
A= defined $stringB= length $string
ABresult
0X0
100
111
2737
2738 # replace variable names with the value
2739 223 ▶ while ($string =~ s/^$RE_VAR_TEST//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^$RE_VAR_TEST//o) 40 223 263
2740 40 ▶ $result .= $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 16 24 40
2741 40 $result .= $self->replace_variable(\$string);
2742 }
2743
2744 # if we found none then set the result to the string
2745 223 ▶ $result .= $string if length $string;
Branch: 1 branch
BranchTrueFalseTotal
if length $string 209 14 223
2746
2747 # replace backslashed charaters with their actual ASCII codes
2748 0 $result =~ s/(?<!\\)\\(0\d+|c\w|x\w+|[nrtfbaeulULQE])/"\"\\$1\""/oeeg;
2749
2750 # Remove some tabs if asked
2751 223 $result =~ s/[\t]+\\T//og;
2752
2753 # remove any remaining backslashes unless we are processing
2754 # the arguments of a function call. If that is the case
2755 # we will surly get another change to remove the backslash
2756 # when charater is used in the block or body.
2757 223 ▶ $result =~ s/(?<!\\)\\//og unless $token->file_loc == FILE_LOC_ARG;
Branch: 1 branch
BranchTrueFalseTotal
unless $token->file_loc == 1 135 88 223
2758
2759 # and return the result
2760 223 return $result;
2761 } # <-- End token_eval -->
2762 ################################################################################
2763 #
2764 # ==== token_if ==== ###########################################################
2765 #
2766 # Arguments:
2767 # See Above
2768 #
2769 # Returns:
2770 # Whatever is in the if block or elsif block or else block
2771 #
2772 # Description:
2773 # Check to see if the args are true then executes the correct tokens
2774 #
2775 ################################################################################
2776 sub token_if
2777 16 ▶{
Subroutine token_if: called CC=4 SCAR=14.1
Pod undocumented
2778 16 my ($self, $token) = @_;
2779 16 my (@tokens) = @{$token->data};
2780 16 my ($a, $b, $rv, $tmp);
2781
2782 #
2783 # now loop trying to execute a block of PML
2784 #
2785 16 while(1)
2786 {
2787 #
2788 # check to make sure there are at least two tokens
2789 #
2790 21 ▶ last unless @tokens >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens >= 2 0 21 21
2791
2792 #
2793 # get the argument and block tokens from the tokens array
2794 #
2795 21 ($a, $b, @tokens) = @tokens;
2796
2797 #
2798 # check to see if this token return a true value
2799 #
2800 21 ▶ if ($self->tokens_execute($a))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tokens_execute($a)) 16 5 21
2801 {
2802 # if we get here then we get to execute
2803 # the block and return what it returns
2804 16 ▶ return $self->tokens_execute($b) || undef;
Condition50%1/2
$self->tokens_execute($b) || undef
l!l
160
MC/DC0%0/1
$self->tokens_execute($b) || undef
$self->tokens_execute($b)
Truth table50%1/2
A
A= $self->tokens_execute($b)
Aresult
11
00
2805
2806 #foreach my $token (@$b)
2807 #{
2808 # $tmp = $self->token_execute($token);
2809 # $rv .= $tmp if defined $tmp;
2810 #}
2811
2812 #return $rv;
2813 }
2814 }
2815
2816 #
2817 # if we get this far there were no succesfull tokens
2818 #
2819 0 return undef;
2820 } # <-- End token_if -->
2821 ################################################################################
2822 #
2823 # ==== token_not ==== ##########################################################
2824 #
2825 # Arguments:
2826 # See Above
2827 #
2828 # Returns:
2829 # The inverse of the inner token
2830 #
2831 # Description:
2832 # This token comes with one other token to execute
2833 # The unless token returns the inverse of executing that token
2834 #
2835 ################################################################################
2836 sub token_not
2837 11 ▶{
Subroutine token_not: called CC=1 SCAR=0.0
Pod undocumented
2838 11 my ($self, $token) = @_;
2839 11 return not scalar $self->tokens_execute($token->data);
2840 } # <-- End token_not -->
2841 ################################################################################
2842 #
2843 # ==== token_perl ==== #########################################################
2844 #
2845 # Arguments:
2846 # See Above
2847 #
2848 # Returns:
2849 # What ever is the last value in the perl code
2850 #
2851 # Description:
2852 # Evals the perl code and returns it
2853 #
2854 ################################################################################
2855 sub token_perl
2856 20 ▶{
Subroutine token_perl: called CC=4 SCAR=14.1
Pod undocumented
2857 20 my ($self, $token) = @_;
2858 20 my %v = %{$self->[PML_V]};
2859 20 my $code = $token->data;
2860 20 my @rv;
2861
2862 20 @rv = eval "$code";
2863
2864 20 ▶ if ($@ and $self->warning) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and $self->warning) 0 20 20
Condition33%1/3
$@ and $self->warning
!ll&&!rl&&r
2000
MC/DC0%0/2
$@ and $self->warning
$@ $self->warning
Truth table33%1/3
A and B
A= $@B= $self->warning
ABresult
0X0
100
111
2865 0 print STDERR "An error occured in your perl code: $@\n";
2866 }
2867
2868 20 %{$self->[PML_V]} = %v;
2869
2870 20 local $^W=0; # bug in perl? next line causes "Use of uninitialized value at PML.pm"
2871 20 ▶ if ($token->context == CONTEXT_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->context == 2) { } 3 17 20
2872 3 return @rv;
2873 } else {
2874 17 return join '', @rv;
2875 }
2876 } # <-- End token_perl -->
2877 ################################################################################
2878 #
2879 # ==== token_set ==== ##########################################################
2880 #
2881 # Arguments:
2882 # See Above
2883 #
2884 # Returns:
2885 # None
2886 #
2887 # Description:
2888 # Sets the variable to the value(s) in the token(s)
2889 #
2890 ################################################################################
2891 sub token_set
2892 25 ▶{
Subroutine token_set: called CC=36 SCAR=55.5
Pod undocumented
2893 25 my ($self, $token) = @_;
2894 25 my ($sub_token, $v, @values) = @{$token->data};
2895 25 my ($array, $hash, $index, $ref, $i);
2896
2897 25 $v = $self->tokens_execute($v);
2898
2899 # reject the variable name if it does not match
2900 # the standard variable naming procedures
2901 25 ▶ if ($v !~ /^$RE_VAR/o or $v =~ /[\$\{\}]/o or $v =~ /^(\.|ARGV)$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $v =~ /^$RE_VAR/o or $v =~ /[\$\{\}]/o or $v =~ /^(\.|ARGV)$/o) 0 25 25
Condition33%2/6
not $v =~ /^$RE_VAR/o or $v =~ /[\$\{\}]/o or $v =~ /^(\.|ARGV)$/o
l!l&&r!l&&!r
0025
not $v =~ /^$RE_VAR/o or $v =~ /[\$\{\}]/o
l!l&&r!l&&!r
0025
MC/DC0%0/3
not $v =~ /^$RE_VAR/o or $v =~ /[\$\{\}]/o or $v =~ /^(\.|ARGV)$/o
not $v =~ /^$RE_VAR/o $v =~ /[\$\{\}]/o $v =~ /^(\.|ARGV)$/o
Truth table25%1/4
not(A) or B or C
A= not $v =~ /^$RE_VAR/oB= $v =~ /[\$\{\}]/oC= $v =~ /^(\.|ARGV)$/o
ABCresult
1XX1
01X1
0011
0000
2902 0 print STDERR "The variable name '$v' contains illeagal charaters\n";
2903 0 croak("bad variable name");
2904 }
2905
2906 # execute the tokens and get the real data
2907 25 @values = $self->tokens_execute(@values);
2908
2909 25 ▶ if ($v =~ /^(.*?)\[(\d+)\]$/o) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v =~ /^(.*?)\[(\d+)\]$/o) { } 0 25 25
elsif ($v =~ /^([^\.]+)\.([^\.]+)$/o) { } 0 25 25
2910 0 $array = $1; $index = $2;
2911
2912 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{$array} and ref $self->[0]{$array} ne "ARRAY") 0 0 0
Condition0%0/3
defined $self->[0]{$array} and ref $self->[0]{$array} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[0]{$array} and ref $self->[0]{$array} ne "ARRAY"
defined $self->[0]{$array} ref $self->[0]{$array} ne "ARRAY"
Truth table0%0/3
A and B
A= defined $self->[0]{$array}B= ref $self->[0]{$array} ne "ARRAY"
ABresult
0X0
100
111
2913 defined $self->[PML_V]{$array} and
2914 ref($self->[PML_V]{$array}) ne 'ARRAY'
2915 ) {
2916 0 print STDERR "pml does not support complexe data structures, but you tried to set one\n";
2917 0 return undef;
2918 }
2919
2920 0 $ref = \$self->[PML_V]{$array}[$index];
2921 } elsif ($v =~ /^([^\.]+)\.([^\.]+)$/o) {
2922 0 $hash = $1; $index = $2;
2923  
2924 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{$hash} and ref $self->[0]{$hash} ne "HASH") 0 0 0
Condition0%0/3
defined $self->[0]{$hash} and ref $self->[0]{$hash} ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[0]{$hash} and ref $self->[0]{$hash} ne "HASH"
defined $self->[0]{$hash} ref $self->[0]{$hash} ne "HASH"
Truth table0%0/3
A and B
A= defined $self->[0]{$hash}B= ref $self->[0]{$hash} ne "HASH"
ABresult
0X0
100
111
2925 defined $self->[PML_V]{$hash} and
2926 ref($self->[PML_V]{$hash}) ne 'HASH'
2927 ) {
2928 0 print STDERR "pml does not support complexe data structures, but you tried to set one\n";
2929 0 return undef;
2930 }
2931
2932 0 $ref = \$self->[PML_V]{$hash}{$index};
2933 } else {
2934 25 ▶ $self->[PML_V]{$v} = '' unless exists $self->[PML_V]{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->[0]{$v} 16 9 25
2935 25 $ref = \$self->[PML_V]{$v};
2936 }
2937
2938 25 ▶ if ($sub_token == TOKEN_SET_SET) {
Branch: 5 branches
BranchTrueFalseTotal
if ($sub_token == 1) { } 20 5 25
elsif ($sub_token == 2) { } 3 2 5
elsif ($sub_token == 3) { } 1 1 2
elsif ($sub_token == 4) { } 1 0 1
elsif ($sub_token == 5) { } 0 0 0
2939 20 ▶ if (@values > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values > 1) { } 3 17 20
2940 3 ▶ if ($array or $hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array or $hash) { } 0 3 3
Condition33%1/3
$array or $hash
l!l&&r!l&&!r
003
MC/DC0%0/2
$array or $hash
$array $hash
Truth table33%1/3
A or B
A= $arrayB= $hash
ABresult
1X1
011
000
2941 0 print STDERR "you can only assign one value to a array index or hash key\n";
2942 0 $$ref = $values[-1];
2943 } else {
2944 3 $self->[PML_V]{$v} = [@values];
2945 }
2946 } else {
2947 17 $$ref = $values[0];
2948 }
2949 } elsif ($sub_token == TOKEN_SET_IF) {
2950 3 ▶ return undef if defined $ref and $$ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref and $$ref 2 1 3
Condition66%2/3
defined $ref and $$ref
!ll&&!rl&&r
012
MC/DC50%1/2
defined $ref and $$ref
defined $ref $$ref
Truth table66%2/3
A and B
A= defined $refB= $$ref
ABresult
0X0
100
111
2951 1 $token = new PML::Token TOKEN_SET;
2952 1 $token->data([TOKEN_SET_SET, $v, @values]);
2953 1 $self->token_set($token);
2954 } elsif ($sub_token == TOKEN_SET_APPEND) {
2955 1 ▶ if (not $array and not $hash and ref $self->[PML_V]{$v} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $array || $hash and ref $self->[0]{$v} eq 'ARRAY') { } 0 1 1
Condition33%2/6
not $array || $hash and ref $self->[0]{$v} eq "ARRAY"
!ll&&!rl&&r
010
$array || $hash
l!l&&r!l&&!r
001
MC/DC0%0/3
not $array || $hash and ref $self->[0]{$v} eq "ARRAY"
$array $hash ref $self->[0]{$v} eq "ARRAY"
Truth table25%1/4
not(A || B) and C
A= $arrayB= $hashC= ref $self->[0]{$v} eq "ARRAY"
ABCresult
1XX0
01X0
0000
0011
2956 0 push(@{$self->[PML_V]{$v}}, @values);
2957 } else {
2958 1 foreach $i (@values) {
2959 1 $i =~ s/^\s+//o;
2960 1 ▶ defined $$ref and $$ref =~ s/\s+$//o;
Branch: 1 branch
BranchTrueFalseTotal
defined $$ref and $$ref =~ s/\s+$//o 1 0 1
2961 1 $$ref .= " $i";
2962 }
2963 }
2964 } elsif ($sub_token == TOKEN_SET_PREPEND) {
2965 1 ▶ if (not $array and not $hash and ref $self->[PML_V]{$v} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $array || $hash and ref $self->[0]{$v} eq 'ARRAY') { } 0 1 1
Condition33%2/6
not $array || $hash and ref $self->[0]{$v} eq "ARRAY"
!ll&&!rl&&r
010
$array || $hash
l!l&&r!l&&!r
001
MC/DC0%0/3
not $array || $hash and ref $self->[0]{$v} eq "ARRAY"
$array $hash ref $self->[0]{$v} eq "ARRAY"
Truth table25%1/4
not(A || B) and C
A= $arrayB= $hashC= ref $self->[0]{$v} eq "ARRAY"
ABCresult
1XX0
01X0
0000
0011
2966 0 unshift(@{$self->[PML_V]{$v}}, @values);
2967 } else {
2968 1 foreach $i (@values) {
2969 1 $i =~ s/\s+$//o;
2970 1 ▶ defined $$ref and $$ref =~ s/^\s+//o;
Branch: 1 branch
BranchTrueFalseTotal
defined $$ref and $$ref =~ s/^\s+//o 1 0 1
2971 1 $$ref = "$i $$ref";
2972 }
2973 }
2974 } elsif ($sub_token == TOKEN_SET_CONCAT) {
2975 0 ▶ if (not $array and not $hash and ref($self->[PML_V]{$v}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $array || $hash and ref $self->[0]{$v} eq 'ARRAY') { } 0 0 0
Condition0%0/6
not $array || $hash and ref $self->[0]{$v} eq "ARRAY"
!ll&&!rl&&r
000
$array || $hash
l!l&&r!l&&!r
000
MC/DC0%0/3
not $array || $hash and ref $self->[0]{$v} eq "ARRAY"
$array $hash ref $self->[0]{$v} eq "ARRAY"
Truth table0%0/4
not(A || B) and C
A= $arrayB= $hashC= ref $self->[0]{$v} eq "ARRAY"
ABCresult
1XX0
01X0
0000
0011
2976 0 push(@{$self->[PML_V]{$v}}, @values);
2977 } else {
2978 0 foreach $i (@values) {
2979 0 $i =~ s/^\s+//o;
2980 0 ▶ defined $$ref and $$ref =~ s/\s+$//o;
Branch: 1 branch
BranchTrueFalseTotal
defined $$ref and $$ref =~ s/\s+$//o 0 0 0
2981 0 $$ref .= "$i";
2982 }
2983 }
2984 } else {
2985 0 print STDERR "WOAH! Unknown Set Sub Token \"$sub_token\", you found a bug in PML.\n";
2986 0 croak "PML Internal Error";
2987 }
2988
2989 23 return undef;
2990 } # <-- End token_set -->
2991 ################################################################################
2992 #
2993 # ==== token_include ==== ######################################################
2994 #
2995 # Arguments:
2996 # See Above
2997 #
2998 # Returns:
2999 # None
3000 #
3001 # Description:
3002 # runs the tokens for the included file
3003 #
3004 ################################################################################
3005 sub token_include
3006 1 ▶{
Subroutine token_include: called CC=7 SCAR=19.9
Pod undocumented
3007 1 my ($self, $token) = @_;
3008 1 my @files = @{$token->data};
3009 1 my $file;
3010 1 my $rv = '';
3011
3012 1 local $^W=0; #FIXME temp fix for Use of uninitialized value
3013
3014 1 foreach $file (@files)
3015 {
3016 1 ▶ next unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 1 1
3017 1 $rv .= $self->tokens_execute($_) foreach @{$self->[PML_INCLUDES]{$file}};
3018 1 ▶ print STDERR "Executed included file $file\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PML::DEBUG 0 1 1
3019 }
3020
3021 1 ▶ print STDERR "The included text to be returned is:\n$rv\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PML::DEBUG 0 1 1
3022 1 ▶ return $rv || undef;
Condition50%1/2
$rv || undef
l!l
10
MC/DC0%0/1
$rv || undef
$rv
Truth table50%1/2
A
A= $rv
Aresult
11
00
3023 } # <-- End token_include -->
3024 ################################################################################
3025 #
3026 # ==== token_macro ==== ########################################################
3027 #
3028 # Arguments:
3029 # See Above
3030 #
3031 # Returns:
3032 # What ever the macro returns
3033 #
3034 # Description:
3035 # Runs the tokens for the macro
3036 #
3037 ################################################################################
3038 sub token_macro
3039 5 ▶{
Subroutine token_macro: called CC=10 SCAR=24.3
Pod undocumented
3040 5 my ($self, $token) = @_;
3041 5 my ($name, @args) = @{$token->data};
3042 5 my ($argument, $save_argv, $result, %save);
3043
3044 # keep from going to deep in recursion
3045 5 $self->_in;
3046
3047 # first make sure that the macro exists
3048 5 ▶ unless (exists $self->[PML_MACROS]{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->[13]{$name}) 0 5 5
3049 0 print STDERR "Macro \"$name\" was not defined, possible bug in PML\n";
3050 0 croak("PML Internal Error");
3051 }
3052
3053 # process the list of argument names from the macro definition
3054 my @arg_names = $self->tokens_execute (
3055 5 $self->[PML_MACROS]{$name}->[0]
3056 );
3057
3058 # look for one name called _ALL_ and remove it
3059 # this is for backwards compatability before ARGV existed
3060 5 ▶ if (defined $arg_names[0] and $arg_names[0] eq '_ALL_') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg_names[0] and $arg_names[0] eq "_ALL_") 0 5 5
Condition66%2/3
defined $arg_names[0] and $arg_names[0] eq "_ALL_"
!ll&&!rl&&r
320
MC/DC0%0/2
defined $arg_names[0] and $arg_names[0] eq "_ALL_"
defined $arg_names[0] $arg_names[0] eq "_ALL_"
Truth table66%2/3
A and B
A= defined $arg_names[0]B= $arg_names[0] eq "_ALL_"
ABresult
0X0
100
111
3061 0 shift @arg_names;
3062 }
3063
3064 # save the values of the arguments so
3065 # we can restore them at the end of the
3066 # macro call
3067 5 foreach $argument (@arg_names) {
3068 2 $save{$argument} = $self->[PML_V]{$argument};
3069 }
3070
3071 # make sure that the macro was called with at least
3072 # the number of arguments as there are names
3073 5 ▶ if (not (@args >= @arg_names) and $self->[PML_W]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @args >= @arg_names and $self->[6]) 0 5 5
Condition33%1/3
not @args >= @arg_names and $self->[6]
!ll&&!rl&&r
500
MC/DC0%0/2
not @args >= @arg_names and $self->[6]
not @args >= @arg_names $self->[6]
Truth table33%1/3
not(A) and B
A= not @args >= @arg_namesB= $self->[6]
ABresult
0X0
100
111
3074 0 print STDERR "Macro '$name' called with wrong number of arguments\n";
3075 }
3076  
3077 # now, place the arguments into the correct variables
3078 5 foreach $argument (@arg_names) {
3079 2 $self->[PML_V]{$argument} = $self->tokens_execute(shift @args);
3080 }
3081
3082 # save the current value of ARGV incase this is a macro call
3083 # inside another macro call.
3084 5 $save_argv = $self->[PML_V]{'ARGV'};
3085
3086 # all remaing arguments are put into ARGV and _ALL_
3087 # the _ALL_ part is for backward compatiblity and will be
3088 # removed someday
3089 5 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 4 5
3090 1 $self->[PML_V]{'ARGV'} = [$self->tokens_execute(@args)];
3091 1 $self->[PML_V]{'_ALL_'} = $self->[PML_V]{'ARGV'};
3092 }
3093
3094 # don't complain when we give join undef
3095 5 local $^W=0;
3096
3097 # execute the block of the macro
3098 5 $result = join '', $self->tokens_execute($self->[PML_MACROS]{$name}[1]);
3099  
3100 # restore the ARGV variable
3101 5 $self->[PML_V]{'ARGV'} = $save_argv;
3102
3103 # restore the variables in the arguments
3104 5 foreach $argument (keys %save) {
3105 2 $self->[PML_V]{$argument} = $save{$argument};
3106 }
3107
3108 # restore the rescurse count
3109 5 $self->_out;
3110
3111 # put the result into the output stream
3112 5 return $result;
3113 } # <-- End token_macro -->
3114 ################################################################################
3115 #
3116 # ==== token_variable ==== #####################################################
3117 #
3118 # Arguments:
3119 # See Above
3120 #
3121 # Returns:
3122 # 1 or more values or undef
3123 #
3124 # Description:
3125 # tries to expand variable
3126 #
3127 ################################################################################
3128 sub token_variable
3129 23 ▶{
Subroutine token_variable: called CC=5 SCAR=16.6
Pod undocumented
3130 23 my ($self, $token) = @_;
3131 23 my $v = $token->data;
3132 23 my @result;
3133
3134 23 ▶ while ($v =~ s/^$RE_VAR_TEST//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^$RE_VAR_TEST//o) 23 23 46
3135 23 ▶ push @result, $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 23 23
3136 23 push @result, $self->replace_variable(\$v);
3137 }
3138
3139 # set result to v if there is something in v
3140 23 ▶ push @result, $v if length $v;
Branch: 1 branch
BranchTrueFalseTotal
if length $v 0 23 23
3141
3142 23 ▶ if ($token->context == CONTEXT_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->context == 2) { } 23 0 23
3143 23 return @result;
3144 } else {
3145 0 return join '', @result;
3146 }
3147 } # <-- End token_variable -->
3148 ################################################################################
3149 #
3150 # ==== token_foreach ==== ######################################################
3151 #
3152 # Arguments:
3153 # See Above
3154 #
3155 # Returns:
3156 # The code from the block
3157 #
3158 # Description:
3159 # Executes the block tokens one time for each of the arguments,
3160 # setting the variable "." to the name of the argument
3161 #
3162 ################################################################################
3163 sub token_foreach
3164 2 ▶{
Subroutine token_foreach: called CC=13 SCAR=33.9
Pod undocumented
3165 2 my ($self, $token) = @_;
3166 2 my ($a, $b) = @{$token->data};
3167 2 my @args = $self->tokens_execute($a);
3168 2 my ($savedot, $savelabel, $havelabel, $rv);
3169
3170 # protect from deep recursion
3171 2 $self->_in;
3172
3173 # save off the old value of '.'
3174 2 $savedot = $self->[PML_V]{'.'};
3175
3176 # if we have a label, use it along with '.'
3177 2 ▶ if ($havelabel = $token->label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($havelabel = $token->label) 1 1 2
3178 1 $savelabel = $self->[PML_V]{$havelabel};
3179 }
3180
3181 # add to the count of loops
3182 2 $self->[PML_LOOP_COUNTERS]{'foreach'}++;
3183
3184 2 foreach my $arg (@args) {
3185 6 $self->[PML_V]{'.'} = $arg;
3186 6 ▶ $self->[PML_V]{$havelabel} = $arg if $havelabel;
Branch: 1 branch
BranchTrueFalseTotal
if $havelabel 3 3 6
3187 6 $rv .= join('', $self->tokens_execute($b));
3188 # see if that last call died
3189 6 ▶ if ($self->[PML_DIE_MESSAGE]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22]) 0 6 6
3190 0 ▶ if ($self->[PML_DIE_MESSAGE] =~ /$RE_LOOP_INT/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22] =~ /$RE_LOOP_INT/) { } 0 0 0
3191 # the die was a next, last or redo
3192 0 ▶ if (not $2 or $2 eq $token->label) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $2 or $2 eq $token->label) { } 0 0 0
Condition0%0/3
not $2 or $2 eq $token->label
l!l&&r!l&&!r
000
MC/DC0%0/2
not $2 or $2 eq $token->label
not $2 $2 eq $token->label
Truth table0%0/3
not(A) or B
A= not $2B= $2 eq $token->label
ABresult
1X1
011
000
3193 0 $self->[PML_DIE_MESSAGE]='';
3194 0 ▶ if ($1 eq 'next') {next}
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq 'next') { } 0 0 0
elsif ($1 eq 'redo') { } 0 0 0
elsif ($1 eq 'last') { } 0 0 0
3195 0 elsif ($1 eq 'redo') {redo}
3196 0 elsif ($1 eq 'last') {last}
3197 } else {
3198 0 die $self->[PML_DIE_MESSAGE];
3199 }
3200 0 } else {die $self->[PML_DIE_MESSAGE]}
3201 }
3202 }
3203
3204 # we are out of the loop
3205 2 $self->[PML_LOOP_COUNTERS]{'foreach'}--;
3206
3207 # restore the variable stored in havelabel
3208 2 ▶ $self->[PML_V]{$havelabel} = $savelabel if $havelabel;
Branch: 1 branch
BranchTrueFalseTotal
if $havelabel 1 1 2
3209
3210 # restore the value of the '.'
3211 2 $self->[PML_V]{'.'} = $savedot;
3212
3213 # stop recursion protection
3214 2 $self->_out;
3215
3216 2 ▶ return $rv || undef;
Condition50%1/2
$rv || undef
l!l
20
MC/DC0%0/1
$rv || undef
$rv
Truth table50%1/2
A
A= $rv
Aresult
11
00
3217 } # <-- End token_foreach -->
3218 ################################################################################
3219 #
3220 # ==== token_while ==== ########################################################
3221 #
3222 # Arguments:
3223 # See Above
3224 #
3225 # Returns:
3226 # A String
3227 #
3228 # Description:
3229 # Repeates the block while the condition is true
3230 #
3231 ################################################################################
3232 sub token_while
3233 3 ▶{
Subroutine token_while: called CC=10 SCAR=25.6
Pod undocumented
3234 3 my ($self, $token) = @_;
3235 3 my ($condition, $block) = @{$token->data};
3236 3 my $rv = '';
3237
3238 # say that we are in a loop
3239 3 $self->[PML_LOOP_COUNTERS]{'while'}++;
3240
3241 3 local $^W=0;
3242 3 ▶ while (scalar $self->tokens_execute($condition)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $self->tokens_execute($condition)) 15 2 17
3243 15 $rv .= join '', $self->tokens_execute($block);
3244 15 ▶ if ($self->[PML_DIE_MESSAGE]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22]) 1 14 15
3245 1 ▶ if ($self->[PML_DIE_MESSAGE] =~ /$RE_LOOP_INT/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22] =~ /$RE_LOOP_INT/) { } 1 0 1
3246 # the die was a next, last or redo
3247 1 ▶ if (not $2 or $2 eq $token->label) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $2 or $2 eq $token->label) { } 1 0 1
Condition33%1/3
not $2 or $2 eq $token->label
l!l&&r!l&&!r
100
MC/DC0%0/2
not $2 or $2 eq $token->label
not $2 $2 eq $token->label
Truth table33%1/3
not(A) or B
A= not $2B= $2 eq $token->label
ABresult
1X1
011
000
3248 1 $self->[PML_DIE_MESSAGE]='';
3249 0 ▶ if ($1 eq 'next') {next}
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq 'next') { } 0 1 1
elsif ($1 eq 'redo') { } 0 1 1
elsif ($1 eq 'last') { } 1 0 1
3250 0 elsif ($1 eq 'redo') {redo}
3251 1 elsif ($1 eq 'last') {last}
3252 } else {
3253 0 die $self->[PML_DIE_MESSAGE];
3254 }
3255 0 } else {die $self->[PML_DIE_MESSAGE]}
3256 }
3257  
3258 }
3259
3260 # done with the loop
3261 3 $self->[PML_LOOP_COUNTERS]{'while'}--;
3262
3263 3 ▶ return $rv || undef;
Condition50%1/2
$rv || undef
l!l
30
MC/DC0%0/1
$rv || undef
$rv
Truth table50%1/2
A
A= $rv
Aresult
11
00
3264 } # <-- End token_while -->
3265 ################################################################################
3266 #
3267 # ==== token_skip ==== #########################################################
3268 #
3269 # Arguments:
3270 # See Above
3271 #
3272 # Returns:
3273 # The skip text
3274 #
3275 # Description:
3276 # just returns the text in the skip block
3277 #
3278 ################################################################################
3279 sub token_skip
3280 1 ▶{
Subroutine token_skip: called CC=2 SCAR=7.6
Pod undocumented
3281 1 ▶ return $_[1]->data || undef;
Condition50%1/2
$_[1]->data || undef
l!l
10
MC/DC0%0/1
$_[1]->data || undef
$_[1]->data
Truth table50%1/2
A
A= $_[1]->data
Aresult
11
00
3282 } # <-- End token_skip -->
3283 ################################################################################
3284 #
3285 # ==== token_wrap ==== #########################################################
3286 #
3287 # Arguments:
3288 # See Above
3289 #
3290 # Returns:
3291 # Text wrapped
3292 #
3293 # Description:
3294 # Wraps the text
3295 #
3296 ################################################################################
3297 sub token_wrap
3298 0 ▶{
Subroutine token_wrap: not called CC=4 SCAR=30.0
Pod undocumented
3299 0 my ($self, $token) = @_;
3300 0 my ($c, $f, $s, $b) = @{$token->data};
3301 0 my ($text, $result);
3302
3303 0 $c = $self->tokens_execute($c);
3304 0 $f = $self->tokens_execute($f);
3305 0 $s = $self->tokens_execute($s);
3306
3307 0 $Text::Wrap::columns = $c;
3308
3309 0 $text = join '', $self->tokens_execute($b);
3310 0 $text =~ s/(?<!\n)\n(?!\n)/ /go;
3311
3312 0 ▶ while ($text =~ /([^\n]+)?(\n+)?/go) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /([^\n]+)?(\n+)?/go) 0 0 0
3313 0 ▶ if ($1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 0 0 0
3314 0 $result .= wrap($f, $s, $1);
3315 }
3316
3317 0 ▶ if ($2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 0 0 0
3318 0 $result .= $2;
3319 }
3320 }
3321
3322 0 return $result;
3323 } # <-- End token_wrap -->
3324 ################################################################################
3325 #
3326 # ==== token_rib ==== ##########################################################
3327 #
3328 # Arguments:
3329 # See Above
3330 #
3331 # Returns:
3332 # The text in the block or the first argument
3333 #
3334 # Description:
3335 # replace if blank token executer
3336 #
3337 ################################################################################
3338 sub token_rib
3339 4 ▶{
Subroutine token_rib: called CC=3 SCAR=11.2
Pod undocumented
3340 4 local ($^W)=0;
3341 4 my ($self, $token) = @_;
3342 4 my ($a, $b) = @{$token->data};
3343 4 my $block = join '', $self->tokens_execute($b);
3344
3345 4 ▶ return $block || $self->tokens_execute($a) || undef;
Condition60%3/5
$block || $self->tokens_execute($a) || undef
l!l
40
$block or $self->tokens_execute($a)
l!l&&r!l&&!r
220
MC/DC0%0/2
$block || $self->tokens_execute($a) || undef
$block $self->tokens_execute($a)
Truth table66%2/3
A or B
A= $blockB= $self->tokens_execute($a)
ABresult
1X1
011
000
3346 } # <-- End token_rib -->
3347 ################################################################################
3348 #
3349 # ==== token_magic_macro ==== ##################################################
3350 #
3351 # Arguments:
3352 # 1) A PML Object
3353 # 2) A PML::Token Object
3354 #
3355 # Returns:
3356 # Whatever the macro call returns
3357 #
3358 # Description:
3359 # Replaces all variables in the macro name untill there are none
3360 # left, the calls that macro if it exists
3361 #
3362 ################################################################################
3363 sub token_magic_macro
3364 1 ▶{
Subroutine token_magic_macro: called CC=3 SCAR=12.0
Pod undocumented
3365 1 my ($self, $token) = @_;
3366 1 my ($eval_token, $name);
3367 1 my ($func, $a) = @{$token->data};
3368
3369 # first build a token to eval the macro name
3370 1 $eval_token = new PML::Token TOKEN_EVAL;
3371 1 $eval_token->data($func);
3372
3373 # now get the name of the macro
3374 1 $name = $self->tokens_execute($eval_token);
3375
3376 # make sure there is a macro called $name
3377 1 ▶ unless (exists $self->[PML_MACROS]{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->[13]{$name}) 0 1 1
3378 0 ▶ if ($self->warning) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->warning) 0 0 0
3379 0 print STDERR "you called a macro with a variable in it's name, the name resolved to '$name' but there is no macro by that name\n";
3380 }
3381 0 return '';
3382 }
3383
3384 # if we get here we can let token_macro do the work for us
3385 1 $token->id(TOKEN_MACRO);
3386 1 $token->data([$name, $a]);
3387
3388 1 return scalar $self->tokens_execute($token);
3389 } # <-- End token_magic_macro -->
3390 ################################################################################
3391 #
3392 # ==== token_loop_int ==== #####################################################
3393 #
3394 # Arguments:
3395 # 1) PML Object
3396 # 2) PML::Token
3397 #
3398 # Returns:
3399 # Nothing
3400 #
3401 # Description:
3402 # Dies if we are in a loop
3403 #
3404 ################################################################################
3405 sub token_loop_int
3406 1 ▶{
Subroutine token_loop_int: called CC=5 SCAR=19.4
Pod undocumented
3407 1 my ($self, $token) = @_;
3408 1 my ($name, $label) = @{$token->data};
3409
3410 # if we have a label then resolve it
3411 1 ▶ $label = $self->tokens_execute($label) if $label;
Branch: 1 branch
BranchTrueFalseTotal
if $label 0 1 1
3412 1 ▶ $label ||= '';
Condition50%1/2
$label ||= ""
l!l
01
MC/DC0%0/1
$label ||= ""
$label
Truth table50%1/2
A
A= $label
Aresult
11
00
3413
3414 # check to see if we are in a loop
3415 1 ▶ if (grep {$_>=1} values %{$self->[PML_LOOP_COUNTERS]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ >= 1;} values %{$$self[21];}) { } 1 0 1
3416 1 die "$name:$label";
3417 } else { # we are not in a loop so we go all the way back up to execute
3418 0 ▶ if ($self->warning) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->warning) 0 0 0
3419 0 print STDERR "using \@$name() outside of a loop can be messy\n";
3420 };
3421 0 die "$name:tc";
3422 }
3423
3424 0 return undef;
3425 } # <-- End token_loop_int -->
3426 ################################################################################
3427 #
3428 # ==== AUTOLOAD ==== ###########################################################
3429 #
3430 # Arguments:
3431 # 1) Args going to orig method call
3432 #
3433 # Returns:
3434 # What ever the orig method call would return
3435 #
3436 # Description:
3437 # Helps map method calls to subs
3438 #
3439 ################################################################################
3440 AUTOLOAD
3441 2254 ▶{
Subroutine AUTOLOAD: called CC=8 SCAR=22.1
3442 2254 my ($class, $method) = ($AUTOLOAD =~ /^(.*)::(.*)$/);
3443
3444 2254 ▶ if ($class eq 'PML::Token') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'PML::Token') { } 2254 0 2254
3445 2254 ▶ if ($method eq 'id') {
Branch: 5 branches
BranchTrueFalseTotal
if ($method eq 'id') { } 1033 1221 2254
elsif ($method eq 'context') { } 191 1030 1221
elsif ($method eq 'file_loc' or $method eq 'fli') { } 371 659 1030
elsif ($method eq 'data') { } 656 3 659
elsif ($method eq 'label') { } 3 0 3
3446 1033 return _token_id(@_);
3447 } elsif ($method eq 'context') {
3448 191 return _token_context(@_);
3449 ▶ } elsif ($method eq 'file_loc' or $method eq 'fli') {
Condition66%2/3
$method eq "file_loc" or $method eq "fli"
l!l&&r!l&&!r
3710659
MC/DC50%1/2
$method eq "file_loc" or $method eq "fli"
$method eq "file_loc" $method eq "fli"
Truth table66%2/3
A or B
A= $method eq "file_loc"B= $method eq "fli"
ABresult
1X1
011
000
3450 371 return _token_file_loc(@_);
3451 } elsif ($method eq 'data') {
3452 656 return _token_data(@_);
3453 } elsif ($method eq 'label') {
3454 3 return _token_label(@_);
3455 } else {
3456 0 carp "unknown PML::Token method '$method'";
3457 0 return undef;
3458 }
3459 } else {
3460 0 carp "unknown PML method '$method'";
3461 0 return undef;
3462 }
3463 } # <-- End AUTOLOAD -->
3464 ################################################################################
3465 #
3466 # ==== DESTROY ==== ############################################################
3467 #
3468 # Arguments:
3469 # 1) Object to destroy
3470 #
3471 # Returns:
3472 # None
3473 #
3474 # Description:
3475 # Cleans up after object
3476 #
3477 ################################################################################
3478 DESTROY
3479 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
3480  
3481 } # <-- End DESTROY -->
3482 ################################################################################
3483 # END-OF-MODULE #
3484 ################################################################################
3485 18 1;
↑ Summary PML/File.pm »