blib/lib/Eobj/PLroot.pl

filter: Statementstmt 22.8% 62 / 271 Branchbran 13.0% 17 / 130 Conditioncond 11.1% 2 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 33.3% 8 / 24 Podpod n/a totaltotal 19.6% 89 / 454 CC 78 SCAR 41.5
CC
78
Cov
19%
objdump
182.0
const
137.9
prettyval
110.0
CRAP 63.4
« blib/lib/Eobj/PLerrsys.pm ↑ Summary blib/lib/Eobj.pm »
1 #
2 # This file is part of the Eobj project.
3 #
4 # Copyright (C) 2003, Eli Billauer
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #
20 # A copy of the license can be found in a file named "licence.txt", at the
21 # root directory of this project.
22 #
23  
24 # Eobj's basic root class
25 ${__PACKAGE__.'::errorcrawl'}='system';
26 #our $errorcrawl='system';
27 2 ▶sub new {
Subroutine new: called CC=8 SCAR=22.6
28 2 my $this = shift;
29 2 my $self = $this->SUPER::new(@_);
30 2 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
31 2 ▶ $self = {} unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 2 0 2
32 2 bless $self, $class;
33 2 $self->store_hash([], @_);
34  
35 2 my $name = $self->get('name');
36  
37 2 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 2 0 2
38 2 ▶ puke("New \'$class\' object created with illegal name: ".$self->prettyval($name)."\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^[a-zA-Z_]\w*$/ 0 2 2
39 unless ($name=~/^[a-zA-Z_]\w*$/);
40  
41 blow("New \'$class\' object created with an already occupied name: \'$name\'\n")
42 2 ▶ if (exists $Eobj::objects{$name});
Branch: 1 branch
BranchTrueFalseTotal
if exists $Eobj::objects{$name} 0 2 2
43 2 my $lc = lc($name);
44 2 foreach (keys %Eobj::objects) {
45 1 ▶ blow("New \'$class\' object created with a name \'$name\' when \'$_\' is already in the system (only case difference)\n")
Branch: 1 branch
BranchTrueFalseTotal
if lc $_ eq $lc 0 1 1
46 if (lc($_) eq $lc);
47 }
48 } else {
49 # No name given? Let's be forgiving, and give one of our own...
50 0 $name = $self->suggestname('DefaultName');
51 0 $self->const('name', $name);
52 }
53 2 $Eobj::objects{$name}=$self;
54  
55 2 $self -> const('eobj-object-count', $Eobj::objectcounter++);
56 2 return $self;
57 }
58  
59 2 ▶sub destroy {
Subroutine destroy: called CC=1 SCAR=0.0
60 2 my $self = shift;
61 2 my $name = $self->get('name');
62  
63 2 delete $Eobj::objects{$name};
64 2 bless $self, 'PL_destroyed';
65 2 undef %{$self};
66  
67 2 return undef;
68 }
69  
70 2 ▶sub survivor { } # So method is recognized
Subroutine survivor: called CC=1 SCAR=0.0
71  
72 0 ▶sub who {
Subroutine who: not called CC=1 SCAR=6.9
73 0 my $self = shift;
74 0 return "object \'".$self->get('name')."\'";
75 }
76  
77 0 ▶sub safewho {
Subroutine safewho: not called CC=2 SCAR=17.9
78 0 my ($self, $who) = @_;
79 0 ▶ return "(non-object item)" unless ($self->isobject($who));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isobject($who) 0 0 0
80 0 return $who->who;
81 }
82  
83 0 ▶sub isobject {
Subroutine isobject: not called CC=2 SCAR=17.9
84 0 my ($self, $other) = @_;
85 0 my $r = ref $other;
86 0 ▶ return 1 if (Eobj::definedclass($r) == 2);
Branch: 1 branch
BranchTrueFalseTotal
if Eobj::definedclass($r) == 2 0 0 0
87 0 return undef;
88 }
89  
90 0 ▶sub objbyname {
Subroutine objbyname: not called CC=1 SCAR=6.9
91 0 my ($junk, $name) = @_;
92 0 return $Eobj::objects{$name};
93 }
94  
95 0 ▶sub suggestname {
Subroutine suggestname: not called CC=4 SCAR=30.0
96 0 my ($self, $name) = @_;
97 0 my $sug = $name;
98 0 my ($bulk, $num) = ($name =~ /^(.*)_(\d+)$/);
99 0 my %v;
100  
101 0 foreach (keys %Eobj::objects) { $v{lc($_)}=1; } # Store lowercased names
102 0 ▶ unless (defined $bulk) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bulk) 0 0 0
103 0 $bulk = $name;
104 0 $num = 0;
105 }
106
107 0 ▶ while ($v{lc($sug)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v{lc $sug}) 0 0 0
108 0 $num++;
109 0 $sug = $bulk.'_'.$num;
110 }
111 0 return $sug;
112 }
113  
114 7 ▶sub get {
Subroutine get: called CC=5 SCAR=19.4
115 7 my $self = shift;
116 7 my $prop = shift;
117 7 my $final;
118  
119 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 7 7
120  
121 7 $final = $self->{join("\n", 'plPROP', @path)};
122  
123 # Now try to return it the right way. If we have a reference, then
124 # the property is set. So if the calling context wants an array, why
125 # hassle? Let's just give an array.
126 # But if a scalar is expected, and we happen to have only one
127 # member in the list -- let's be kind and give the first value
128 # as a scalar.
129  
130 7 ▶ if (ref($final)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $final) 7 0 7
131 0 ▶ return @{$final} if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 7 7
132 7 return ${$final}[0];
133 }
134  
135 # We got here, so the property wasn't defined. Now, if
136 # we return an undef in an array context, it's no good, because it
137 # will be considered as a list with lenght 1. If the property
138 # wasn't defined we want to say "nothing" -- and that's an empty list.
139  
140 0 ▶ return () if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
141  
142 # Wanted a scalar? Undef is all we can offer now.
143  
144 0 return undef;
145 }
146  
147 8 ▶sub getraw {
Subroutine getraw: called CC=1 SCAR=0.0
148 8 my $self = shift;
149
150 8 return $self->{join("\n", 'plPROP', @_)};
151 }
152  
153 2 ▶sub store_hash {
Subroutine store_hash: called CC=4 SCAR=15.5
154 2 my $self = shift;
155 2 my $rpath = shift;
156 2 my @path = @{$rpath};
157 2 my %h = @_;
158  
159 2 foreach (keys %h) {
160 2 my $val = $h{$_};
161  
162 2 ▶ if (ref($val) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'HASH') { } 0 2 2
elsif (ref $val eq 'ARRAY') { } 0 2 2
163 0 $self->store_hash([@path, $_], %{$val});
164 } elsif (ref($val) eq 'ARRAY') {
165 0 $self->const([@path, $_], @{$val});
166 } else {
167 2 $self->const([@path, $_], $val);
168 }
169 }
170 }
171  
172 4 ▶sub const {
Subroutine const: called CC=16 SCAR=49.3
173 4 my $self = shift;
174 4 my $prop = shift;
175  
176 4 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 2 2 4
177  
178 4 my @newval = @_;
179  
180 4 my $pre = $self->getraw(@path);
181  
182 4 ▶ if (defined($pre)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pre) { } 0 4 4
183 0 ▶ puke("Attempt to change a settable property into constant\n")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pre eq "PL_const" 0 0 0
184 unless (ref($pre) eq 'PL_const');
185  
186 0 my @pre = @{$pre};
187  
188 0 my $areeq = ($#pre == $#newval);
189 0 my $i;
190 0 my $eq = $self->get(['plEQ',@path]);
191  
192 0 ▶ if (ref($eq) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $eq eq 'CODE') { } 0 0 0
193 0 ▶ for ($i=0; $i<=$#pre; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#pre) 0 0 0
194 0 ▶ $areeq = 0 unless (&{$eq}($pre[$i], $newval[$i]));
Branch: 1 branch
BranchTrueFalseTotal
unless &{$eq;}($pre[$i], $newval[$i]) 0 0 0
195 }
196 } else {
197 0 ▶ for ($i=0; $i<=$#pre; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#pre) 0 0 0
198 0 ▶ $areeq = 0 unless ($pre[$i] eq $newval[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless $pre[$i] eq $newval[$i] 0 0 0
199 }
200 }
201  
202 0 ▶ unless ($areeq) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($areeq) 0 0 0
203 0 ▶ if (($#path==2) && ($path[0] eq 'vars') && ($path[2] eq 'dim')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#path == 2 and $path[0] eq 'vars' and $path[2] eq 'dim') { } 0 0 0
Condition0%0/6
$#path == 2 and $path[0] eq "vars" and $path[2] eq "dim"
!ll&&!rl&&r
000
$#path == 2 and $path[0] eq "vars"
!ll&&!rl&&r
000
MC/DC0%0/3
$#path == 2 and $path[0] eq "vars" and $path[2] eq "dim"
$#path == 2 $path[0] eq "vars" $path[2] eq "dim"
Truth table0%0/4
A and B and C
A= $#path == 2B= $path[0] eq "vars"C= $path[2] eq "dim"
ABCresult
0XX0
10X0
1100
1111
204 # This is dimension inconsintency. Will happen a lot to novices,
205 # and deserves a special error message.
206 0 wrong("Conflict in setting the size of variable \'$path[1]\' in ".
207 $self->who.". The conflicting values are ".
208 $self->prettyval(@pre)." and ".$self->prettyval(@newval).
209 ". (This usually happens as a result of connecting variables of".
210 " different sizes, possibly indirectly)\n");
211
212
213 } else {
214 0 { local $@; require Eobj::PLerrsys; } # XXX fix require to not clear $@?
215 0 my ($at, $hint) = &Eobj::PLerror::constdump();
216
217 0 wrong("Attempt to change constant value of \'".
218 join(",",@path)."\' to another unequal value ".
219 "on ".$self->who." $at\n".
220 "Previous value was ".$self->prettyval(@pre).
221 " and the new value is ".$self->prettyval(@newval)."\n$hint\n");
222 }
223 }
224 } else {
225 4 ▶ if ($Eobj::callbacksdepth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Eobj::callbacksdepth) 0 4 4
226 0 my $prop = join ",",@path;
227 0 my $who = $self->who;
228 0 hint("On $who: \'$prop\' = ".$self->prettyval(@newval)." due to magic property setting\n");
229 }
230 4 $self->domutate((bless \@newval, 'PL_const'), @path);
231  
232 4 my $cbref = $self->getraw('plMAGICS', @path);
233 4 ▶ return unless (ref($cbref) eq 'PL_settable');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cbref eq "PL_settable" 4 0 4
234 0 my $subref;
235  
236 0 $Eobj::callbacksdepth++;
237 0 ▶ while (ref($subref=shift @{$cbref}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($subref = shift @{$cbref;}) eq "CODE") 0 0 0
238 0 &{$subref}($self, @path);
239 }
240 0 $Eobj::callbacksdepth--;
241 }
242 }
243  
244 0 ▶sub set {
Subroutine set: not called CC=4 SCAR=30.0
245 0 my $self = shift;
246 0 my $prop = shift;
247  
248 0 my @path;
249 0 ▶ @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
250  
251 0 my @newval = @_;
252  
253 0 my $pre = $self->getraw(@path);
254 0 my $ppp = ref($pre);
255 0 ▶ puke ("Attempted to set a constant property\n")
Branch: 1 branch
BranchTrueFalseTotal
if defined $pre and $ppp ne "PL_settable" 0 0 0
Condition0%0/3
defined $pre and $ppp ne "PL_settable"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pre and $ppp ne "PL_settable"
defined $pre $ppp ne "PL_settable"
Truth table0%0/3
A and B
A= defined $preB= $ppp ne "PL_settable"
ABresult
0X0
100
111
256 if ((defined $pre) && ($ppp ne 'PL_settable'));
257 0 $self->domutate((bless \@newval, 'PL_settable'), @path);
258 0 return 1;
259 }
260  
261 4 ▶sub domutate {
Subroutine domutate: called CC=4 SCAR=15.5
262 4 my $self = shift;
263 4 my $newval = shift;
264 4 my $def = 0;
265 0 ▶ $def=1 if ((defined ${$newval}[0]) || ($#{$newval}>0));
Branch: 1 branch
BranchTrueFalseTotal
if defined do { $newval }->[0] or $#{$newval;} > 0 4 0 4
Condition33%1/3
defined do { $newval }->[0] or $#{$newval;} > 0
l!l&&r!l&&!r
400
MC/DC0%0/2
defined do { $newval }->[0] or $#{$newval;} > 0
defined do { $newval }->[0] $#{$newval;} > 0
Truth table33%1/3
A or B
A= defined do { $newval }->[0]B= $#{$newval;} > 0
ABresult
1X1
011
000
266
267 4 ▶ if ($def) {
Branch: 1 branch
BranchTrueFalseTotal
if ($def) { } 4 0 4
268 4 $self->{join("\n", 'plPROP', @_)} = $newval;
269 0 } else { delete $self->{join("\n", 'plPROP', @_)}; }
270 4 return 1;
271 }
272  
273 0 ▶sub seteq {
Subroutine seteq: not called CC=3 SCAR=24.8
274 0 my $self = shift;
275 0 my $prop = shift;
276 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
277 0 my $eq = shift;
278 0 ▶ puke("Callbacks should be references to subroutines\n")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $eq eq "CODE" 0 0 0
279 unless (ref($eq) eq 'CODE');
280 0 $self->set(['plEQ', @path], $eq);
281 }
282  
283 0 ▶sub addmagic {
Subroutine addmagic: not called CC=3 SCAR=24.8
284 0 my $self = shift;
285 0 my $prop = shift;
286 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
287 0 my $callback = shift;
288  
289 0 ▶ unless (defined($self->get([@path]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->get([@path])) { } 0 0 0
290 0 $self->punshift(['plMAGICS', @path], $callback);
291 } else {
292 0 $Eobj::callbacksdepth++;
293 0 &{$callback}($self, @path);
294 0 $Eobj::callbacksdepth--;
295 }
296 }
297  
298 0 ▶sub pshift {
Subroutine pshift: not called CC=4 SCAR=30.0
299 0 my $self = shift;
300 0 my $prop = shift;
301 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
302 0 my $pre = $self->getraw(@path);
303 0 ▶ if (ref($pre) eq 'PL_settable') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pre eq 'PL_settable') { } 0 0 0
304 0 return shift @{$pre};
305 } else {
306 0 ▶ return $self->set($prop, undef) # We're changing a constant property here. Will puke.
Branch: 1 branch
BranchTrueFalseTotal
if defined $pre 0 0 0
307 if (defined $pre);
308 0 return undef; # There was nothing there.
309 }
310 }
311  
312 0 ▶sub ppop {
Subroutine ppop: not called CC=4 SCAR=30.0
313 0 my $self = shift;
314 0 my $prop = shift;
315 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
316 0 my $pre = $self->getraw(@path);
317 0 ▶ if (ref($pre) eq 'PL_settable') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pre eq 'PL_settable') { } 0 0 0
318 0 return pop @{$pre};
319 } else {
320 0 ▶ return $self->set($prop, undef) # We're changing a constant property here. Will puke.
Branch: 1 branch
BranchTrueFalseTotal
if defined $pre 0 0 0
321 if (defined $pre);
322 0 return undef; # There was nothing there.
323 }
324 }
325  
326 0 ▶sub punshift {
Subroutine punshift: not called CC=4 SCAR=30.0
327 0 my $self = shift;
328 0 my $prop = shift;
329 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
330
331 0 my @val = @_;
332  
333 0 my $pre = $self->getraw(@path);
334 0 ▶ if (ref($pre) eq 'PL_settable') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pre eq 'PL_settable') { } 0 0 0
335 0 unshift @{$pre}, @val;
336 } else {
337 0 ▶ $self->set(\@path, (defined($pre))? ($pre, @val) : @val);
Branch: 1 branch
BranchTrueFalseTotal
defined $pre ? : 0 0 0
338 }
339 }
340  
341 0 ▶sub ppush {
Subroutine ppush: not called CC=4 SCAR=30.0
342 0 my $self = shift;
343 0 my $prop = shift;
344 0 ▶ my @path = (ref($prop) eq 'ARRAY') ? @{$prop} : ($prop);
Branch: 1 branch
BranchTrueFalseTotal
ref $prop eq 'ARRAY' ? : 0 0 0
345
346 0 my @val = @_;
347  
348 0 my $pre = $self->getraw(@path);
349 0 ▶ if (ref($pre) eq 'PL_settable') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pre eq 'PL_settable') { } 0 0 0
350 0 push @{$pre}, @val;
351 } else {
352 0 ▶ $self->set(\@path, (defined($pre))? (@val, $pre) : @val);
Branch: 1 branch
BranchTrueFalseTotal
defined $pre ? : 0 0 0
353 }
354 }
355  
356 0 ▶sub globalobj {
Subroutine globalobj: not called CC=1 SCAR=6.9
357 0 return &Eobj::globalobj();
358 }
359  
360 0 ▶sub linebreak {
Subroutine linebreak: not called CC=1 SCAR=6.9
361 0 my $self = shift;
362 0 return &Eobj::linebreak(@_);
363 }
364  
365 0 ▶sub objdump {
Subroutine objdump: not called CC=13 SCAR=52.0
366 0 my $self = shift;
367 0 my @todump;
368  
369 0 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
370 0 @todump = sort {$Eobj::objects{$a}->get('eobj-object-count') <=>
371 0 $Eobj::objects{$b}->get('eobj-object-count')}
372 keys %Eobj::objects;
373 0 @todump = map {$Eobj::objects{$_}} @todump;
374 } else {
375 0 @todump = (@_);
376 }
377  
378 0 foreach my $obj (@todump) {
379 0 ▶ unless ($self->isobject($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->isobject($obj)) 0 0 0
380 0 my $r = $Eobj::objects{$obj};
381 0 ▶ if (defined $r) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r) { } 0 0 0
382 0 $obj = $r;
383 } else {
384 0 print "Unknown object specifier ".$self->prettyval($obj)."\n\n";
385 0 next;
386 }
387 }
388
389 0 my @prefix = ();
390 0 print $self->linebreak($self->safewho($obj).", class=\'".ref($obj)."\':")."\n";
391 0 my $indent = ' ';
392 0 foreach my $prop (sort keys %$obj) {
393 0 my @path = split("\n", $prop);
394 0 ▶ shift @path if ($path[0] eq 'plPROP');
Branch: 1 branch
BranchTrueFalseTotal
if $path[0] eq "plPROP" 0 0 0
395 0 my $propname = pop @path;
396  
397 # Now we make sure that the @path will be exactly like @prefix
398 # First, we shorten @prefix if it's longer than @path, or if it
399 # has items that are unequal to @path.
400  
401 0 CHOP: while (1) {
402 # If @prefix is longer, no need to check -- we need chopping
403 # anyhow
404 0 ▶ unless ($#path < $#prefix) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($#path < $#prefix) 0 0 0
405 0 my $i;
406 0 my $last = 1;
407 0 ▶ for ($i=0; $i<=$#prefix; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#prefix) 0 0 0
408 0 ▶ if ($prefix[$i] ne $path[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix[$i] ne $path[$i]) 0 0 0
409 0 $last = 0; last;
410 }
411 }
412 0 ▶ last CHOP if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 0 0 0
413 }
414 0 my $tokill = pop @prefix;
415 0 $indent = substr($indent, 0, -((length($tokill) + 3)));
416 }
417  
418 0 my $out = $indent;
419  
420 # And now we fill in the missing @path to @prefix
421 0 ▶ while ($#path > $#prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#path > $#prefix) 0 0 0
422 0 my $toadd = $path[$#prefix + 1];
423 0 push @prefix, $toadd;
424 0 $out .= "$toadd > ";
425 0 $toadd =~ s/./ /g; # Substitute any character with white space...
426 0 $indent .= "$toadd ";
427 }
428 0 $out .= "$propname=";
429  
430 # Now we pretty-print the value.
431 0 my $valref = $obj->{$prop};
432 0 ▶ my @val = (ref($valref)) ? @$valref : (undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $valref ? : 0 0 0
433
434 0 my $extraindent = $out;
435 0 $extraindent =~ s/./ /g;
436  
437 0 $out .= $self->prettyval(@val);
438  
439 # Finally, we do some linebreaking, so that the output will be neat
440 0 print $self->linebreak($out, $extraindent)."\n";
441 }
442 0 print "\n";
443 }
444 }
445  
446 0 ▶sub prettyval {
Subroutine prettyval: not called CC=10 SCAR=47.0
447 0 my $self = shift;
448 0 my $MaxListToPrint = 4;
449 0 my $MaxStrLen = 40;
450  
451 0 my @a = @_; # @a will be manipulated. Get a local copy
452  
453 0 ▶ if (@a > $MaxListToPrint) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a > $MaxListToPrint) 0 0 0
454 # cap the length of $#a and set the last element to '...'
455 0 $#a = $MaxListToPrint;
456 0 $a[$#a] = "...";
457 }
458 0 for (@a) {
459 # set args to the string "undef" if undefined
460 0 ▶ $_ = "undef", next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
461 0 ▶ if (ref $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
462 0 ▶ if ($Eobj::classes{ref($_)}) { # Is this a known object?
Branch: 1 branch
BranchTrueFalseTotal
if ($Eobj::classes{ref $_}) 0 0 0
463 0 $_='{'.$_->who.'}'; # Get the object's pretty ID
464 0 next;
465 }
466 # force reference to string representation
467 0 $_ .= '';
468 0 s/'/\\'/g;
469 }
470 else {
471 0 s/'/\\'/g;
472 # terminate the string early with '...' if too long
473 0 ▶ substr($_,$MaxStrLen) = '...'
Branch: 1 branch
BranchTrueFalseTotal
if $MaxStrLen and $MaxStrLen < length $_ 0 0 0
Condition0%0/3
$MaxStrLen and $MaxStrLen < length $_
!ll&&!rl&&r
000
MC/DC0%0/2
$MaxStrLen and $MaxStrLen < length $_
$MaxStrLen $MaxStrLen < length $_
Truth table0%0/3
A and B
A= $MaxStrLenB= $MaxStrLen < length $_
ABresult
0X0
100
111
474 if $MaxStrLen and $MaxStrLen < length;
475 }
476 # 'quote' arg unless it looks like a number
477 0 ▶ $_ = "'$_'" unless /^-?[\d.]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^-?[\d.]+$/ 0 0 0
478 # print high-end chars as 'M-<char>'
479 0 s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
480 # print remaining control chars as ^<char>
481 0 s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
482 }
483
484 # append 'all', 'the', 'data' to the $sub string
485 0 ▶ return ($#a != 0) ? '(' . join(', ', @a) . ')' : $a[0];
Branch: 1 branch
BranchTrueFalseTotal
$#a != 0 ? : 0 0 0
486 }
« blib/lib/Eobj/PLerrsys.pm ↑ Summary blib/lib/Eobj.pm »