blib/lib/Language/MPI.pm

filter: Statementstmt 75.8% 365 / 481 Branchbran 56.1% 55 / 98 Conditioncond 35.4% 17 / 48 MC/DCmcdc 6.6% 2 / 30 Subroutinesub 68.9% 71 / 103 Podpod 4.0% 4 / 99 totaltotal 59.8% 514 / 859 CC 89 SCAR 12.8
CC
89
Cov
70%
func_lremove
20.0
func_lunion
12.0
func_lunique
12.0
CRAP 3.6
↑ Summary
1 # MPI.pm
2
3 =pod
4
5 =head1 NAME
6
7 Language::MPI - 2008.0217 Message Parsing Interpreter
8
9 =head1 SYNOPSIS
10
11 Processor for the Message Parsing Interpreter text
12 composition language, based on the MPI found in MU* online
13 environments, adapted for more general semantics.
14
15 http://en.wikipedia.org/wiki/Message_Parsing_Interpreter
16
17 =head1 USAGE
18
19 use Language::MPI;
20 $node = new Language::MPI($noderef);
21 $node->setvar("varname", "varval");
22 $results = $node->parse("tick {set:varname,{time:}} tock");
23 $val = $node->readvar("varname");
24
25 MPI assumes an operating environment consisting of a set
26 of nodes each of which has a set of named properties. How
27 these nodes and properties are stored and structured is up
28 to the application except that:
29
30 =over
31
32 =item * noderefs are perl scalars used by application
33 supplied functions. Something with a printable value is
34 encouraged but not required.
35
36 =item * properties may be identified by and resolve to
37 plain text strings.
38
39 =back
40
41 MPI, in the interest of more general usage, expects some
42 support subroutines to be supplied by app to access nodes
43 and properties. Should any of these not be supplied, errors
44 are trapped to prevent crashing. Functions not needing
45 these should still work properly. Should the application
46 designer wish, app data to be passed to these callbacks may
47 be set into and read from the object by the setvar() and
48 readvar() methods.
49
50 =over
51
52 =item mpi_neighbors($thisnode, $pattern, $obj)
53
54 $thisnode is a noderef.
55 $pattern is a string pattern used to specify which nodes
56 'neighboring' the current node are of interest.
57 returns list of noderefs;
58
59 =item mpi_prop($thisnode, $propname, $obj)
60
61 $propname is the string name of a property.
62 returns propval;
63
64 =item mpi_props($thisnode, $proppat, $obj)
65
66 $propat is a string specifier to a property directory or a
67 subset of properties.
68 returns list of propnames;
69
70 =item mpi_propset($thisnode, $propname, $val, $obj)
71
72 =back
73
74 =head1 INSTALATION
75
76 perl Makefile.PL
77 make
78 make install
79
80 Or simply copy the MPI.pm file to Language/ under the perl
81 modules directory. README and the man file for this package
82 exist as pod data in MPI.pm.
83
84 =head1 STATUS
85
86 Some MPI standard functions incomplete or unimplimented. Testing incomplete.
87
88 =head1 Etc
89
90 This code developed using perl 5.8.8. Might work with perl
91 5.6.0 or older with proper libraries. Uses strict and warning.
92
93 Copyright (c)2007 Peter Hanely. All rights reserved.
94 This program is free software; you can redistribute it and/or
95 modify it under the same terms as Perl itself.
96
97 =head1 LANGUAGE
98
99 =head2 VARS
100
101 =over
102
103 =item Variable names of alphabetic characters are general MPI use.
104
105 =item Names beginning with an underscore "_" are reserved
106 for mpi internal variables and should not be used by the
107 application.
108
109 =item Names beginning with "\" are suggested for application
110 values placed in the mpi object.
111
112 =cut
113
114 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 # warning good for debug, but produce noise from good code
117 1 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
118 #use Carp;
119
120 package Language::MPI;
121
122 1 our ($VERSION, @ISA, @EXPORT_OK, $perl_list);
123 #use vars qw($VERSION, @ISA, @EXPORT_OK, $perl_list);
124
125 BEGIN
126 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
127 1 require Exporter;
128 1 our ($VERSION, @ISA, @EXPORT_OK);
129
130 1 @ISA = qw(Exporter);
131 1 @EXPORT_OK = qw(parse setvar readvar simp_functions);
132
133 1 $VERSION = "2008.0217";
134 }
135
136 # control functions alter execution of their parameters,
137 # and thus parse their own parameters.
138 1 my %ctrl_functions =
139 ( 'debug' => \&func_debug,
140 'debugif' => \&func_debugif,
141 'filter' => \&func_filter,
142 'fold' => \&func_fold,
143 'for' => \&func_for,
144 'foreach' => \&func_foreach,
145 # 'func' => \&func_func,
146 'if' => \&func_if,
147 'lit' => \&func_lit,
148 'lsort' => \&func_lsort,
149 'neighbors' => \&func_neighbors,
150 'parse' => \&func_parse,
151 'while' => \&func_while,
152 'with' => \&func_with
153 );
154
155 # simple functions have their parameters parsed by calling code.
156 1 my %simp_functions =
157 ( 'abs' => \&func_abs,
158 'add' => \&func_add,
159 'and' => \&func_and,
160 'attr' => \&func_attr,
161 'convsecs' => \&func_convsecs,
162 'convtime' => \&func_convtime,
163 'count' => \&func_count,
164 'date' => \&func_date,
165 'debug' => \&func_debug,
166 'debugif' => \&func_debugif,
167 'dec' => \&func_dec,
168 'default' => \&func_default,
169 'delprop' => \&func_delprop,
170 'dice' => \&func_dice,
171 'dist' => \&func_dist,
172 'div' => \&func_div,
173 'eq' => \&func_eq,
174 'escape' => \&func_escape,
175 'eval' => \&func_eval,
176 'exec' => \&func_exec,
177 'filter' => \&func_filter,
178 'fold' => \&func_fold,
179 'for' => \&func_for,
180 'foreach' => \&func_foreach,
181 'ftime' => \&func_ftime,
182 'fullname' => \&func_fullname,
183 'func' => \&func_func,
184 'ge' => \&func_ge,
185 'gt' => \&func_gt,
186 'if' => \&func_if,
187 'inc' => \&func_inc,
188 'index' => \&func_index,
189 'instr' => \&func_instr,
190 'isnum' => \&func_isnum,
191 'lcommon' => \&func_lcommon,
192 'le' => \&func_le,
193 'list' => \&func_list,
194 'listprops' => \&func_listprops,
195 'lit' => \&func_lit,
196 'lmember' => \&func_lmember,
197 'lrand' => \&func_lrand,
198 'lremove' => \&func_lremove,
199 'lsort' => \&func_lsort,
200 'lt' => \&func_lt,
201 'ltimestr' => \&func_ltimestr,
202 'lunion' => \&func_lunion,
203 'lunique' => \&func_lunique,
204 'max' => \&func_max,
205 'midstr' => \&func_midstr,
206 'min' => \&func_min,
207 'mklist' => \&func_mklist,
208 'mod' => \&func_mod,
209 'mult' => \&func_mult,
210 'name' => \&func_name,
211 'ne' => \&func_ne,
212 'neighbors2' => \&func_neighbors2,
213 'nl' => \&func_nl,
214 'not' => \&func_not,
215 'null' => \&func_null,
216 'or' => \&func_or,
217 'parse' => \&func_parse,
218 'prop' => \&func_prop,
219 'rand' => \&func_rand,
220 'secs' => \&func_secs,
221 'select' => \&func_select,
222 'set' => \&func_set,
223 'sign' => \&func_sign,
224 'smatch' => \&func_smatch,
225 'stimestr' => \&func_stimestr,
226 'store' => \&func_store,
227 'strip' => \&func_strip,
228 'strlen' => \&func_strlen,
229 'sublist' => \&func_sublist,
230 'subst' => \&func_subst,
231 'subt' => \&func_subt,
232 'time' => \&func_time,
233 'timestr' => \&func_timestr,
234 'timesub' => \&func_timesub,
235 'tolower' => \&func_tolower,
236 'toupper' => \&func_toupper,
237 'tzoffset' => \&func_tzoffset,
238 'v' => \&func_v,
239 'version' => \&func_version,
240 'while' => \&func_while,
241 'with' => \&func_with,
242 'xor' => \&func_xor
243 );
244
245 =head1 MPI primitives
246
247 =cut
248
249 =head2 {abs:num}
250
251 =cut
252
253 sub func_abs
254 1 ▶{ my ($this, $val) = @_;
Subroutine func_abs: called CC=1 SCAR=0.0
Pod undocumented
255 1 abs $val->[0];
256 }
257
258 =head2 {add:num1,num2...}
259
260 =cut
261
262 sub func_add
263 2 ▶{ my ($this, $val) = @_;
Subroutine func_add: called CC=2 SCAR=6.9
Pod undocumented
264 2 my ($num, $tot);
265 2 foreach $num (@$val)
266 5 { $tot += $num; }
267 2 $tot;
268 }
269
270 =head2 {and:num1,num2...}
271
272 =cut
273
274 sub func_and
275 1 ▶{ my ($this, $val) = @_;
Subroutine func_and: called CC=3 SCAR=11.3
Pod undocumented
276 1 my ($num, $tot);
277 1 $tot = 1;
278 1 foreach $num (@$val)
279 { #$tot &&= $num;
280 0 ▶ if (!$num) { $tot = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($num) 0 3 3
281 }
282 1 $tot;
283 }
284
285 =head2 {attr:attribute...,text}
286
287 =cut
288
289 sub func_attr
290 1 ▶{ my ($this, $val) = @_;
Subroutine func_attr: called CC=1 SCAR=0.0
Pod undocumented
291 #stub
292 1 $$val[-1];
293 }
294
295 sub func_convsecs
296 0 ▶{ my ($this, $val) = @_;
Subroutine func_convsecs: not called CC=1 SCAR=6.9
Pod undocumented
297
298 }
299
300 sub func_convtime
301 0 ▶{ my ($this, $val) = @_;
Subroutine func_convtime: not called CC=1 SCAR=6.9
Pod undocumented
302
303 }
304
305 =head2 {count:array}
306
307 =cut
308
309 sub func_count
310 1 ▶{ my ($this, $val) = @_;
Subroutine func_count: called CC=1 SCAR=0.0
Pod undocumented
311 1 my (@arry);
312 1 @arry = &unpack_list($val->[0]);
313 1 return (scalar (@arry));
314 }
315
316 =head2 {date:}
317
318 =cut
319
320 sub func_date
321 1 ▶{ my ($sec, $min, $hour, $mday, $mon, $year) = gmtime (time());
Subroutine func_date: called CC=2 SCAR=7.0
Pod undocumented
322 1 ▶ if ($year < 1000) { $year += 1900; }
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 1000) 1 0 1
323 1 $mon++;
324 1 "$mon/$mday/$year";
325 }
326
327 sub func_debug
328 0 ▶{ }
Subroutine func_debug: not called CC=1 SCAR=0.0
Pod undocumented
329
330 sub func_debugif
331 0 ▶{ }
Subroutine func_debugif: not called CC=1 SCAR=0.0
Pod undocumented
332
333 =head2 {dec:var,dec}
334
335 =cut
336
337 sub func_dec
338 3 ▶{ my ($this, $val) = @_;
Subroutine func_dec: called CC=2 SCAR=7.0
Pod undocumented
339 3 my ($var, $inc) = @$val;
340 3 ▶ $inc = $inc || 1;
Condition50%1/2
$inc || 1
l!l
30
MC/DC0%0/1
$inc || 1
$inc
Truth table50%1/2
A
A= $inc
Aresult
11
00
341 3 $this->{$var} -= $inc;
342 }
343
344 =head2 {default:var1,var2...}
345
346 =cut
347
348 sub func_default
349 1 ▶{ my ($this, $val) = @_;
Subroutine func_default: called CC=4 SCAR=16.6
Pod undocumented
350 1 my ($indx) = 0;
351 0 ▶ while (($indx < @$val) && !($val->[$indx])) { $indx ++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($indx < @$val and not $val->[$indx]) 0 1 1
Condition33%1/3
$indx < @$val and not $val->[$indx]
!ll&&!rl&&r
010
MC/DC0%0/2
$indx < @$val and not $val->[$indx]
$indx < @$val not $val->[$indx]
Truth table33%1/3
A and not(B)
A= $indx < @$valB= not $val->[$indx]
ABresult
0X0
100
111
352 1 ▶ if ($indx < @$val) { $val->[$indx]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($indx < @$val) { } 1 0 1
353 0 else { ""; }
354 }
355
356 =head2 {delprop:var[,obj]}
357
358 =cut
359
360 sub func_delprop
361 1 ▶{ my ($this, $val) = @_;
Subroutine func_delprop: called CC=3 SCAR=11.8
Pod undocumented
362 1 my ($prop, $obj) = @$val;
363 1 ▶ $obj = $obj || $this->{'_node'};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
364 1 ▶ if (defined &mpi_propset)
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Language::MPI::mpi_propset) 1 0 1
365 1 { eval (&mpi_propset($obj, $prop, "", $this)); }
366 }
367
368 =head2 {dice:range[,count[,bonus]]}
369
370 =cut
371
372 sub func_dice
373 1 ▶{ my ($this, $val) = @_;
Subroutine func_dice: called CC=3 SCAR=11.1
Pod undocumented
374 1 my ($range, $count, $bonus) = @$val;
375 1 my ($indx, $tot);
376 0 ▶ if ($count <= 0) { $count = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($count <= 0) 0 1 1
377 1 ▶ for ($indx = 0; $indx < $count; $indx ++)
Branch: 1 branch
BranchTrueFalseTotal
if ($indx < $count) 3 1 4
378 3 { $tot += int(rand($range)+1); }
379 1 $tot+$bonus;
380 }
381
382 =head2 {dist:x1,y2...}
383
384 =cut
385
386 sub func_dist
387 1 ▶{ my ($this, $val) = @_;
Subroutine func_dist: called CC=2 SCAR=7.2
Pod undocumented
388 1 my ($x1, $y1, $z1, $x2, $y2, $z2) = @$val;
389 1 ▶ if (@$val == 4)
Branch: 1 branch
BranchTrueFalseTotal
if (@$val == 4) 0 1 1
390 0 { ($x2, $y2) = ($z1, $x2); }
391 1 my ($dx, $dy, $dz) = ($x2-$x1, $y2-$y1, $z2-$z1);
392 1 sqrt($dx*$dx + $dy*$dy + $dz*$dz);
393 }
394
395 =head2 {div:num,num1...}
396
397 =cut
398
399 sub func_div
400 1 ▶{ my ($this, $val) = @_;
Subroutine func_div: called CC=1 SCAR=0.0
Pod undocumented
401 1 int($val->[0]/$val->[1]);
402 }
403
404 =head2 {eq:var1,var2}
405
406 =cut
407
408 sub func_eq
409 1 ▶{ my ($this, $val) = @_;
Subroutine func_eq: called CC=1 SCAR=0.0
Pod undocumented
410 1 $val->[0] eq $val->[1];
411 }
412
413 sub func_escape
414 0 ▶{ }
Subroutine func_escape: not called CC=1 SCAR=0.0
Pod undocumented
415
416 =head2 {eval:vars...}
417
418 =cut
419
420 sub func_eval
421 1 ▶{ my ($this, $val) = @_;
Subroutine func_eval: called CC=2 SCAR=6.9
Pod undocumented
422 1 my ($tot, $param);
423 1 foreach $param(@$val)
424 1 { $tot .= &parse($this, $param); }
425 1 $tot;
426 }
427
428 =head2 {exec:prop[,node]}
429
430 =cut
431
432 sub func_exec
433 1 ▶{ my ($this, $val) = @_;
Subroutine func_exec: called CC=4 SCAR=14.6
Pod undocumented
434 1 my ($prop, $obj) = @$val;
435 1 my ($tmp) = "";
436 1 ▶ my ($propval) = eval {&mpi_prop($obj || $this->{'_node'}, $prop, $this)};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
437 1 ▶ if ($propval)
Branch: 1 branch
BranchTrueFalseTotal
if ($propval) 1 0 1
438 1 ▶ { $tmp = &parse($this, $propval) || "" };
Condition50%1/2
&parse($this, $propval) || ''
l!l
10
MC/DC0%0/1
&parse($this, $propval) || ''
&parse($this, $propval)
Truth table50%1/2
A
A= &parse($this, $propval)
Aresult
11
00
439 1 $tmp;
440 }
441
442 sub func_filter
443 0 ▶{ }
Subroutine func_filter: not called CC=1 SCAR=0.0
Pod undocumented
444
445 sub func_fold
446 0 ▶{ }
Subroutine func_fold: not called CC=1 SCAR=0.0
Pod undocumented
447
448 =head2 {for:varname,start,end,increment,commands}
449
450 =cut
451
452 # control function, parses its own parameters
453 sub func_for
454 1 ▶{ my ($this, $params) = @_;
Subroutine func_for: called CC=5 SCAR=19.0
Pod undocumented
455 1 my ($varname,$start,$end,$increment,$command, $result, $results);
456 1 ($varname, $params) = &parse_parameter($this, $params);
457 1 ($start, $params) = &parse_parameter($this, $params);
458 1 ($end, $params) = &parse_parameter($this, $params);
459 1 ($increment, $command) = &parse_parameter($this, $params);
460 1 $this->{$varname} = $start;
461 1 ▶ if ($increment > 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($increment > 0) { } 1 0 1
elsif ($increment < 0) { } 0 0 0
462 1 ▶ { while ($this->{$varname} <= $end)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{$varname} <= $end) 4 1 5
463 4 { ($result, $params) = &parse_parameters($this, $command);
464 4 $results .= join '', @$result;
465 4 $this->{$varname} += $increment;
466 }
467 }
468 elsif ($increment < 0)
469 0 ▶ { while ($this->{$varname} <= $end)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{$varname} <= $end) 0 0 0
470 0 { ($result, $params) = &parse_parameters($this, $command);
471 0 $results .= join '', @$result;
472 0 $this->{$varname} += $increment;
473 }
474 }
475 else # sanity case
476 0 { ($result, $params) = &parse_parameters($this, $command);
477 0 $results .= join '', @$result;
478 }
479 1 ($results, $params);
480 }
481
482 =head2 {foreach:varname,list,command[,list seperator]}
483
484 =cut
485
486 sub func_foreach
487 1 ▶{ my ($this, $params) = @_;
Subroutine func_foreach: called CC=2 SCAR=7.3
Pod undocumented
488 1 my ($varname,$list,$expr,$sep, @list, $val, $res, $result);
489 1 ($varname, $params) = &parse_parameter($this, $params);
490 1 ($list, $expr) = &parse_parameter($this, $params);
491 1 ($params) = &skip_param($this, $expr);
492 #$sep = $sep || "\n";
493 1 @list = unpack_list($list, $sep);
494 1 foreach $val(@list)
495 0 { $this->{$varname} = $val;
496 0 ($res) = &parse_parameter($this, $expr);
497 0 $result .= $res;
498 }
499 1 ($res, $params);
500 }
501
502 sub func_ftime
503 0 ▶{ }
Subroutine func_ftime: not called CC=1 SCAR=0.0
Pod undocumented
504
505 sub func_fullname
506 0 ▶{ }
Subroutine func_fullname: not called CC=1 SCAR=0.0
Pod undocumented
507
508 =head2 {func:name,var1:var2...,commands}
509
510 =cut
511
512 sub func_func
513 0 ▶{ my ($this, $val) = @_;
Subroutine func_func: not called CC=1 SCAR=6.9
Pod undocumented
514 0 my ($func, $vars, $code) = @$val;
515 0 $this->{"_f_$func"} = $code;
516 0 $this->{"_f_$func v"} = $vars;
517 0 "$func, $vars, $code";
518 }
519
520 =head2 {ge:var1,var2}
521
522 =cut
523
524 sub func_ge
525 1 ▶{ my ($this, $val) = @_;
Subroutine func_ge: called CC=1 SCAR=0.0
Pod undocumented
526 1 $val->[0] >= $val->[1];
527 }
528
529 =head2 {gt:var1,var2}
530
531 =cut
532
533 sub func_gt
534 1 ▶{ my ($this, $val) = @_;
Subroutine func_gt: called CC=1 SCAR=0.0
Pod undocumented
535 1 $val->[0] > $val->[1];
536 }
537
538 =head2 {if:condition,true[,false]}
539
540 =cut
541
542 sub func_if
543 1 ▶{ my ($this, $params) = @_;
Subroutine func_if: called CC=2 SCAR=7.3
Pod undocumented
544 1 my ($check, $ret);
545 1 ($check, $params) = &parse_parameter($this, $params);
546 1 ▶ if ($check)
Branch: 1 branch
BranchTrueFalseTotal
if ($check) { } 1 0 1
547 1 { ($ret, $params) = &parse_parameter($this, $params);
548 1 ($params) = &skip_param($this, $params);
549 }
550 else
551 0 { ($params) = &skip_param($this, $params);
552 0 ($ret, $params) = &parse_parameter($this, $params);
553 }
554 1 $ret;
555 }
556
557 =head2 {inc:var,inc}
558
559 =cut
560
561 sub func_inc
562 1 ▶{ my ($this, $val) = @_;
Subroutine func_inc: called CC=2 SCAR=7.0
Pod undocumented
563 1 my ($var, $inc) = @$val;
564 1 ▶ $inc = $inc || 1;
Condition50%1/2
$inc || 1
l!l
10
MC/DC0%0/1
$inc || 1
$inc
Truth table50%1/2
A
A= $inc
Aresult
11
00
565 1 $this->{$var} += $inc;
566 }
567
568 =head2 {index:prop[,obj]}
569
570 =cut
571
572 sub func_index
573 1 ▶{ my ($this, $val) = @_;
Subroutine func_index: called CC=4 SCAR=14.6
Pod undocumented
574 1 my ($prop, $obj) = @$val;
575 1 ▶ $obj = $obj || $this->{"_node"};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
576 1 $prop = eval {&mpi_prop($obj, $prop, $this)};
577 1 ▶ if ($prop)
Branch: 1 branch
BranchTrueFalseTotal
if ($prop) 1 0 1
578 1 ▶ { eval {&mpi_prop($obj, $prop, $this)} || ""; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &mpi_prop($obj, $prop, $this) } } or "" 1 0 1
579 }
580
581 =head2 {insrt:string1,string2}
582
583 =cut
584
585 sub func_instr
586 0 ▶{ my ($this, $val) = @_;
Subroutine func_instr: not called CC=1 SCAR=6.9
Pod undocumented
587 0 my ($str1, $str2) = @$val;
588 0 index($str1, $str2) + 1;
589 }
590
591 sub func_isnum
592 0 ▶{ my ($this, $val) = @_;
Subroutine func_isnum: not called CC=2 SCAR=17.9
Pod undocumented
593 0 my ($num) = @$val;
594 0 ▶ if (!$num) { $num = '0e0'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($num) 0 0 0
595 0 $num;
596 }
597
598 =head2 {lcommon:list1,list2}
599
600 =cut
601
602 sub func_lcommon
603 1 ▶{ my ($this, $val) = @_;
Subroutine func_lcommon: called CC=4 SCAR=15.2
Pod undocumented
604 1 my ($l1, $l2) = @$val;
605 1 my (%h, $i, @res);
606 1 foreach $i(&unpack_list($l1))
607 0 { $h{$i} = 1; }
608 1 foreach $i(&unpack_list($l2))
609 1 ▶ { if ($h{$i})
Branch: 1 branch
BranchTrueFalseTotal
if ($h{$i}) 0 1 1
610 0 { push @res, $i;
611 0 undef $h{$i}; # remove duplicates.
612 }
613 }
614 1 &pack_list(@res);
615 }
616
617 =head2 {le:var1,var2}
618
619 =cut
620
621 sub func_le
622 1 ▶{ my ($this, $val) = @_;
Subroutine func_le: called CC=1 SCAR=0.0
Pod undocumented
623 1 $val->[0] <= $val->[1];
624 }
625
626 =head2 {list:props[,obj]}
627
628 =cut
629
630 sub func_list
631 1 ▶{ my ($this, $val) = @_;
Subroutine func_list: called CC=3 SCAR=11.2
Pod undocumented
632 1 my ($list, $obj) = @$val;
633 1 my (@list, $i);
634 1 ▶ $obj = $obj || $this->{"_node"};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
635 1 foreach $i(eval{&mpi_props($obj, $list, $this)})
636 3 { push @list, eval(&mpi_prop($obj, $i, $this)); }
637 1 &pack_list(@list);
638 }
639
640 =head2 {listprops:props[,obj]}
641
642 =cut
643
644 sub func_listprops
645 1 ▶{ my ($this, $val) = @_;
Subroutine func_listprops: called CC=2 SCAR=7.2
Pod undocumented
646 1 my ($list, $obj) = @$val;
647 1 ▶ $obj = $obj || $this->{"_node"};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
648 1 &pack_list(eval{&mpi_props($obj, $list, $this)});
649 }
650
651 =head2 {lit:expression to not parse}
652
653 =cut
654
655 sub func_lit
656 1 ▶{ my ($this, $param) = @_;
Subroutine func_lit: called CC=1 SCAR=0.0
Pod undocumented
657 1 my ($lit);
658 1 ($param, $lit) = &skip_parameters($this, $param);
659 1 $lit;
660 }
661
662 =head2 {lmember:list,item[,delimiter]}
663
664 =cut
665
666 sub func_lmember
667 1 ▶{ my ($this, $val) = @_;
Subroutine func_lmember: called CC=4 SCAR=15.2
Pod undocumented
668 1 my ($list, $item, $del) = @$val;
669 1 my ($i, @list);
670 1 @list = &unpack_list($list, $del);
671 1 ▶ for ($i = 0; $i < @list && $list[$i] ne $item; $i++) { }
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @list and $list[$i] ne $item) 0 1 1
Condition33%1/3
$i < @list and $list[$i] ne $item
!ll&&!rl&&r
100
MC/DC0%0/2
$i < @list and $list[$i] ne $item
$i < @list $list[$i] ne $item
Truth table33%1/3
A and B
A= $i < @listB= $list[$i] ne $item
ABresult
0X0
100
111
672 0 ▶ if ($list[$i] eq $item) { return $i+1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($list[$i] eq $item) 0 1 1
673 1 0;
674 }
675
676 =head2 {lrand:list[,delimiter]}
677
678 =cut
679
680 sub func_lrand
681 0 ▶{ my ($this, $val) = @_;
Subroutine func_lrand: not called CC=1 SCAR=6.9
Pod undocumented
682 0 my ($list, $del) = @$val;
683 0 my ($i, @list);
684 0 @list = &unpack_list($list, $del);
685 0 $list[int(rand @list)];
686 }
687
688 =head2 {lremove:list1,list2}
689
690 =cut
691
692 sub func_lremove
693 0 ▶{ my ($this, $val) = @_;
Subroutine func_lremove: not called CC=4 SCAR=30.0
Pod undocumented
694 0 my ($l1, $l2) = @$val;
695 0 my (%h, $i, @res);
696 0 foreach $i(&unpack_list($l1))
697 0 { $h{$i} = 1; }
698 0 foreach $i(&unpack_list($l2))
699 0 ▶ { if (!$h{$i})
Branch: 1 branch
BranchTrueFalseTotal
unless ($h{$i}) 0 0 0
700 0 { push @res, $i;
701 0 $h{$i} = 1; # remove duplicates.
702 }
703 }
704 0 &pack_list(@res);
705 }
706
707 sub func_lsort
708 0 ▶{ my ($this, $params) = @_;
Subroutine func_lsort: not called CC=1 SCAR=6.9
Pod undocumented
709 0 my ($list, @list, $var1, $var2, $code);
710 0 ($list, $params) = &parse_parameter($this, $params);
711 # do fancy sort later
712 0 &pack_list(sort &unpack_list($list));
713 }
714
715 =head2 {lt:num1,num2}
716
717 =cut
718
719 sub func_lt
720 0 ▶{ my ($this, $val) = @_;
Subroutine func_lt: not called CC=1 SCAR=6.9
Pod undocumented
721 0 $val->[0] < $val->[1];
722 }
723
724 sub func_ltimestr
725 0 ▶{ }
Subroutine func_ltimestr: not called CC=1 SCAR=0.0
Pod undocumented
726
727 =head2 {lunion:list1,list2}
728
729 =cut
730
731 sub func_lunion
732 0 ▶{ my ($this, $val) = @_;
Subroutine func_lunion: not called CC=3 SCAR=24.8
Pod undocumented
733 0 my ($l1, $l2) = @$val;
734 0 my (%h, $i);
735 0 foreach $i(&unpack_list($l1))
736 0 { $h{$i} = 1; }
737 0 foreach $i(&unpack_list($l2))
738 0 { $h{$i} = 1; }
739 0 &pack_list(keys %h);
740 }
741
742 =head2 {lunique:list}
743
744 =cut
745
746 sub func_lunique
747 0 ▶{ my ($this, $val) = @_;
Subroutine func_lunique: not called CC=3 SCAR=24.8
Pod undocumented
748 0 my ($l1, $l2) = @$val;
749 0 my (%h, $i, @res);
750 0 foreach $i(&unpack_list($l1))
751 0 ▶ { if (!$h{$i})
Branch: 1 branch
BranchTrueFalseTotal
unless ($h{$i}) 0 0 0
752 0 { $h{$i} = 1;
753 0 push @res,$i;
754 }
755 }
756 0 &pack_list(@res);
757 }
758
759 =head2 {max:var1,var2...}
760
761 =cut
762
763 sub func_max
764 1 ▶{ my ($this, $val) = @_;
Subroutine func_max: called CC=3 SCAR=11.3
Pod undocumented
765 1 my ($tot, $var);
766 1 $tot = $val->[0];
767 1 foreach $var(@$val)
768 0 ▶ { if ($tot > $var) { $tot = $var; } }
Branch: 1 branch
BranchTrueFalseTotal
if ($tot > $var) 0 3 3
769 1 $tot;
770 }
771
772 =head2 {midstr:string,start[,end]}
773
774 =cut
775
776 sub func_midstr
777 0 ▶{ my ($this, $val) = @_;
Subroutine func_midstr: not called CC=1 SCAR=6.9
Pod undocumented
778 0 my ($str, $pos1, $pos2);
779 0 substr ($str, $pos1, $pos2);
780 }
781
782 =head2 {min:var1,var2...}
783
784 =cut
785
786 sub func_min
787 1 ▶{ my ($this, $val) = @_;
Subroutine func_min: called CC=3 SCAR=11.3
Pod undocumented
788 1 my ($tot, $var);
789 1 $tot = $val->[0];
790 1 foreach $var(@$val)
791 0 ▶ { if ($tot > $var) { $tot = $var; } }
Branch: 1 branch
BranchTrueFalseTotal
if ($tot > $var) 0 3 3
792 1 $tot;
793 }
794
795 =head2 {mklist:list items}
796
797 =cut
798
799 sub func_mklist
800 3 ▶{ my ($this, $val) = @_;
Subroutine func_mklist: called CC=1 SCAR=0.0
Pod undocumented
801 #join "\n", @$val;
802 3 &pack_list(&unpack_list($val));
803 }
804
805 =head2 {mod:num1,num2}
806
807 =cut
808
809 sub func_mod
810 1 ▶{ my ($this, $val) = @_;
Subroutine func_mod: called CC=1 SCAR=0.0
Pod undocumented
811 1 $val->[0] % $val->[1];
812 }
813
814 =head2 {mult:num1,num2...}
815
816 =cut
817
818 sub func_mult
819 1 ▶{ my ($this, $val) = @_;
Subroutine func_mult: called CC=2 SCAR=6.9
Pod undocumented
820 1 my ($num, $tot);
821 1 $tot = 1;
822 1 foreach $num (@$val)
823 3 { $tot *= $num; }
824 1 $tot;
825 }
826
827 sub func_name
828 0 ▶{ }
Subroutine func_name: not called CC=1 SCAR=0.0
Pod undocumented
829
830 =head2 {ne:var1,var2}
831
832 =cut
833
834 sub func_ne
835 1 ▶{ my ($this, $val) = @_;
Subroutine func_ne: called CC=1 SCAR=0.0
Pod undocumented
836 1 $val->[0] ne $val->[1];
837 }
838
839 =head2 {neighbors:varname,pattern,code}
840
841 =cut
842
843 sub func_neighbors
844 1 ▶{ my ($this, $params) = @_;
Subroutine func_neighbors: called CC=4 SCAR=15.9
Pod undocumented
845 1 my ($varname,$pattern,$expr, @list, $val, $res, $result);
846 1 ($varname, $params) = &parse_parameter($this, $params);
847 1 ($pattern, $expr) = &parse_parameter($this, $params);
848 1 @list = eval {&mpi_neighbors($this->{'_node'}, $pattern, $this)};
849 1 foreach $val(@list)
850 1 { $this->{$varname} = $val;
851 1 ($res, $params) = &parse_parameter($this, $expr);
852 1 $result .= $res;
853 }
854 1 ▶ if (@list == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@list == 0) 0 1 1
855 0 { $res = "";
856 0 $params = &skip_parameters($this, $expr);
857 0 $params =~ /^\}(.*)/;
858 0 ▶ $params = $! || $params;
Condition0%0/3
$! || $params
l!l&&r!l&&!r
000
MC/DC0%0/2
$! || $params
$! $params
Truth table0%0/3
A || B
A= $!B= $params
ABresult
1X1
011
000
859 }
860 1 ($res, $params);
861 }
862
863 =head2 {neighbors2:pattern}
864
865 =cut
866
867 sub func_neighbors2
868 0 ▶{ my ($this, $params) = @_;
Subroutine func_neighbors2: not called CC=1 SCAR=6.9
Pod undocumented
869 0 my ($pattern) = @$params;
870 0 &pack_list(eval {&mpi_neighbors($this->{'_node'}, $pattern, $this)});
871 }
872
873
874 =head2 {nl:}
875
876 =cut
877
878 sub func_nl
879 1 ▶{ "\n"; }
Subroutine func_nl: called CC=1 SCAR=0.0
Pod undocumented
880
881 =head2 {not:var}
882
883 =cut
884
885 sub func_not
886 1 ▶{ my ($this, $val) = @_;
Subroutine func_not: called CC=1 SCAR=0.0
Pod undocumented
887 1 !($val->[0]);
888 }
889
890 =head2 {null:...}
891
892 =cut
893
894 sub func_null
895 1 ▶{ ""; }
Subroutine func_null: called CC=1 SCAR=0.0
Pod undocumented
896
897 =head2 {or:var1,var2...}
898
899 =cut
900
901 sub func_or
902 1 ▶{ my ($this, $val) = @_;
Subroutine func_or: called CC=3 SCAR=11.0
Pod undocumented
903 1 my ($num, $tot);
904 1 foreach $num (@$val)
905 { #$tot ||= $num;
906 3 ▶ if (!$num) { $tot = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($num) 1 2 3
907 }
908 1 $tot;
909 }
910
911 sub func_parse
912 0 ▶{ }
Subroutine func_parse: not called CC=1 SCAR=0.0
Pod undocumented
913
914 =head2 {prop:property,node}
915
916 =cut
917
918 sub func_prop
919 1 ▶{ my ($this, $val) = @_;
Subroutine func_prop: called CC=3 SCAR=11.8
Pod undocumented
920 1 my ($prop, $obj) = @$val;
921 1 ▶ $obj = $obj || $this->{"_node"};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
922 1 ▶ eval {&mpi_prop($obj, $prop, $this)} || "";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &mpi_prop($obj, $prop, $this) } } or "" 1 0 1
923 }
924
925 =head2 {rand:props[,obj]}
926
927 =cut
928
929 sub func_rand
930 0 ▶{ my ($this, $val) = @_;
Subroutine func_rand: not called CC=2 SCAR=17.9
Pod undocumented
931 0 my ($list, $obj) = @$val;
932 0 my (@list, $i);
933 0 ▶ $obj = $obj || $this->{"_node"};
Condition0%0/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table0%0/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
934 0 @list = eval{&mpi_props($obj, $list, $this)};
935 0 eval(&mpi_prop($obj, $list[int(rand @list)], $this));
936 }
937
938 =head2 {secs:}
939
940 =cut
941
942 sub func_secs
943 1 ▶{ time(); }
Subroutine func_secs: called CC=1 SCAR=0.0
Pod undocumented
944
945 sub func_select
946 0 ▶{ }
Subroutine func_select: not called CC=1 SCAR=0.0
Pod undocumented
947
948 =head2 {set:var,val}
949
950 =cut
951
952 sub func_set
953 3 ▶{ my ($this, $val) = @_;
Subroutine func_set: called CC=2 SCAR=7.6
Pod undocumented
954 3 my ($var, $v) = @$val;
955 3 ▶ if ($var =~ /^[a..zA..Z]/) # some vars are reserved for engine use
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^[a..zA..Z]/) 0 3 3
956 0 { $this->{$var} = $v; }
957 }
958
959 =head2 {sign:num}
960
961 =cut
962
963 sub func_sign
964 1 ▶{ my ($this, $val) = @_;
Subroutine func_sign: called CC=1 SCAR=0.0
Pod undocumented
965 1 $val->[0] <=> 0;
966 }
967
968 =head2 {smatch:string,pattern}
969
970 =cut
971
972 sub func_smatch
973 1 ▶{ my ($this, $val) = @_;
Subroutine func_smatch: called CC=1 SCAR=0.0
Pod undocumented
974 1 my ($str, $pat) = @$val;
975 1 $str =~ /($pat)/;
976 1 $1
977 }
978
979 sub func_stimestr
980 0 ▶{ }
Subroutine func_stimestr: not called CC=1 SCAR=0.0
Pod undocumented
981
982 =head2 {store:val,property[,node]}
983
984 =cut
985
986 sub func_store
987 1 ▶{ my ($this, $val) = @_;
Subroutine func_store: called CC=3 SCAR=11.8
Pod undocumented
988 1 my ($str, $prop, $obj) = @$val;
989 1 ▶ $obj = $obj || $this->{'_node'};
Condition33%1/3
$obj || $this->{'_node'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$obj || $this->{'_node'}
$obj $this->{'_node'}
Truth table33%1/3
A || B
A= $objB= $this->{'_node'}
ABresult
1X1
011
000
990 1 ▶ eval {&mpi_propset($obj, $prop, $str, $this)} || "";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &mpi_propset($obj, $prop, $str, $this) } } or "" 1 0 1
991 }
992
993 =head2 {strip:string}
994
995 =cut
996
997 sub func_strip
998 1 ▶{ my ($this, $val) = @_;
Subroutine func_strip: called CC=1 SCAR=0.0
Pod undocumented
999 1 chomp $val->[0];
1000 1 $val->[0] =~ s/^\s*//;
1001 1 $val->[0] =~ s/\s*$//;
1002 1 $val->[0];
1003 }
1004
1005 =head2 {strlen:string}
1006
1007 =cut
1008
1009 sub func_strlen
1010 1 ▶{ my ($this, $val) = @_;
Subroutine func_strlen: called CC=1 SCAR=0.0
Pod undocumented
1011 1 length $val->[0];
1012 }
1013
1014 =head2 {sublist:list,pos1,pos2[,sep]}
1015
1016 =cut
1017
1018 sub func_sublist
1019 0 ▶{ my ($this, $val) = @_;
Subroutine func_sublist: not called CC=2 SCAR=17.9
Pod undocumented
1020 0 my ($list, $pos1, $pos2, $sep) = @$val;
1021 0 my @list = &unpack_list($list, $sep);
1022 0 ▶ if (!defined($pos2)) { $pos2 = @list; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pos2) 0 0 0
1023 0 &pack_list( splice( @list, $pos1+1, $pos2-$pos1) );
1024 }
1025
1026 =head2 {subst:string,old,new}
1027
1028 =cut
1029
1030 sub func_subst
1031 1 ▶{ my ($this, $val) = @_;
Subroutine func_subst: called CC=1 SCAR=0.0
Pod undocumented
1032 1 my ($str, $old, $new) = @$val;
1033 1 $str =~ s/$old/$new/g;
1034 1 $str;
1035 }
1036
1037 =head2 {subt:num1,num2...}
1038
1039 =cut
1040
1041 sub func_subt
1042 1 ▶{ my ($this, $val) = @_;
Subroutine func_subt: called CC=2 SCAR=6.9
Pod undocumented
1043 1 my ($num, $tot);
1044 1 $tot = shift @$val;
1045 1 foreach $num (@$val)
1046 2 { $tot -= $num; }
1047 1 $tot;
1048 }
1049
1050 =head2 {time:}
1051
1052 =cut
1053
1054 sub func_time
1055 1 ▶{ my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time());
Subroutine func_time: called CC=2 SCAR=7.0
Pod undocumented
1056 1 ▶ if ($year < 1000) { $year += 1900; }
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 1000) 1 0 1
1057 1 "$hour:$min:$sec";
1058 }
1059
1060 sub func_timestr
1061 0 ▶{ }
Subroutine func_timestr: not called CC=1 SCAR=0.0
Pod undocumented
1062
1063 sub func_timesub
1064 0 ▶{ }
Subroutine func_timesub: not called CC=1 SCAR=0.0
Pod undocumented
1065
1066 =head2 {tolower:string}
1067
1068 =cut
1069
1070 sub func_tolower
1071 1 ▶{ my ($this, $val) = @_;
Subroutine func_tolower: called CC=1 SCAR=0.0
Pod undocumented
1072 1 lc $val->[0];
1073 }
1074
1075 =head2 {toupper:string}
1076
1077 =cut
1078
1079 sub func_toupper
1080 2 ▶{ my ($this, $val) = @_;
Subroutine func_toupper: called CC=1 SCAR=0.0
Pod undocumented
1081 2 uc $val->[0];
1082 }
1083
1084 sub func_tzoffset
1085 0 ▶{ }
Subroutine func_tzoffset: not called CC=1 SCAR=0.0
Pod undocumented
1086
1087 =head2 {v:varname}
1088
1089 =cut
1090
1091 sub func_v
1092 16 ▶{ my ($this, $val) = @_;
Subroutine func_v: called CC=1 SCAR=0.0
Pod undocumented
1093 16 $this->{$val->[0]};
1094 }
1095
1096 =head2 {version:}
1097
1098 =cut
1099
1100 sub func_version
1101 1 ▶{ $VERSION; }
Subroutine func_version: called CC=1 SCAR=0.0
Pod undocumented
1102
1103 =head2 {while:condition,command}
1104
1105 =cut
1106
1107 sub chk_cond
1108 3 ▶{ my ($this, $cond) = @_;
Subroutine chk_cond: called CC=1 SCAR=0.0
Pod undocumented
1109 3 my ($res) = &parse_parameter($this, $cond);
1110 # debug
1111 # print "cond $res -- ";
1112 3 $res;
1113 }
1114
1115 sub func_while
1116 1 ▶{ my ($this, $params) = @_;
Subroutine func_while: called CC=3 SCAR=11.0
Pod undocumented
1117 1 my ($go,$cond,$expr,$sep, $val, $res, $result, %save, $maxloop);
1118 1 $cond = $params;
1119 1 ($expr) = &skip_param($this, $params);
1120 1 ($params) = &skip_param($this, $expr);
1121 1 $maxloop = 255; #sanity
1122 1 ▶ while (&chk_cond($this, $cond) && ($maxloop >= 0))
Branch: 1 branch
BranchTrueFalseTotal
if (&chk_cond($this, $cond) and $maxloop >= 0) 2 1 3
Condition66%2/3
&chk_cond($this, $cond) and $maxloop >= 0
!ll&&!rl&&r
102
MC/DC50%1/2
&chk_cond($this, $cond) and $maxloop >= 0
&chk_cond($this, $cond) $maxloop >= 0
Truth table66%2/3
A and B
A= &chk_cond($this, $cond)B= $maxloop >= 0
ABresult
0X0
100
111
1123 2 { ($res, $params) = &parse_parameter($this, $expr);
1124 2 $result .= $res;
1125 2 $maxloop --;
1126 }
1127 1 ($result, $params);
1128 }
1129
1130 =head2 {with:varname...}
1131
1132 =cut
1133
1134 sub func_with
1135 1 ▶{ my ($this, $params) = @_;
Subroutine func_with: called CC=3 SCAR=11.0
Pod undocumented
1136 1 my ($varname,$expr,$val, $res, %save);
1137 1 ($varname, $expr) = &parse_parameter($this, $params);
1138 1 foreach $val(split /:/, $varname)
1139 1 { $save{$val} = $this->{$val};
1140 1 $this->{$val} = ''; # a 'null' that isn't undef
1141 }
1142 1 ($res, $params) = &parse_parameter($this, $expr);
1143 1 foreach $val(split /:/, $varname)
1144 1 { $this->{$val} = $save{$val}; }
1145 1 ($res, $params);
1146 }
1147
1148 =head2 {xor:num1,num2...}
1149
1150 =cut
1151
1152 sub func_xor
1153 1 ▶{ my ($this, $val) = @_;
Subroutine func_xor: called CC=3 SCAR=11.2
Pod undocumented
1154 1 my ($num, $tot);
1155 1 $tot = shift @$val;
1156 1 foreach $num (@$val)
1157 2 ▶ { $tot = ($tot xor $num); }
Condition50%2/4
$tot ^^ $num
l&&rl&&!r!l&&r!l&&!r
1010
MC/DC50%1/2
$tot ^^ $num
$tot $num
Truth table50%2/4
A ^^ B
A= $totB= $num
ABresult
110
101
011
000
1158 1 $tot;
1159 }
1160
1161 # ====================================================
1162 # core routines
1163 # ====================================================
1164 =head2 -
1165
1166 =cut
1167
1168 =head1 Public object methods
1169
1170 =cut
1171
1172 =head2 new(noderef);
1173
1174 Create new MPI object.
1175
1176 =cut
1177
1178 sub new
1179 1 ▶{ my ($class, $node) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
1180 1 my (%this);
1181 1 $this{'_node'} = $node;
1182 1 bless \%this, $class;
1183 }
1184
1185 =head2 $mpi->setvar(var,val);
1186
1187 Sets a variable in the mpi object to a scalar value.
1188
1189 =cut
1190
1191 sub setvar
1192 0 ▶{ my ($this, $var, $val) = @_;
Subroutine setvar: not called CC=1 SCAR=6.9
Pod documented
1193 0 $this->{$var} = $val;
1194 }
1195
1196 =head2 $mpi->readvar(var);
1197
1198 Reads a scalar value from the mpi object
1199
1200 =cut
1201
1202 sub readvar
1203 0 ▶{ my ($this, $var) = @_;
Subroutine readvar: not called CC=1 SCAR=6.9
Pod documented
1204 0 $this->{$var};
1205 }
1206
1207 # unpack a list in either MPI \n delimited string or perl list ref
1208 sub unpack_list
1209 8 ▶{ my ($list, $sep) = @_;
Subroutine unpack_list: called CC=3 SCAR=11.0
Pod undocumented
1210 8 my (@list);
1211 8 ▶ if (ref $list)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $list) { } 3 5 8
1212 3 { @list = @$list; }
1213 else
1214 5 ▶ { $sep = $sep || "\n";
Condition50%1/2
$sep || "\n"
l!l
05
MC/DC0%0/1
$sep || "\n"
$sep
Truth table50%1/2
A
A= $sep
Aresult
11
00
1215 5 @list = split "\n", $list;
1216 }
1217 8 @list;
1218 }
1219
1220 sub pack_list
1221 0 ▶{ if ($perl_list) {return \@_}
Subroutine pack_list: called CC=2 SCAR=8.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($Language::MPI::perl_list) { } 0 6 6
1222 else
1223 6 { join "\n", @_; }
1224 }
1225
1226 # parse 1 parameter, which may contain a mix of plain text and MPI functions
1227 sub parse_parameter
1228 215 ▶{ my ($this, $text) = @_;
Subroutine parse_parameter: called CC=4 SCAR=13.9
Pod undocumented
1229 215 my ($result, $prefix, $remainder, $match, $value);
1230 215 $result = "";
1231 # find start of MPI function or terminating comma
1232 215 ▶ while ($text =~ /(,|\}|\{\w+:?)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(,|\}|\{\w+:?)/) 230 66 296
1233 230 { $match = $1;
1234 # terminating comma or '}', split remaining text into result and remainder
1235 230 ▶ if ($match =~ /(,|\})/)
Branch: 2 branches
BranchTrueFalseTotal
if ($match =~ /(,|\})/) { } 149 81 230
elsif ($match =~ /\{(\w+)/) { } 81 0 81
1236 149 { ($prefix, $remainder) = split $match, $text, 2;
1237 149 $result .= $prefix;
1238 149 return ($result, $remainder, $match);
1239 }
1240 # mpi function, evaluate
1241 elsif ($match =~ /\{(\w+)/ )
1242 81 { ($prefix, $remainder) = split $match, $text, 2;
1243 81 $result .= $prefix;
1244 81 ($value, $remainder) = &eval_mpi($this, $1, $remainder);
1245 #if (! defined($value))
1246 #{ "catch"; }
1247 81 $result .= $value;
1248 81 $text = $remainder;
1249 }
1250 }
1251 # nothing left to parse
1252 66 ($result.$text, '', '');
1253 }
1254
1255 # skip a parameter
1256 sub skip_param
1257 4 ▶{ my ($this, $text) = @_;
Subroutine skip_param: called CC=4 SCAR=14.1
Pod undocumented
1258 4 my ($match, $prefix, $remainder);
1259 4 ▶ while ($text =~ /(,|\}|\{\w+:?)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(,|\}|\{\w+:?)/) 8 0 8
1260 8 { $match = $1;
1261 # terminating comma or }, split remaining text into result and remainder
1262 8 ▶ if ($match =~ /([,\}])/)
Branch: 2 branches
BranchTrueFalseTotal
if ($match =~ /([,\}])/) { } 4 4 8
elsif ($match =~ /\{(\w+)/) { } 4 0 4
1263 4 { ($prefix, $remainder) = split $1, $text, 2;
1264 4 return ($remainder, $match);
1265 }
1266 # mpi function, recurse in and skip
1267 elsif ($match =~ /\{(\w+)/ )
1268 4 { ($prefix, $remainder) = split $match, $text, 2;
1269 4 ($remainder) = &skip_parameters($this, $remainder);
1270 4 $text = $remainder;
1271 }
1272 }
1273 # nothing left to parse
1274 0 ('');
1275 }
1276
1277 # skip all remaining parameters
1278 sub skip_parameters
1279 6 ▶{ my ($this, $text) = @_;
Subroutine skip_parameters: called CC=4 SCAR=14.0
Pod undocumented
1280 6 my ($match, $prefix, $prefix1, $remainder);
1281 6 ▶ while ($text =~ /(\}|\{\w+:?)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(\}|\{\w+:?)/) 7 0 7
1282 7 { $match = $1;
1283 # terminating }, split remaining text into result and remainder
1284 7 ▶ if ($match =~ /([\}])/)
Branch: 2 branches
BranchTrueFalseTotal
if ($match =~ /([\}])/) { } 6 1 7
elsif ($match =~ /\{(\w+)/) { } 1 0 1
1285 6 { ($prefix, $remainder) = split $1, $text, 2;
1286 6 $prefix1 .= $prefix;
1287 6 return ($remainder, $prefix1, $1);
1288 }
1289 # mpi function, recurse in and skip
1290 elsif ($match =~ /\{(\w+)/ )
1291 1 { ($prefix, $remainder) = split $match, $text, 2;
1292 1 $prefix1 .= $prefix.$match;
1293 1 ($remainder, $prefix, $match) = &skip_parameters($this, $remainder);
1294 1 $prefix1 .= $prefix.$match;
1295 1 $text = $remainder;
1296 }
1297 }
1298 # nothing left to parse
1299 0 ('');
1300 }
1301
1302 # parse all parameters for the current function
1303 sub parse_parameters
1304 78 ▶{ my ($this, $text) = @_;
Subroutine parse_parameters: called CC=2 SCAR=6.9
Pod undocumented
1305 78 my @params;
1306 78 my ($result, $term);
1307 78 $term = "zz";
1308 78 ▶ while ($term =~ /[^\}]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($term =~ /[^\}]/) 131 78 209
1309 131 { ($result, $text, $term) = &parse_parameter($this, $text);
1310 131 push @params, $result;
1311 }
1312 78 (\@params, $text);
1313 }
1314
1315 # evaluate 1 MPI function
1316 sub eval_mpi
1317 81 ▶{ my ($this, $function, $text) = @_;
Subroutine eval_mpi: called CC=6 SCAR=21.6
Pod undocumented
1318 81 my ($result, $remainder, $params);
1319 81 $function = lc $function;
1320 81 $result = "";
1321 # if function is in control function list, pass raw text and let function parse.
1322 81 ▶ if ($ctrl_functions{$function})
Branch: 3 branches
BranchTrueFalseTotal
if ($ctrl_functions{$function}) { } 7 74 81
elsif ($simp_functions{$function}) { } 73 1 74
elsif ($$this{"_f_$function"}) { } 0 1 1
1323 7 { ($result, $remainder) = &{$ctrl_functions{$function}}($this, $text);
1324 }
1325 # parse parameters and pass results to function.
1326 elsif ($simp_functions{$function})
1327 73 { ($params, $remainder) = &parse_parameters($this, $text);
1328 73 ($result) = &{$simp_functions{$function}}($this, $params);
1329 }
1330 # else concat parameters
1331 elsif ($this->{"_f_$function"})
1332 0 { my (@vars, $var, $i, %save);
1333 0 ($params, $remainder) = &parse_parameters($this, $text);
1334 0 @vars = split /:/, $this->{"_f_$function v"};
1335 0 ▶ for ($i = 0; $i < @vars; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @vars) 0 0 0
1336 0 { $var = $vars[$i];
1337 0 $save{$var} = $this->{$var};
1338 0 $this->{$var} = $params->[$i];
1339 }
1340 0 $result = &parse($this, $this->{"_f_$function"});
1341 0 foreach $var(split /:/, $this->{"_f_$function v"})
1342 0 { $this->{$var} = $save{$var}; }
1343 }
1344 else
1345 1 { ($params, $remainder) = &parse_parameters($this, $text);
1346 1 $result = join (',', @$params);
1347 }
1348 81 ($result, $remainder);
1349 }
1350
1351 =head2 $mpi->parse(string);
1352
1353 Processes a string for MPI codes
1354
1355 =cut
1356
1357 # parse a text block. simular to parse_parameter, except not terminating at ','
1358 sub parse
1359 65 ▶{ my ($this, $text) = @_;
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
1360 65 my ($result, $value, $term);
1361 # while we have unprocessed text
1362 # find MPI, if any.
1363 # preceeding text copied to result.
1364 # MPI evaluated and retuned values added to result.
1365
1366 65 $term = "zz"; # meaningless except not null
1367 65 ▶ while ($term)
Branch: 1 branch
BranchTrueFalseTotal
if ($term) 66 65 131
1368 66 { ($value, $text, $term) = &parse_parameter($this, $text);
1369 66 $result .= $value.$term;
1370 }
1371
1372 65 $result;
1373 }
1374
1375 1 1;
1376
1377 __END__
↑ Summary