blib/lib/Data/Dumper/Interp.pm

filter: Statementstmt 82.1% 1015 / 1236 Branchbran 63.7% 511 / 802 Conditioncond 61.9% 161 / 260 MC/DCmcdc 43.5% 64 / 147 Subroutinesub 79.1% 125 / 158 Podpod 62.5% 20 / 32 totaltotal 71.9% 1896 / 2635 CC 518 SCAR 42.3
CC
518
Cov
73%
_preprocess
973.0
_postprocess_DD_result
85.7
_Do
46.5
CRAP 69.0
↑ Summary
1 # License: Public Domain or CC0 See
2 # https://creativecommons.org/publicdomain/zero/1.0/
3 # The author, Jim Avera (jim.avera at gmail) has waived all copyright and
4 # related or neighboring rights. Attribution is requested but is not required.
5  
6 ##FIXME: Refaddr(1) has no effect inside Blessed structures
7 #
8  
9 ##use strict; use warnings FATAL => 'all'; use utf8;
10 15 ▶use strict; use warnings; use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 #use 5.010; # say, state
12 #use 5.011; # cpantester gets warning that 5.11 is the minimum acceptable
13 #use 5.014; # /r for non-destructive substitution
14 15 ▶use 5.018; # lexical_subs
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use feature qw(say state lexical_subs current_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 ▶use feature 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use feature 'unicode_strings';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package
20 # newline so Dist::Zilla::Plugin::PkgVersion won't add $VERSION
21 15 DB {
22 2414 ▶ sub DB_Vis_Evalwrapper {
Subroutine DB_Vis_Evalwrapper: called CC=1 SCAR=0.0
Pod undocumented
23 2414 eval $Data::Dumper::Interp::string_to_eval; ## no critic
24 }
25 }
26  
27 package Data::Dumper::Interp;
28  
29 15 ▶{ no strict 'refs'; ${__PACKAGE__."::VER"."SION"} = 997.999; }
Subroutine BEGIN: called CC=1 SCAR=0.0
30 15 our $VERSION = '8.002'; # VERSION from Dist::Zilla::Plugin::OurPkgVersion
31 15 our $DATE = '2026-06-23'; # DATE from Dist::Zilla::Plugin::OurDate
32  
33 # Arrgh! Moose forcibly enables experimental feature warnings!
34 # So import Moose first and then adjust warnings...
35 15 ▶use Moose 2.4000;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 15 extends 'Data::Visitor' => { -version => 0.32 },
38 'Exporter' => { -version => 5.57 },
39 ;
40  
41 15 ▶no warnings "experimental::lexical_subs";
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 15 ▶use constant _SUPPORTS_CORE_BOOLS => defined &builtin::is_bool;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 15 my $bitwise_supported;
45 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
46 15 ▶ $bitwise_supported = eval "use feature 'bitwise'";
Subroutine BEGIN: called CC=1 SCAR=0.0
47 15 warnings->unimport("experimental::builtin") if _SUPPORTS_CORE_BOOLS;
48 }
49 15 ▶use if $bitwise_supported, "feature", "bitwise";
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 15 ▶use re qw/is_regexp regexp_pattern/;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 15 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
53 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 15 ▶use POSIX qw(INT_MAX);
Subroutine BEGIN: called CC=1 SCAR=0.0
55 15 ▶use Scalar::Util qw(blessed reftype refaddr looks_like_number weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
56 15 ▶use List::Util 1.45 qw(min max first none all any sum0);
Subroutine BEGIN: called CC=1 SCAR=0.0
57 15 ▶use Data::Structure::Util qw/circular_off/;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 15 ▶use Regexp::Common qw/RE_balanced RE_quoted/;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 #use Term::ReadKey ();
60 15 ▶use Term::Size 0.211 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
61 15 ▶use Sub::Identify qw/sub_name sub_fullname get_code_location/;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 15 ▶use File::Basename qw/basename/;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 15 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 ############################ Exports #######################################
66 # Short-hand functions/methods are generated on demand (i.e. if imported or
67 # called as a method) based on a naming convention.
68 ############################################################################
69  
70 15 our @EXPORT = qw( visnew
71 vis avis hvis ivis dvis
72 viso aviso hviso iviso ivisO dviso dvisO
73 visq avisq hvisq ivisq dvisq
74 visr avisr hvisr ivisr dvisr
75 rvis rvisq
76 addrvis addrvisl
77 u quotekey qsh qshlist qshpath
78 );
79  
80 15 our @EXPORT_OK = qw(addrvis_digits
81 RefArgFormatter
82  
83 $Debug $MaxStringwidth $Trunctailwidth $Truncsuffix
84 $Objects $Foldwidth $Useqq $Quotekeys $Sortkeys
85 $Maxdepth $Maxrecurse $Deparse $Deepcopy);
86  
87 15 our %EXPORT_TAGS = (
88 null => [],
89 );
90  
91 sub _generate_sub($;$); # forward
92 sub u(_); # forward
93  
94 15 our ($COND_LB, $COND_RB, $COND_MULT, $LQ, $RQ);
95  
96 #---------------------------------------------------------------------------
97 15 my $sane_cW = $^W;
98 15 my $sane_cH = $^H;
99 15 our @save_stack;
100 9656 ▶sub _SaveAndResetPunct() {
Subroutine _SaveAndResetPunct: called CC=1 SCAR=0.0
101 # Save things which will later be restored
102 9656 push @save_stack, [ $@, $!+0, $^E+0, $., $,, $/, $\, $?, $^W ];
103 # Reset sane values
104 9656 $, = ""; # output field separator is null string
105 9656 $/ = "\n"; # input record separator is newline
106 9656 $\ = ""; # output record separator is null string
107 9656 $? = 0; # child process exit status
108 9656 $^W = $sane_cW; # our load-time warnings
109 #$^H = $sane_cH; # our load-time pragmas (strict etc.)
110 }
111 12070 ▶sub _RestorePunct_NoPop() {
Subroutine _RestorePunct_NoPop: called CC=1 SCAR=0.0
112 12070 ( $@, $!, $^E, $., $,, $/, $\, $?, $^W ) = @{ $save_stack[-1] };
113 }
114 9656 ▶sub _RestorePunct() {
Subroutine _RestorePunct: called CC=1 SCAR=0.0
115 9656 &_RestorePunct_NoPop;
116 9656 pop @save_stack;
117 }
118 #---------------------------------------------------------------------------
119  
120 15 our $AUTOLOAD_debug;
121  
122 39 ▶sub AUTOLOAD { # invoked on call to undefined *method*
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
123 39 our $AUTOLOAD;
124 39 _SaveAndResetPunct();
125 39 our $Debug;
126 39 { local $Debug = $AUTOLOAD_debug;
127 39 _generate_sub($AUTOLOAD);
128 }
129 39 _RestorePunct();
130 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
131 39 goto &$AUTOLOAD;
132 }
133 #sub DESTROY {} #unnecessary: No D::D::Interp objects are ever instantiated
134  
135 ############################################################################
136 # Internal debug-message utilities
137  
138 0 ▶sub oops(@) { @_=("\n".(caller)." oops:\n",@_,"\n"); goto &Carp::confess }
Subroutine oops: not called CC=1 SCAR=6.9
Pod undocumented
139 0 ▶sub btwN($@) { my $N=shift; local $_=join("",map{u} @_); s/\n\z//s; printf "%4d: %s\n",(caller($N))[2],$_; }
Subroutine btwN: not called CC=1 SCAR=6.9
Pod undocumented
140 0 ▶sub btw(@) { unshift @_,0; goto &btwN }
Subroutine btw: not called CC=1 SCAR=6.9
Pod undocumented
141  
142 0 ▶sub _chop_ateval($) { # remove "at (eval N) line..." from an exception message
Subroutine _chop_ateval: not called CC=1 SCAR=6.9
143 0 (local $_ = shift) =~ s/ at \(eval[^\)]*\) line \d+[^\n]*\n?\z//s;
144 0 $_
145 }
146 0 ▶sub _croak_or_confess(@) {
Subroutine _croak_or_confess: not called CC=2 SCAR=17.9
147 # Chain to croak, or to confess if there is an eval in the call stack
148 0 ▶ if (Carp::longmess("") =~ /\beval\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if (Carp::longmess("") =~ /\beval\b/u) 0 0 0
149 0 goto &Carp::confess;
150 }
151 0 goto &Carp::croak;
152 }
153  
154 0 ▶sub _tf($) { $_[0] ? "T" : "F" }
Subroutine _tf: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
155 0 ▶sub _showfalse(_) { $_[0] ? $_[0] : 0 }
Subroutine _showfalse: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
156 803 ▶sub _dbvisnew($) {
Subroutine _dbvisnew: called CC=1 SCAR=0.0
157 803 my $v = shift;
158 803 Data::Dumper->new([$v])->Terse(1)->Indent(0)->Quotekeys(0)
159 ->Sortkeys(1)->Useqq(1)
160 ###->Sortkeys(\&__sortkeys)->Pair("=>")
161 #->Useperl(1)
162 }
163 803 ▶sub _dbvis(_) {chomp(my $s=_dbvisnew(shift)->Useqq(1)->Dump); $s }
Subroutine _dbvis: called CC=1 SCAR=0.0
164 0 ▶sub _dbvis1(_){chomp(my $s=_dbvisnew(shift)->Useqq(1)->Maxdepth(1)->Dump); $s }
Subroutine _dbvis1: not called CC=1 SCAR=6.9
165 0 ▶sub _dbvis2(_){chomp(my $s=_dbvisnew(shift)->Useqq(1)->Maxdepth(2)->Dump); $s }
Subroutine _dbvis2: not called CC=1 SCAR=6.9
166 0 ▶sub _dbvisq(_){chomp(my $s=_dbvisnew(shift)->Useqq(0)->Dump); $s }
Subroutine _dbvisq: not called CC=1 SCAR=6.9
167 0 ▶sub _dbavis(@){ "(" . join(", ", map{_dbvis} @_) . ")" }
Subroutine _dbavis: not called CC=1 SCAR=6.9
168 0 ▶sub _dbavis2(@){ "(" . join(", ", map{_dbvis2} @_) . ")" }
Subroutine _dbavis2: not called CC=1 SCAR=6.9
169 0 ▶sub _dbrvis(_) { (ref($_[0]) ? addrvis(refaddr $_[0]) : "")._dbvis($_[0]) }
Subroutine _dbrvis: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
170 0 ▶sub _dbrvis2(_){ (ref($_[0]) ? addrvis(refaddr $_[0]) : "")._dbvis2($_[0]) }
Subroutine _dbrvis2: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
171 0 ▶sub _dbravis2(@){ "(" . join(", ", map{_dbrvis2} @_) . ")" }
Subroutine _dbravis2: not called CC=1 SCAR=6.9
172 0 ▶sub _dbshow(_) {
Subroutine _dbshow: not called CC=2 SCAR=17.9
173 0 my $v = shift;
174 0 ▶ blessed($v) ? "(".blessed($v).")".$v # stringify with (classname) prefix
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($v) ? : 0 0 0
175 : _dbvis($v) # something else
176 }
177 15 our $_dbmaxlen = 300;
178 0 ▶sub _dbrawstr(_) { ($LQ//"<<").(length($_[0])>$_dbmaxlen ? substr($_[0],0,$_dbmaxlen-3)."..." : $_[0]).(${RQ}//">>") }
Subroutine _dbrawstr: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] > $Data::Dumper::Interp::_dbmaxlen ? : 0 0 0
Condition0%0/4
$Data::Dumper::Interp::LQ // "<<"
l!l
00
$Data::Dumper::Interp::RQ // ">>"
l!l
00
MC/DC0%0/1
$Data::Dumper::Interp::LQ // "<<"
$Data::Dumper::Interp::LQ
MC/DC0%0/1
$Data::Dumper::Interp::RQ // ">>"
$Data::Dumper::Interp::RQ
Truth table0%0/2
A
A= $Data::Dumper::Interp::LQ
Aresult
11
00
Truth table0%0/2
A
A= $Data::Dumper::Interp::RQ
Aresult
11
00
179 0 ▶sub _dbstr($) {
Subroutine _dbstr: not called CC=2 SCAR=17.9
180 0 local $_ = shift;
181 0 ▶ return "undef" if !defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
182 0 s/\x{0a}/\N{U+2424}/sg; # a special NL glyph
183 0 s/ /\N{U+00B7}/sg; # space -> Middle Dot
184 0 s/[\x{00}-\x{1F}]/ chr( ord($&)+0x2400 ) /aseg;
185 0 $_
186 }
187 0 ▶sub _dbstrposn($$) {
Subroutine _dbstrposn: not called CC=1 SCAR=6.9
188 0 local $_ = shift;
189 0 my $posn = shift;
190 0 local $_dbmaxlen = max($_dbmaxlen+8, $posn+8);
191 0 my $visible = _dbstr($_); # simplified 'controlpics'
192 0 "posn=$posn shown at '(<<HERE)':"
193 . substr($visible, 0, $posn+1)."(<<HERE)".substr($visible,$posn+1)
194 }
195 ############################################################################
196  
197  
198 #################### Configuration Globals #################
199  
200 # Used by sub import() so must be declared first
201 15 our ($Debug, $MaxStringwidth, $Truncsuffix, $Trunctailwidth, $Objects,
202 $Refaddr, $Foldwidth, $Foldwidth1,
203 $Useqq, $Quotekeys, $Sortkeys,
204 $Maxdepth, $Maxrecurse, $Deparse, $Deepcopy);
205  
206 15 ▶sub _reset_defaults() {
Subroutine _reset_defaults: called CC=16 SCAR=32.4
207 15 ▶ $Debug = 0 unless defined $Debug;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Debug 15 0 15
208 15 ▶ $MaxStringwidth = 0 unless defined $MaxStringwidth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::MaxStringwidth 15 0 15
209 15 ▶ $Truncsuffix = "..." unless defined $Truncsuffix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Truncsuffix 15 0 15
210 15 ▶ $Trunctailwidth = 0 unless defined $Trunctailwidth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Trunctailwidth 15 0 15
211 15 ▶ $Objects = 1 unless defined $Objects;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Objects 15 0 15
212 15 ▶ $Refaddr = 0 unless defined $Refaddr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Refaddr 15 0 15
213 15 ▶ $Foldwidth = undef unless defined $Foldwidth; # undef auto-detects
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Foldwidth 15 0 15
214 15 ▶ $Foldwidth1 = undef unless defined $Foldwidth1; # override for 1st
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Foldwidth1 15 0 15
215  
216 # The following override Data::Dumper defaults
217 # Initial D::D values are captured once when we are first loaded.
218  
219 #$Useqq = "<unicode:controlpic>" unless defined $Useqq;
220 15 ▶ $Useqq = "unicode" unless defined $Useqq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Useqq 15 0 15
221 15 ▶ $Quotekeys = 0 unless defined $Quotekeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Quotekeys 15 0 15
222 15 ▶ $Sortkeys = \&__sortkeys unless defined $Sortkeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Sortkeys 15 0 15
223 15 ▶ $Maxdepth = $Data::Dumper::Maxdepth unless defined $Maxdepth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Maxdepth 15 0 15
224 15 ▶ $Maxrecurse = $Data::Dumper::Maxrecurse unless defined $Maxrecurse;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Maxrecurse 15 0 15
225 15 ▶ $Deparse = 0 unless defined $Deparse;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Deparse 15 0 15
226 15 ▶ $Deepcopy = 0 unless defined $Deepcopy;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Interp::Deepcopy 15 0 15
227 }
228 15 _reset_defaults(); # at startup
229  
230 # This user-callable function (or method) restores default defaults
231 # Mainly useful after calling visnew->set_defaults()
232 0 ▶sub reset_defaults() {
Subroutine reset_defaults: not called CC=1 SCAR=6.9
Pod documented
233 0 undef $Debug;
234 0 undef $MaxStringwidth;
235 0 undef $Truncsuffix;
236 0 undef $Trunctailwidth;
237 0 undef $Objects;
238 0 undef $Refaddr;
239 0 undef $Foldwidth; # undef auto-detects
240 0 undef $Foldwidth1; # override for 1st
241  
242 0 undef $Useqq;
243 0 undef $Quotekeys;
244 0 undef $Sortkeys;
245 0 undef $Maxdepth;
246 0 undef $Maxrecurse;
247 0 undef $Deparse;
248 0 undef $Deepcopy;
249 0 _reset_defaults();
250 }
251  
252 #################### Methods #################
253  
254 has dd => (
255 is => 'ro',
256 lazy => 1,
257 7656 ▶ default => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
258 7656 my $self = shift;
259 7656 Data::Dumper->new([],[])
260 ->Terse(1)
261 ->Indent(0)
262 ->Sparseseen(1)
263 ->Useqq($Useqq)
264 ->Quotekeys($Quotekeys)
265 ->Sortkeys($Sortkeys)
266 ->Maxdepth($Maxdepth)
267 ->Maxrecurse($Maxrecurse)
268 ->Deparse($Deparse)
269 ->Deepcopy($Deepcopy)
270 },
271 # This generates pass-through methods which call the dd object
272 15 handles => [qw/Values Useqq Quotekeys Trailingcomma Pad Varname Quotekeys
273 Maxdepth Maxrecurse Useperl Sortkeys Deparse Deepcopy
274 /],
275 );
276  
277 # Config values which have no counterpart in Data::Dumper
278 7657 ▶has Debug => (is=>'rw', default => sub{ $Debug });
Subroutine __ANON__: called CC=1 SCAR=0.0
279 7657 ▶has MaxStringwidth => (is=>'rw', default => sub{ $MaxStringwidth });
Subroutine __ANON__: called CC=1 SCAR=0.0
280 7657 ▶has Truncsuffix => (is=>'rw', default => sub{ $Truncsuffix });
Subroutine __ANON__: called CC=1 SCAR=0.0
281 7657 ▶has Trunctailwidth => (is=>'rw', default => sub{ $Trunctailwidth });
Subroutine __ANON__: called CC=1 SCAR=0.0
282 7657 ▶has Objects => (is=>'rw', default => sub{ $Objects });
Subroutine __ANON__: called CC=1 SCAR=0.0
283 7657 ▶has Refaddr => (is=>'rw', default => sub{ $Refaddr });
Subroutine __ANON__: called CC=1 SCAR=0.0
284 7657 ▶has Foldwidth => (is=>'rw', default => sub{
Subroutine __ANON__: called CC=2 SCAR=7.0
285 7657 ▶ $Foldwidth // do{
Condition66%2/3
$Data::Dumper::Interp::Foldwidth // do { &_set_default_Foldwidth(); $Data::Dumper::Interp::Foldwidth }
l!l&&r!l&&!r
7644130
MC/DC0%0/2
$Data::Dumper::Interp::Foldwidth // do { &_set_default_Foldwidth(); $Data::Dumper::Interp::Foldwidth }
$Data::Dumper::Interp::Foldwidth do { &_set_default_Foldwidth(); $Data::Dumper::Interp::Foldwidth }
Truth table66%2/3
A // B
A= $Data::Dumper::Interp::FoldwidthB= do { &_set_default_Foldwidth(); $Data::Dumper::Interp::Foldwidth }
ABresult
1X1
011
000
286 13 _set_default_Foldwidth();
287 13 $Foldwidth
288 }
289 15 });
290 7657 ▶has Foldwidth1 => (is=>'rw', default => sub{ $Foldwidth1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
291 15 has _Listform => (is=>'rw');
292 7657 ▶has _VisitState => (is=>'rw', default => sub{ {my_visit_depth => 0} });
Subroutine __ANON__: called CC=1 SCAR=0.0
293  
294 0 ▶sub _SetDefaults {
Subroutine _SetDefaults: not called CC=1 SCAR=6.9
295 0 my $self = shift;
296 0 $Debug = $self->Debug();
297 0 $MaxStringwidth = $self->MaxStringwidth();
298 0 $Truncsuffix = $self->Truncsuffix();
299 0 $Trunctailwidth = $self->Trunctailwidth();
300 0 $Objects = $self->Objects();
301 0 $Refaddr = $self->Refaddr();
302 0 $Foldwidth = $self->Foldwidth();
303 0 $Foldwidth1 = $self->Foldwidth1();
304 0 $Quotekeys = $self->Quotekeys();
305 # These from from the Data::Dumper object, via wrappers
306 0 $Useqq = $self->Useqq();
307 0 $Quotekeys = $self->Quotekeys();
308 0 $Maxdepth = $self->Maxdepth();
309 0 $Maxrecurse = $self->Maxrecurse();
310 0 $Sortkeys = $self->Sortkeys();
311 0 $Deparse = $self->Deparse();
312 0 $Deepcopy = $self->Deepcopy();
313 0 return $self
314 }
315  
316 # Make "setters" return the outer object $self
317 around [qw/Values Useqq Quotekeys Trailingcomma Pad Varname Quotekeys
318 Maxdepth Maxrecurse Useperl Sortkeys Deparse Deepcopy
319  
320 Debug MaxStringwidth Truncsuffix Trunctailwidth Objects Refaddr
321 Foldwidth Foldwidth1 _Listform
322 108897 ▶ /] => sub{
Subroutine __ANON__: called CC=2 SCAR=6.9
323 108897 my $orig = shift;
324 108897 my $self = shift;
325 #Carp::cluck("##around (@_)\n");
326 108897 ▶ if (@_ > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 0) 54009 54888 108897
327 54009 $self->$orig(@_);
328 54009 return $self;
329 }
330 54888 $self->$orig
331 15 };
332  
333 ############### Utility Functions #################
334  
335 #---------------------------------------------------------------------------
336 # Display an address as <decimal:hex> showing only the last few digits.
337 # The number of digits shown increases when collisions occur.
338 # The arg can be a numeric address or a ref from which the addr is taken.
339 # If a ref the result is REFTYPEorOBJTYPE<dec:hex> otherwise just <dec:hex>
340 15 ▶use constant _ADDRVIS_SHARED_MARK => "S*";
Subroutine BEGIN: called CC=1 SCAR=0.0
341 15 our $addrvis_ndigits = 3;
342 15 our $addrvis_seen = {}; # full (decimal) address => undef
343 15 our $addrvis_dec_abbrs = {}; # abbreviated decimal digits => undef
344 170581 ▶sub _abbr_hex($) {
Subroutine _abbr_hex: called CC=2 SCAR=7.0
345 # Preserve a _ADDRVIS_SHARED_MARK prefix, if present
346 170581 local $_ = shift;
347 170581 ▶ /^((?:\Q${\_ADDRVIS_SHARED_MARK}\E)?\K)(.*)/ or die;
Branch: 1 branch
BranchTrueFalseTotal
/^((?:\Q${\"S*";}\E)?\K)(.*)/u or die 170581 0 170581
348 170581 $1.substr(sprintf("%0*x", $addrvis_ndigits, $2), -$addrvis_ndigits)
349 }
350 176962 ▶sub _abbr_dec($) {
Subroutine _abbr_dec: called CC=2 SCAR=7.0
351 # Strip off _ADDRVIS_SHARED_MARK prefix, if present
352 176962 local $_ = shift;
353 176962 ▶ /^((?:\Q${\_ADDRVIS_SHARED_MARK}\E)?\K)(.*)/ or die;
Branch: 1 branch
BranchTrueFalseTotal
/^((?:\Q${\"S*";}\E)?\K)(.*)/u or die 176962 0 176962
354 176962 substr(sprintf("%0*d", $addrvis_ndigits, $2), -$addrvis_ndigits)
355 }
356 170581 ▶sub _refaddrdechex($) { # Returns just "<hex:dec>" (possibly marked as shared)
Subroutine _refaddrdechex: called CC=8 SCAR=21.7
357 170581 ▶ my $arg = shift // return("undef");
Condition50%1/2
shift() // (return "undef")
l!l
1705810
MC/DC0%0/1
shift() // (return "undef")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
358 170581 my $refstr = ref($arg);
359 170581 my $addr;
360 170581 ▶ if ($refstr ne "") {
Branch: 2 branches
BranchTrueFalseTotal
if ($refstr ne '') { } 90 170491 170581
elsif (&looks_like_number($arg)) { } 170491 0 170491
361 90 ▶ if ($INC{"threads/shared.pm"}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{'threads/shared.pm'} and defined(my $id = threads::shared::is_shared($arg))) { } 0 90 90
Condition33%1/3
$INC{"threads/shared.pm"} and defined(my $id = threads::shared::is_shared($arg))
!ll&&!rl&&r
9000
MC/DC0%0/2
$INC{"threads/shared.pm"} and defined(my $id = threads::shared::is_shared($arg))
$INC{"threads/shared.pm"} defined(my $id = threads::shared::is_shared($arg))
Truth table33%1/3
A and B
A= $INC{"threads/shared.pm"}B= defined(my $id = threads::shared::is_shared($arg))
ABresult
0X0
100
111
362 && defined(my $id = threads::shared::is_shared($arg))) {
363 0 $addr = _ADDRVIS_SHARED_MARK.$id;
364 } else {
365 90 $addr = refaddr($arg)
366 }
367 }
368 170491 elsif (looks_like_number($arg)) { $addr = $arg }
369 else {
370 #Carp::cluck("addrvis arg '$arg' is neither a ref or a number\n");
371 0 carp("addrvis arg '$arg' is neither a ref or a number\n");
372 0 return ""
373 }
374  
375 170581 ▶ if (! exists $addrvis_seen->{$addr}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Data::Dumper::Interp::addrvis_seen->{$addr}) 2176 168405 170581
376 2176 my $dec_abbr = _abbr_dec($addr);
377 2176 ▶ while (exists $addrvis_dec_abbrs->{$dec_abbr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Data::Dumper::Interp::addrvis_dec_abbrs->{$dec_abbr}) 3 2176 2179
378 3 ++$addrvis_ndigits;
379 3 %$addrvis_dec_abbrs = map{ (_abbr_dec($_) => undef) } keys %$addrvis_seen;
380 3 $dec_abbr = _abbr_dec($addr);
381 }
382 2176 $addrvis_dec_abbrs->{$dec_abbr} = undef;
383 2176 $addrvis_seen->{$addr} = undef;
384 }
385 170581 '<'._abbr_dec($addr).':'._abbr_hex($addr).'>'
386 }
387 170539 ▶sub addrvis(_) {
Subroutine addrvis: called CC=2 SCAR=6.9
Pod documented
388 170539 ▶ my $arg = shift // return("undef");
Condition100%2/2
shift() // (return "undef")
l!l
1705372
MC/DC100%1/1
shift() // (return "undef")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
389 170537 my $r = _refaddrdechex($arg); # hex:dec with possible shared-mem indicator
390 170537 ref($arg).$r
391 }
392 2 ▶sub addrvisl(_) {
Subroutine addrvisl: called CC=3 SCAR=11.1
Pod documented
393 # Return bare "hex:dec" or "Typename hex:dec"
394 2 ▶ &addrvis =~ s/^([^\<]*)\<(.*)\>$/ $1 ? "$1 $2" : $2 /er or oops
Branch: 2 branches
BranchTrueFalseTotal
&addrvis =~ s/^([^\<]*)\<(.*)\>$/$1 ? "$1 $2" : $2;/eru or &oops() 2 0 2
$1 ? : 1 1 2
395 }
396 1 ▶sub addrvis_digits(;$) {
Subroutine addrvis_digits: called CC=3 SCAR=11.6
Pod undocumented
397 1 ▶ return $addrvis_ndigits if ! defined $_[0]; # "get" request
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 1 1
398 1 ▶ if ($_[0] <= $addrvis_ndigits) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] <= $Data::Dumper::Interp::addrvis_ndigits) 0 1 1
399 0 return $addrvis_ndigits; # can not decrease
400 }
401 1 $addrvis_ndigits = $_[0];
402 1 %$addrvis_dec_abbrs = map{ (_abbr_dec($_) => undef) } keys %$addrvis_seen;
403 1 $addrvis_ndigits;
404 }
405 2 ▶sub addrvis_forget() {
Subroutine addrvis_forget: called CC=1 SCAR=0.0
Pod undocumented
406 2 $addrvis_seen = {};
407 2 $addrvis_dec_abbrs = {};
408 2 $addrvis_ndigits = 3;
409 }
410  
411 =for Pod::Coverage addrvis_digits addrvis_forget
412  
413 =cut
414  
415 875 ▶sub u(_) { $_[0] // "undef" }
Subroutine u: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0] // "undef"
l!l
622253
MC/DC100%1/1
$_[0] // "undef"
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
416 sub quotekey(_); # forward. Implemented after regex declarations.
417  
418 43 ▶sub __stringify_if_overloaded($) {
Subroutine __stringify_if_overloaded: called CC=3 SCAR=15.4
419 43 ▶ if (defined(my $class = blessed($_[0]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $class = builtin::blessed($_[0]))) 0 43 43
420 0 ▶ return "$_[0]" if overload::Method($class,'""');
Branch: 1 branch
BranchTrueFalseTotal
if overload::Method($class, "\"\"") 0 0 0
421 }
422 43 $_[0]
423 }
424  
425 15 ▶use constant _NIX_SHELL_UNSAFE_REGEX => qr/[^-=\w_:\.,\/]/a;
Subroutine BEGIN: called CC=1 SCAR=0.0
426 20 ▶sub __nix_forceqsh(_) {
Subroutine __nix_forceqsh: called CC=4 SCAR=13.9
427 20 local $_ = shift;
428 20 ▶ return "undef" if !defined; # undef without quotes
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 1 19 20
429 19 ▶ $_ = vis($_) if ref;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 19 19
430 # Prefer "double quoted" if no shell escapes would be needed.
431 19 ▶ if (/["\$`!\\\x{00}-\x{1F}\x{7F}]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/["\$`!\\\x{00}-\x{1F}\x{7F}]/u) { } 8 11 19
432 # Unlike Perl, /bin/sh does not recognize any backslash escapes in '...'
433 8 s/'/'\\''/g; # foo'bar => foo'\''bar
434 8 return "'${_}'";
435 } else {
436 11 return "\"${_}\"";
437 }
438 }
439  
440 15 ▶use constant _WIN_CMD_UNSAFE_REGEX => qr/[^-=\w_:\.,\\]/a;
Subroutine BEGIN: called CC=1 SCAR=0.0
441 4 ▶sub __win_forceqsh(_) {
Subroutine __win_forceqsh: called CC=3 SCAR=11.2
442 4 local $_ = shift;
443 4 ▶ return "undef" if !defined; # undef without quotes
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 4 4
444 4 ▶ $_ = vis($_) if ref;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 4 4
445 # This was intended to quote as would be needed to pass the word as a
446 # parameter to a command typed to cmd.com in Windows.
447 # However parameter parameter parsing is implemented within each command
448 # and there is no universal ruleset. For example Strawberry perl
449 # appears to split parameters on white space only, whereas (as I understand)
450 # Windows commands, at least built-in ones, split words on any of
451 # space tab , ; or = and all those must be protected, see
452 # https://ss64.com/nt/syntax-esc.html
453 #
454 # For the moment at least, qsh "quotes" words so they come through when
455 # passed as parameters to Strawberry perl when, in cmd.com, you type
456 #
457 # perl \path\to\script.pl PARAM1 PARAM2 ...
458 #
459 # Here's what I *think* is true:
460 # * "double quotes" escape word delimiters (space tab , ; =)
461 # * ^ escapes : & \ < > ^ | when NOT in "quotes"
462 # (but we always put them in "quotes")
463 # * ^<newline> (outside of "quotes") is ignored
464 # (it appears to be impossible to directly include a newline in a cmd
465 # parameter. It requires a helper program or interpolating
466 # a %variable%, see https://superuser.com/a/1519790)
467 # * \ outside "quotes" means \
468 # \ inside "quotes" is literal _unless_ followed by "
469 # Backslash usually need not be protected, except:
470 # * \ quotes " whether inside "quotes" or bare (!)
471 # * \ quotes \ ONLY(?) if immediately followed by " or \"
472 # otherwise \\ means two backslashes.
473 #FIXME TODO UNFINISHED
474 #TODO - rewrite using Win32::ShellQuote ???
475 4 s/\\(?=")/\\\\/g;
476 4 s/"/\\"/g;
477 4 s/\\\z/\\\\/g; # because the closing " will follow
478 4 return "\"${_}\""; # 6/7/23: UNtested
479 }
480  
481 34 ▶sub qsh(_) {
Subroutine qsh: called CC=12 SCAR=27.2
Pod documented
482 34 local $_ = __stringify_if_overloaded(shift());
483 34 ▶ $^O eq "MSWin32" ?
Branch: 3 branches
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 5 29 34
defined $_ && !ref($_) && $_ ne '' && $_ ne 'undef' && !($_ =~ /[^-=\w_:\.,\\]/u) ? : 1 4 5
defined $_ && !ref($_) && $_ ne '' && $_ ne 'undef' && !($_ =~ m[[^-=\w_:\.,/]]u) ? : 9 20 29
Condition62%15/24
defined $_ and not ref $_ and $_ ne "" and $_ ne "undef" and not $_ =~ /[^-=\w_:\.,\\]/u
!ll&&!rl&&r
041
defined $_ and not ref $_ and $_ ne "" and $_ ne "undef"
!ll&&!rl&&r
005
defined $_ and not ref $_ and $_ ne ""
!ll&&!rl&&r
005
defined $_ and not ref $_
!ll&&!rl&&r
005
defined $_ and not ref $_ and $_ ne "" and $_ ne "undef" and not $_ =~ m[[^-=\w_:\.,/]]u
!ll&&!rl&&r
2189
defined $_ and not ref $_ and $_ ne "" and $_ ne "undef"
!ll&&!rl&&r
1127
defined $_ and not ref $_ and $_ ne ""
!ll&&!rl&&r
1028
defined $_ and not ref $_
!ll&&!rl&&r
1028
MC/DC20%1/5
defined $_ and not ref $_ and $_ ne "" and $_ ne "undef" and not $_ =~ /[^-=\w_:\.,\\]/u
defined $_ not ref $_ $_ ne "" $_ ne "undef" not $_ =~ /[^-=\w_:\.,\\]/u
MC/DC60%3/5
defined $_ and not ref $_ and $_ ne "" and $_ ne "undef" and not $_ =~ m[[^-=\w_:\.,/]]u
defined $_ not ref $_ $_ ne "" $_ ne "undef" not $_ =~ m[[^-=\w_:\.,/]]u
Truth table33%2/6
A and not(B) and C and D and not(E)
A= defined $_B= not ref $_C= $_ ne ""D= $_ ne "undef"E= not $_ =~ /[^-=\w_:\.,\\]/u
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
Truth table66%4/6
A and not(B) and C and D and not(E)
A= defined $_B= not ref $_C= $_ ne ""D= $_ ne "undef"E= not $_ =~ m[[^-=\w_:\.,/]]u
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
484 (defined && !ref && $_ ne "" && $_ ne "undef" && $_ !~ _WIN_CMD_UNSAFE_REGEX ? $_ : __win_forceqsh)
485 :
486 (defined && !ref && $_ ne "" && $_ ne "undef" && $_ !~ _NIX_SHELL_UNSAFE_REGEX ? $_ : __nix_forceqsh)
487 }
488 9 ▶sub qshpath(_) { # like qsh but does not quote initial ~ or ~username
Subroutine qshpath: called CC=5 SCAR=17.5
Pod documented
489 9 local $_ = __stringify_if_overloaded(shift());
490 9 ▶ return qsh($_) if !defined or ref;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or ref $_ 0 9 9
Condition33%1/3
not defined $_ or ref $_
l!l&&r!l&&!r
009
MC/DC0%0/2
not defined $_ or ref $_
not defined $_ ref $_
Truth table33%1/3
not(A) or B
A= not defined $_B= ref $_
ABresult
1X1
011
000
491 9 ▶ my ($tilde_prefix, $rest) = /^( (?:\~[^\/\\]*[\/\\]?+)? )(.*)/xs or die;
Branch: 1 branch
BranchTrueFalseTotal
() = m(^( (?:\~[^/\\]*[/\\]?+)? )(.*))sux or die 9 0 9
492 9 ▶ $rest eq "" ? $tilde_prefix : $tilde_prefix.qsh($rest)
Branch: 1 branch
BranchTrueFalseTotal
$rest eq '' ? : 1 8 9
493 }
494  
495 # Should this have been called 'aqsh' ?
496 3 ▶sub qshlist(@) { join " ", map{qsh} @_ }
Subroutine qshlist: called CC=1 SCAR=0.0
Pod documented
497  
498 ########### Subs callable as either a Function or Method #############
499  
500 9607 ▶sub __getself { # Return $self if passed or else create a new object
Subroutine __getself: called CC=4 SCAR=13.9
501 9607 local $@;
502 9607 my $blessed = eval{ blessed($_[0]) }; # In case a tie handler throws
503 9607 ▶ croak _chop_ateval($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 9607 9607
504 9607 ▶ ($blessed && $_[0]->isa(__PACKAGE__)) ? shift(@_) : __PACKAGE__->new()
Branch: 1 branch
BranchTrueFalseTotal
$blessed && $_[0]->isa(__PACKAGE__) ? : 7669 1938 9607
Condition100%3/3
$blessed and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
1846927669
MC/DC100%2/2
$blessed and $_[0]->isa(__PACKAGE__)
$blessed $_[0]->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= $blessedB= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
505 }
506 7683 ▶sub __getself_s { &__getself->Values([$_[0]]) }
Subroutine __getself_s: called CC=1 SCAR=0.0
507 323 ▶sub __getself_a { &__getself->Values([[@_]]) }
Subroutine __getself_a: called CC=1 SCAR=0.0
508 141 ▶sub __getself_h {
Subroutine __getself_h: called CC=2 SCAR=7.1
509 141 my $obj = &__getself;
510 141 ▶ ($#_ % 2)==1 or confess "Uneven arg count for key => val pairs";
Branch: 1 branch
BranchTrueFalseTotal
$#_ % 2 == 1 or confess("Uneven arg count for key => val pairs") 141 0 141
511 141 $obj->Values([{@_}])
512 }
513  
514 2776 ▶sub _EnabUseqqFeature {
Subroutine _EnabUseqqFeature: called CC=5 SCAR=20.9
515 # Append <feature> to Useqq ONLY if Useqq has not been changed from the
516 # default (indicated by "<pointy brackets>" -- see setting of $Useqq = ... )
517 # AND the default enables some extended features.
518 2776 my ($self, $feature) = @_;
519 2776 my $curr = $self->Useqq;
520 2776 ▶ return $self if length($curr//"") <= 1
Branch: 1 branch
BranchTrueFalseTotal
if length($curr // "") <= 1 or substr($curr, 0, 1) ne "<" or substr($curr, -1, 1) ne ">" 2776 0 2776
Condition37%3/8
length($curr // "") <= 1 or substr($curr, 0, 1) ne "<" or substr($curr, -1, 1) ne ">"
l!l&&r!l&&!r
277600
length($curr // "") <= 1 or substr($curr, 0, 1) ne "<"
l!l&&r!l&&!r
027760
$curr // ""
l!l
27760
MC/DC0%0/3
length($curr // "") <= 1 or substr($curr, 0, 1) ne "<" or substr($curr, -1, 1) ne ">"
$curr substr($curr, 0, 1) ne "<" substr($curr, -1, 1) ne ">"
Truth table0%0/4
A or B or C
A= $currB= substr($curr, 0, 1) ne "<"C= substr($curr, -1, 1) ne ">"
ABCresult
1XX1
01X1
0011
0000
521 || substr($curr,0,1) ne "<"
522 || substr($curr,-1,1) ne ">";
523 #btw '###ENABLE CHANGING Useqq; curr=', _dbvis($curr), " \$Useqq=$Useqq";
524 0 $self->Useqq($curr.$feature)
525 }
526  
527 10702 ▶sub _utfoutput() {
Subroutine _utfoutput: called CC=1 SCAR=0.0
528 # Delay testing STDOUT until the first actual call which needs to know
529 10702 state $utf_output = grep /utf/i, PerlIO::get_layers(*STDOUT, output=>1);
530 }
531  
532 969 ▶sub _generate_sub($;$) {
Subroutine _generate_sub: called CC=36 SCAR=38.1
533 969 my ($arg, $proto_only) = @_;
534 969 (my $methname = $arg) =~ s/.*:://;
535 0 ▶ my sub error($) {
Subroutine error: not called CC=1 SCAR=6.9
536 0 _croak_or_confess "Invalid sub/method name '$methname' (@_)\n"
537 }
538  
539 # Method names are ivis, dvis, vis, avis, or hvis with prepended
540 # or appended modifier letters or digits (in any order), with
541 # optional underscore separators.
542 969 local $_ = $methname;
543  
544 969 s/alvis/avisl/; # backwards compat.
545 969 s/hlvis/hvisl/; # backwards compat.
546  
547 # Discontinued because NOW visl means something else.
548 #s/^[^diha]*\K(?:lvis|visl)/avisl/; # 'visl' same as 'avisl' for bw compat.
549  
550 969 ▶ s/([ahid]?vis|set_defaults)// or error "can not infer the basic function";
Branch: 1 branch
BranchTrueFalseTotal
s/([ahid]?vis|set_defaults)//u or error("can not infer the basic function") 969 0 969
551 969 my $basename = $1; # avis, hvis, ivis, dvis, or vis
552 969 ▶ my $N = s/(\d+)// ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
s/(\d+)//u ? : 449 520 969
553 969 my %mod = map{$_ => 1} split //, $_;
554 969 delete $mod{"_"}; # ignore underscores in names
555  
556 969 ▶ if (($Debug//0) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (($Data::Dumper::Interp::Debug // 0) > 1) 0 969 969
Condition100%2/2
$Data::Dumper::Interp::Debug // 0
l!l
93039
MC/DC100%1/1
$Data::Dumper::Interp::Debug // 0
$Data::Dumper::Interp::Debug
Truth table100%2/2
A
A= $Data::Dumper::Interp::Debug
Aresult
11
00
557 0 warn "## (D=$Debug) methname=$methname base=$basename \$_=$_\n";
558 }
559 ## if ($basename =~ /^[id]/) {
560 ## error "'$1' is inapplicable to $basename" if /([ahl])/;
561 ## }
562 ## error "'$1' mis-placed: Only allowed as '${1}vis'" if /([ahi])/;
563  
564  
565 # All these subs can be called as either or methods or functions.
566 # If the first argument is an object it is used, otherwise a new object
567 # is created; then option-setting methods are called as implied by
568 # the specific sub name.
569 #
570 # Finally the _Do() method is invoked for primatives like 'vis'.
571 #
572 # For ivis/dvis, control jumps to _Interpolate() which uses the object
573 # repeatedly when calling primatives to interpolate values into the string.
574  
575 969 my $listform = '';
576 969 ▶ my $signature = $basename =~ /^[ah]/ ? '@' : '_'; # avis(@) ivis(_) vis(_)
Branch: 1 branch
BranchTrueFalseTotal
$basename =~ /^[ah]/u ? : 476 493 969
577 969 my $code = "sub $methname($signature)";
578 969 ▶ if ($basename eq "vis") {
Branch: 6 branches
BranchTrueFalseTotal
if ($basename eq 'vis') { } 183 786 969
elsif ($basename eq 'avis') { } 239 547 786
elsif ($basename eq 'hvis') { } 237 310 547
elsif ($basename eq 'set_defaults') { } 0 310 310
elsif ($basename eq 'ivis') { } 155 155 310
elsif ($basename eq 'dvis') { } 155 0 155
579 183 ▶ my $listform = delete($mod{l}) ? 'l' : '';
Branch: 1 branch
BranchTrueFalseTotal
delete $mod{'l'} ? : 2 181 183
580 183 $code .= " { &__getself_s->_Listform('${listform}')";
581 }
582 elsif ($basename eq "avis") {
583 239 ▶ my $listform = delete($mod{l}) ? 'l' : 'a';
Branch: 1 branch
BranchTrueFalseTotal
delete $mod{'l'} ? : 100 139 239
584 239 $code .= " { &__getself_a->_Listform('${listform}')";
585 }
586 elsif ($basename eq "hvis") {
587 237 ▶ my $listform = delete($mod{l}) ? 'l' : 'h';
Branch: 1 branch
BranchTrueFalseTotal
delete $mod{'l'} ? : 98 139 237
588 237 $code .= " { &__getself_h->_Listform('${listform}')";
589 }
590 elsif ($basename eq "set_defaults") {
591 0 $code .= " { &__getself" ;
592 }
593 elsif ($basename eq "ivis") {
594 155 $code .= " { \@_ = ( &__getself" ;
595 }
596 elsif ($basename eq "dvis") {
597 155 $code .= " { \@_ = ( &__getself->_EnabUseqqFeature(_utfoutput() ? ':showspaces:condense' : ':condense')" ;
598 #$code .= " { \@_ = ( &__getself->_EnabUseqqFeature(':showspaces')" ;
599 }
600 0 else { oops "basename=",u($basename) }
601  
602 969 my $useqq = "";
603 969 ▶ $useqq .= ":unicode:controlpics" if delete $mod{c};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"c"} 0 969 969
604 969 ▶ $useqq .= ":condense" if delete $mod{C};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"C"} 0 969 969
605 969 ▶ $code .= '->Debug(2)' if delete $mod{D};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"D"} 0 969 969
606 969 ▶ $useqq .= ":hex" if delete $mod{h};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"h"} 0 969 969
607 969 ▶ $code .= '->Objects(0)' if delete $mod{o}; # show internals
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"o"} 387 582 969
608 969 ▶ $code .= '->Objects({overloads => "transparent"})' if delete $mod{O}; # hide overloaded objects, not even showing classname
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"O"} 28 941 969
609 969 ▶ $useqq .= ":octets" if delete $mod{B};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"B"} 0 969 969
610 969 ▶ $code .= '->Refaddr(1)' if delete $mod{r};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"r"} 419 550 969
611 969 ▶ $useqq .= ":underscores" if delete $mod{u};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"u"} 0 969 969
612  
613 969 ▶ $code .= "->Useqq(\$Useqq.'${useqq}')" if $useqq ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $useqq ne "" 0 969 969
614  
615 969 ▶ $code .= "->_EnabUseqqFeature(_utfoutput() ? ':showspaces:condense' : ':condense')" if delete($mod{d}) or $basename eq "dvis";
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"d"} or $basename eq "dvis" 155 814 969
Condition66%2/3
delete $mod{"d"} or $basename eq "dvis"
l!l&&r!l&&!r
0155814
MC/DC50%1/2
delete $mod{"d"} or $basename eq "dvis"
delete $mod{"d"} $basename eq "dvis"
Truth table66%2/3
A or B
A= delete $mod{"d"}B= $basename eq "dvis"
ABresult
1X1
011
000
616  
617 969 ▶ $code .= "->Useqq(0)" if delete $mod{q};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mod{"q"} 411 558 969
618  
619 969 ▶ $code .= "->Maxdepth($N)" if defined($N);
Branch: 1 branch
BranchTrueFalseTotal
if defined $N 449 520 969
620  
621 969 ▶ if ($basename =~ /^([id])vis/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($basename =~ /^([id])vis/u) { } 310 659 969
elsif ($basename eq 'set_defaults') { } 0 659 659
622 310 $code .= ", shift, '$1' ); goto &_Interpolate }";
623 }
624 elsif ($basename eq 'set_defaults') {
625 0 $code .= "->_SetDefaults }";
626 } else {
627 659 $code .= "->_Do }";
628 }
629  
630 0 for (keys %mod) { error "Unknown or inappropriate modifier '$_'" }
631  
632 969 ▶ if ($proto_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto_only) 930 39 969
633 930 ▶ $code =~ s/ *\{.*/;/ or oops;
Branch: 1 branch
BranchTrueFalseTotal
$code =~ s/ *\{.*/;/u or &oops() 930 0 930
634 }
635 # To see the generated code
636 # use Data::Dumper::Interp qw/:debug :DEFAULT/; # or :all
637 969 ▶ if ($Debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Data::Dumper::Interp::Debug) 0 969 969
638 0 warn "# generated: $code\n";
639 }
640 969 ▶ eval "$code"; oops "code=$code\n\$@=$@" if $@;
Subroutine vis: called CC=1 SCAR=0.1
Subroutine ivis: called CC=1 SCAR=0.1
Subroutine dvis: called CC=3 SCAR=11.4
Subroutine rivisq42: called CC=1 SCAR=0.1
Subroutine avis: called CC=1 SCAR=0.1
Subroutine avisl: called CC=1 SCAR=0.1
Subroutine avislq: called CC=1 SCAR=0.1
Pod documented
Pod documented
Pod undocumented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 5 branches
BranchTrueFalseTotal
if $@ 0 969 969
&_utfoutput() ? : 1348 0 1348
&_utfoutput() ? : 1348 0 1348
&_utfoutput() ? : 40 0 40
&_utfoutput() ? : 40 0 40
641 }#_generate_sub
642  
643  
644 981 ▶sub visnew() { __PACKAGE__->new() } # shorthand
Subroutine visnew: called CC=1 SCAR=0.0
Pod documented
645  
646 # $Carp::RefArgFormatter may be set to this to format traceback args
647 # The optional options are for use when currying, e.g.
648 # $Carp::RefArgFormatter = sub($) { Data::Dumper::Interp::CarpArgFormatter($_[0], Maxdepth=9, ...) }
649 45 ▶sub RefArgFormatter {
Subroutine RefArgFormatter: called CC=4 SCAR=13.9
Pod documented
650 45 local $Carp::RefArgFormatter = undef; # prevent recursion
651 15 my ($item, %opts) = @_;
652 13 ▶ $opts{Maxdepth} //= 3;
Condition100%2/2
$opts{"Maxdepth"} //= 3
l!l
49
MC/DC100%1/1
$opts{"Maxdepth"} //= 3
$opts{"Maxdepth"}
Truth table100%2/2
A
A= $opts{"Maxdepth"}
Aresult
11
00
653 13 ▶ $opts{MaxStringwidth} //= 1000;
Condition50%1/2
$opts{"MaxStringwidth"} //= 1000
l!l
013
MC/DC0%0/1
$opts{"MaxStringwidth"} //= 1000
$opts{"MaxStringwidth"}
Truth table50%1/2
A
A= $opts{"MaxStringwidth"}
Aresult
11
00
654 # Use whatever global defaults the user may have set...
655 #$opts{Refaddr} //= 1;
656 #$opts{Objects} //= {objects => 1, overloads => "tagged"};
657 13 my $obj = Data::Dumper::Interp::visnew;
658 13 for my $optname (keys %opts) {
659 27 $obj->$optname($opts{$optname});
660 }
661 13 return $obj->vis($item)
662 }
663  
664  
665 ############# only internals follow ############
666  
667 15 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=18.4
668 15 ▶ if (! Data::Dumper->can("Maxrecurse")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not "Data::Dumper"->can("Maxrecurse")) 0 15 15
669 # Supply if missing in older Data::Dumper
670 0 eval q(sub Data::Dumper::Maxrecurse {
671 my($s, $v) = @_;
672 @_ == 2 ? (($s->{Maxrecurse} = $v), return $s)
673 : $s->{Maxrecurse}//0;
674 });
675 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
676 }
677 }
678  
679 15 ▶sub _get_terminal_width() { # returns undef if unknowable
Subroutine _get_terminal_width: called CC=9 SCAR=24.6
680 13 ▶ if (u($ENV{COLUMNS}) =~ /^[1-9]\d*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (&u($ENV{'COLUMNS'}) =~ /^[1-9]\d*$/u) { } 2 11 13
681 2 return $ENV{COLUMNS}; # overrides actual terminal width
682 } else {
683 11 local *_; # Try to avoid clobbering special filehandle "_"
684 # This does not actualy work; https://github.com/Perl/perl5/issues/19142
685  
686 my $fh =
687 -t STDOUT ? *STDOUT :
688 -t STDERR ? *STDERR :
689 # under Windows the filehandle must be an *output* handle
690 11 ▶ do{my $fh; for("/dev/tty",'CONOUT$') { last if open $fh, $_ } $fh}
Branch: 3 branches
BranchTrueFalseTotal
-t STDOUT ? : 0 11 11
-t STDERR ? : 0 11 11
if open $fh, $_ 0 22 22
Condition16%1/6
do { my $fh; foreach $_ ("/dev/tty", "CONOUT\$") { last if open $fh, $_; } ; $fh } or -t STDIN and *STDIN
l!l&&r!l&&!r
1100
-t STDIN and *STDIN
!ll&&!rl&&r
000
MC/DC0%0/3
do { my $fh; foreach $_ ("/dev/tty", "CONOUT\$") { last if open $fh, $_; } ; $fh } or -t STDIN and *STDIN
do { my $fh; foreach $_ ("/dev/tty", "CONOUT\$") { last if open $fh, $_; } ; $fh } -t STDIN *STDIN
Truth table25%1/4
A or B and C
A= do { my $fh; foreach $_ ("/dev/tty", "CONOUT\$") { last if open $fh, $_; } ; $fh }B= -t STDINC= *STDIN
ABCresult
1XX1
0111
00X0
0100
691 || (-t STDIN && *STDIN)
692 ;
693 11 my ($width, $height);
694 11 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 11 0 11
695 11 ($width, $height) = Term::Size::chars($fh);
696  
697 # # Some platforms (bsd?) carp if the terminal size can not be determined.
698 # # We don't want to see any such warnings. Also there might be a
699 # # __WARN__ trap which we don't want to trigger
700 # #
701 # # Sigh. It never ends! On some platforms (different libc?)
702 # # "stty" directly prints "stdin is not a tty" which we can not trap.
703 # # Probably this is a bug in Term::Readkey where it should redirect
704 # # such messages to /dev/null. So we have to do it here.
705 # require Capture::Tiny;
706 # () = Capture::Tiny::capture_merged(sub{
707 # delete local $SIG{__WARN__};
708 # delete local $SIG{__DIE__};
709 # ($width, $height) = eval{ Term::ReadKey::GetTerminalSize($fh) };
710 # });
711 }
712 11 return $width; # possibly undef (sometimes seems to be zero ?!?)
713 }
714 }
715  
716 13 ▶sub _set_default_Foldwidth() {
Subroutine _set_default_Foldwidth: called CC=2 SCAR=6.9
717 13 _SaveAndResetPunct();
718 13 ▶ $Foldwidth = _get_terminal_width || 80;
Condition100%2/2
&_get_terminal_width() || 80
l!l
211
MC/DC100%1/1
&_get_terminal_width() || 80
&_get_terminal_width()
Truth table100%2/2
A
A= &_get_terminal_width()
Aresult
11
00
719 13 _RestorePunct();
720 13 undef $Foldwidth1;
721 }
722  
723 15 ▶use constant _UNIQUE => substr(refaddr \&oops,-5);
Subroutine BEGIN: called CC=1 SCAR=0.0
724 15 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
725 15 _MAGIC_NOQUOTES_PFX => "|NQMagic${\_UNIQUE}|",
726 15 _MAGIC_KEEPQUOTES_PFX => "|KQMagic${\_UNIQUE}|",
727 15 _MAGIC_REFPFX => "|RPMagic${\_UNIQUE}|",
728 15 _MAGIC_ELIDE_NEXT => "|ENMagic${\_UNIQUE}|",
729 15 };
730  
731 #---------------------------------------------------------------------------
732  
733 # We may be called recursively via $Carp::RefArgFormatter !
734 # So can't use globals which might change.
735  
736 8147 ▶sub _Do {
Subroutine _Do: called CC=29 SCAR=38.4
737 8147 ▶ oops unless @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 8147 8147
738 8147 my $self = $_[0];
739  
740 8147 local $_;
741 8147 &_SaveAndResetPunct;
742  
743 8147 local $Carp::RefArgFormatter = undef; # prevent recursion
744  
745 my ($maxstringwidth, $truncsuffix, $trunctailwidth, $objects, $opt_refaddr, $listform, $debug)
746 8147 = @$self{qw/MaxStringwidth Truncsuffix Trunctailwidth Objects Refaddr _Listform Debug/};
747 8147 my $sortkeys = $self->Sortkeys;
748  
749 8147 ▶ $maxstringwidth = 0 if ($maxstringwidth //= 0) >= INT_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if ($maxstringwidth //= 0) >= 2147483647 0 8147 8147
Condition100%2/2
$maxstringwidth //= 0
l!l
813710
MC/DC100%1/1
$maxstringwidth //= 0
$maxstringwidth
Truth table100%2/2
A
A= $maxstringwidth
Aresult
11
00
750 8147 ▶ $truncsuffix //= "...";
Condition50%1/2
$truncsuffix //= "..."
l!l
81470
MC/DC0%0/1
$truncsuffix //= "..."
$truncsuffix
Truth table50%1/2
A
A= $truncsuffix
Aresult
11
00
751 8147 ▶ $trunctailwidth = min($trunctailwidth//0, $maxstringwidth);
Condition50%1/2
$trunctailwidth // 0
l!l
81470
MC/DC0%0/1
$trunctailwidth // 0
$trunctailwidth
Truth table50%1/2
A
A= $trunctailwidth
Aresult
11
00
752 8147 my $ovopt = "tagged";
753 8147 ▶ if (ref($objects) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $objects eq "HASH") 646 7501 8147
754 646 foreach my $key (keys %$objects) {
755 662 ▶ if ($key eq 'show_classname') { # DEPRECATED
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq 'show_classname') { } 0 662 662
elsif ($key eq 'overloads') { } 646 16 662
elsif ($key eq 'objects') { } 16 0 16
756 0 ▶ $ovopt = $objects->{$key} ? "tagged" : "transparent"
Branch: 1 branch
BranchTrueFalseTotal
$objects->{$key} ? : 0 0 0
757 }
758 elsif ($key eq 'overloads') {
759 646 ▶ if (!defined($objects->{$key})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $objects->{$key}) { } 0 646 646
elsif ($objects->{$key} =~ /^(?:tagged|transparent|ignore)$/u) { } 646 0 646
760 0 $ovopt = "tagged";
761 }
762 elsif ($objects->{$key} =~ /^(?:tagged|transparent|ignore)$/) {
763 646 $ovopt = $objects->{$key}
764 }
765 0 else { confess "Invalid 'overloads' sub-opt value '$objects->{$key}'" }
766 }
767 elsif ($key eq 'objects') { }
768 else {
769 0 confess "Objects hashref value has unknown key '$key'\n";
770 }
771 }
772 646 ▶ $objects = $objects->{objects} // 1;
Condition100%2/2
$objects->{"objects"} // 1
l!l
16630
MC/DC100%1/1
$objects->{"objects"} // 1
$objects->{"objects"}
Truth table100%2/2
A
A= $objects->{"objects"}
Aresult
11
00
773 }
774 8147 ▶ $objects = [ $objects ] unless ref($objects //= []) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref($objects //= []) eq "ARRAY" 8083 64 8147
Condition100%2/2
$objects //= []
l!l
81461
MC/DC100%1/1
$objects //= []
$objects
Truth table100%2/2
A
A= $objects
Aresult
11
00
775  
776 8147 ▶ my $dd = $self->dd || oops vis($self->dd);
Condition33%1/3
$self->dd || &oops(&vis($self->dd))
l!l&&r!l&&!r
814700
MC/DC0%0/2
$self->dd || &oops(&vis($self->dd))
$self->dd &oops(&vis($self->dd))
Truth table33%1/3
A || B
A= $self->ddB= &oops(&vis($self->dd))
ABresult
1X1
011
000
777 8147 my @orig_values = $dd->Values;
778 8147 ▶ croak "Exactly one item may be in Values" if @orig_values != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @orig_values != 1 0 8147 8147
779 8147 my $original = $orig_values[0];
780 8147 ▶ btw "##ORIGINAL=",u($original),"=",_dbvis($original) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 8147 8147
781  
782 8147 ▶ _croak_or_confess "*vis($original) called in void context.\nDid you forget to 'say ...'?"
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 8147 8147
783 if ! defined wantarray;
784  
785 # Allow one extra level if we wrapped the user's args in __getself_[ah]
786 8147 ▶ my $my_maxdepth = $self->Maxdepth || INT_MAX;
Condition100%2/2
$self->Maxdepth || 2147483647
l!l
448103
MC/DC100%1/1
$self->Maxdepth || 2147483647
$self->Maxdepth
Truth table100%2/2
A
A= $self->Maxdepth
Aresult
11
00
787 8147 ▶ ++$my_maxdepth if $listform && $my_maxdepth < INT_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $listform and $my_maxdepth < 2147483647 0 8147 8147
Condition66%2/3
$listform and $my_maxdepth < 2147483647
!ll&&!rl&&r
76804670
MC/DC0%0/2
$listform and $my_maxdepth < 2147483647
$listform $my_maxdepth < 2147483647
Truth table66%2/3
A and B
A= $listformB= $my_maxdepth < 2147483647
ABresult
0X0
100
111
788  
789 8147 @{ $self->{_VisitState} }{ qw/maxstringwidth truncsuffix trunctailwidth
790 objects opt_refaddr listform debug ovopt my_maxdepth my_visit_depth
791 in_overload_replacement/ }
792 =
793 ($maxstringwidth, $truncsuffix, $trunctailwidth, $objects, $opt_refaddr, $listform, $debug, $ovopt, $my_maxdepth, 0, 0);
794  
795 8147 my $modified = $self->visit($original); # see Data::Visitor
796  
797 ($maxstringwidth, $truncsuffix, $trunctailwidth, $objects, $opt_refaddr, $listform, $debug, $ovopt, $my_maxdepth)
798 =
799 8147 @{ $self->{_VisitState} }{ qw/maxstringwidth truncsuffix trunctailwidth
800 objects opt_refaddr listform debug ovopt my_maxdepth/ };
801  
802 8147 ▶ btw "## DD input : ",_dbvis($modified)," my_maxdepth=$my_maxdepth" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 8147 8147
803 8147 $dd->Values([$modified]);
804  
805 # Always call Data::Dumper with Indent(0) and Pad("") to get a single
806 # maximally-compact string, and then manually fold the result to Foldwidth,
807 # inserting the user's Pad before each line *except* the first.
808 #
809 # Also disable Maxdepth because we handle that ourself (see visit_ref).
810 8147 my $users_Maxdepth = $self->Maxdepth; # implemented by D::D
811 8147 $self->Maxdepth(0);
812 8147 my $users_pad = $self->Pad();
813 8147 $self->Pad("");
814  
815 8147 my ($dd_result, $our_result);
816 8147 my ($sAt, $sQ) = ($@, $?);
817 8147 { my $dd_warning = "";
818  
819 0 ▶ { local $SIG{__WARN__} = sub{ $dd_warning .= $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=0.4
820 8147 eval{ $dd_result = $dd->Dump };
821 }
822 8147 ▶ if ($dd_warning || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dd_warning or $@) 0 8147 8147
Condition33%1/3
$dd_warning or $@
l!l&&r!l&&!r
008147
MC/DC0%0/2
$dd_warning or $@
$dd_warning $@
Truth table33%1/3
A or B
A= $dd_warningB= $@
ABresult
1X1
011
000
823 0 ▶ warn "Data::Dumper complained:\n$dd_warning\n$@" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
824 0 ($@, $?) = ($sAt, $sQ);
825 0 $our_result = $self->dd->Values([$original])->Dump;
826 }
827 }
828 8147 ($@, $?) = ($sAt, $sQ);
829 8147 $self->Pad($users_pad);
830 8147 $self->Maxdepth($users_Maxdepth);
831  
832 8147 ▶ $our_result //= $self->_postprocess_DD_result($dd_result, $original);
Condition33%1/3
$our_result //= $self->_postprocess_DD_result($dd_result, $original)
l!l&&r!l&&!r
081470
MC/DC0%0/2
$our_result //= $self->_postprocess_DD_result($dd_result, $original)
$our_result $self->_postprocess_DD_result($dd_result, $original)
Truth table33%1/3
A //= B
A= $our_resultB= $self->_postprocess_DD_result($dd_result, $original)
ABresult
1X1
011
000
833  
834 # Allow deletion of the possibly-recursive clone
835 8147 circular_off($modified);
836 8147 $dd->Values([]);
837  
838 8147 &_RestorePunct;
839 8147 $our_result;
840 }#_Do
841  
842 #----------------------------------------------------------------------------
843 # methods called from Data::Visitor (and helpers) when transforming the input
844  
845 2446 ▶sub _prefix_refaddr {
Subroutine _prefix_refaddr: called CC=9 SCAR=23.1
846 2446 my ($self, $item, $original) = @_;
847 # If enabled by Refaddr(true):
848 #
849 # Prefix (the formatted representation of) a ref with it's abbreviated
850 # address. This is done by wrapping the ref in a temporary [array] with the
851 # prefix, and unwrapping the Data::Dumper result in _postprocess_DD_result().
852 my ($my_visit_depth, $opt_refaddr, $listform, $in_overload_replacement,
853 2446 $debug) = @{ $self->{_VisitState} }
854 2446 { qw/my_visit_depth opt_refaddr listform in_overload_replacement
855 debug/ };
856 2446 ▶ return $item
Branch: 2 branches
BranchTrueFalseTotal
unless $opt_refaddr and not $in_overload_replacement and $listform ? $my_visit_depth > 0 : 1 2408 38 2446
$listform ? : 17 21 38
Condition66%4/6
$opt_refaddr and not $in_overload_replacement and $listform ? $my_visit_depth > 0 : 1
!ll&&!rl&&r
2408038
$opt_refaddr and not $in_overload_replacement
!ll&&!rl&&r
2408038
MC/DC33%1/3
$opt_refaddr and not $in_overload_replacement and $listform ? $my_visit_depth > 0 : 1
$opt_refaddr not $in_overload_replacement $listform ? $my_visit_depth > 0 : 1
Truth table50%2/4
A and not(B) and C
A= $opt_refaddrB= not $in_overload_replacementC= $listform ? $my_visit_depth > 0 : 1
ABCresult
0XX0
10X0
1100
1111
857 unless $opt_refaddr
858 && ! $in_overload_replacement
859 && ($listform ? ($my_visit_depth > 0) # Not on our argument container
860 : 1); # Else always if not a (list)
861 38 ▶ my $pfx = _refaddrdechex($original//$item);
Condition33%1/3
$original // $item
l!l&&r!l&&!r
3800
MC/DC0%0/2
$original // $item
$original $item
Truth table33%1/3
A // B
A= $originalB= $item
ABresult
1X1
011
000
862 # However don't do this if $item already has an addrvis() substituted,
863 # which happens if an object does not stringify or provide another overload
864 # replacement -- see _object_subst().
865 38 my $ix = index($item,$pfx);
866 38 ▶say "_prefix_refaddr: ior=$in_overload_replacement pfx=$pfx ix=$ix original=",_dbvis1($original)," item=$item" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 38 38
867 38 ▶ return $item if $ix >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ix >= 0 0 38 38
868 38 $item = [ _MAGIC_REFPFX.$pfx, $item, _MAGIC_ELIDE_NEXT ];
869 38 ▶ btwN 1, '@@@addrvis-prefixed object:',_dbvis2($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 38 38
870 38 $item
871 }#_prefix_refaddr
872  
873 409 ▶sub _object_subst {
Subroutine _object_subst: called CC=33 SCAR=35.4
874 409 my ($self, $item) = @_;
875 409 my ($ovopt, $debug, $objects) = @{ $self->{_VisitState} }
876 409 { qw/ovopt debug objects/ };
877 409 my $overload_depth;
878 CHECKObject: {
879 409 ▶ if (my $class = blessed($item)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = builtin::blessed($item)) 409 240 649
880 409 ▶btw '@@@repl item is obj ',$item if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 409 409
881 409 my $enabled;
882 OSPEC:
883 409 foreach my $ospec (@$objects) {
884 #if (ref($ospec) eq "Regexp")
885 452 ▶ if (is_regexp($ospec))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_regexp($ospec)) { } 46 406 452
886 {
887 46 my @stack = ($class);
888 46 my %seen;
889 46 ▶ while (my $c = shift @stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = shift @stack) 78 16 94
890 78 ▶ $enabled=1, last OSPEC if $c =~ $ospec;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /$ospec/u 30 48 78
891 48 ▶ last CHECKObject if $seen{$c}++; # circular ISAs !
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$c}++ 0 48 48
892 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
893 48 push @stack, @{"${c}::ISA"};
894 }
895 } else {
896 406 ▶ $enabled=1, last OSPEC if ($ospec eq "1" || $item->isa($ospec));
Branch: 1 branch
BranchTrueFalseTotal
if $ospec eq 1 or $item->isa($ospec) 355 51 406
Condition100%3/3
$ospec eq 1 or $item->isa($ospec)
l!l&&r!l&&!r
3104551
MC/DC100%2/2
$ospec eq 1 or $item->isa($ospec)
$ospec eq 1 $item->isa($ospec)
Truth table100%3/3
A or B
A= $ospec eq 1B= $item->isa($ospec)
ABresult
1X1
011
000
897 }
898 }
899 last CHECKObject
900 409 ▶ unless $enabled;
Branch: 1 branch
BranchTrueFalseTotal
unless $enabled 24 385 409
901 385 ▶ if ($ovopt ne "ignore" && overload::Overloaded($item)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ovopt ne "ignore" and overload::Overloaded($item)) 240 145 385
Condition100%3/3
$ovopt ne "ignore" and overload::Overloaded($item)
!ll&&!rl&&r
6139240
MC/DC100%2/2
$ovopt ne "ignore" and overload::Overloaded($item)
$ovopt ne "ignore" overload::Overloaded($item)
Truth table100%3/3
A and B
A= $ovopt ne "ignore"B= overload::Overloaded($item)
ABresult
0X0
100
111
902 240 ▶btw '@@@repl obj is overloaded' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 240 240
903 # N.B. Overloaded(...) also returns true if it's a NAME of an
904 # overloaded package; should not happen in this case.
905 240 ▶ warn("Recursive overloads on $item ?\n"),last
Branch: 1 branch
BranchTrueFalseTotal
if $overload_depth++ > 10 0 240 240
906 if $overload_depth++ > 10;
907 240 ▶ my $cn = $ovopt eq "tagged" ? "($class)" : "";
Branch: 1 branch
BranchTrueFalseTotal
$ovopt eq 'tagged' ? : 234 6 240
908 # Stringify objects which have the stringification operator
909 240 ▶ if (overload::Method($class,'""')) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Method($class, "\"\"")) 230 10 240
910 230 ▶ my $prefix = _show_as_number($item) ? _MAGIC_NOQUOTES_PFX : "";
Branch: 1 branch
BranchTrueFalseTotal
&_show_as_number($item) ? : 228 2 230
911 230 ▶btw '@@@repl prefix="',$prefix,'"' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 230 230
912 230 $item = $item.""; # stringify;
913 230 ▶ if ($item !~ /^${class}=REF/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $item =~ /^$class=REF/u) { } 230 0 230
914 230 $item = "${prefix}${cn}$item";
915 } else {
916 # The "stringification" looks like Perl's default; don't prefix it
917 }
918 230 ▶btw '@@@repl stringified:',$item if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 230 230
919 230 redo CHECKObject;
920 }
921 # Substitute the virtual value behind an overloaded deref operator
922 # and prefix with (classname) to make clear what happened.
923 10 ▶ my sub _wrap_with_classname($) {
Subroutine _wrap_with_classname: called CC=2 SCAR=6.9
924 10 ▶ $cn ? [ _MAGIC_REFPFX.$cn, $_[0], _MAGIC_ELIDE_NEXT ] : $_[0]
Branch: 1 branch
BranchTrueFalseTotal
$cn ? : 5 5 10
925 }
926 10 ▶ if (overload::Method($class,'@{}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Method($class, "\@{}")) 2 8 10
927 2 $item = _wrap_with_classname \@{ $item };
928 2 ▶btw '@@@repl (overload @{} --> ', $item,')' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
929 2 redo CHECKObject;
930 }
931 8 ▶ if (overload::Method($class,'%{}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Method($class, "%{}")) 2 6 8
932 2 $item = _wrap_with_classname \%{ $item };
933 2 ▶btw '@@@repl (overload %{} --> ', $item,')' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
934 2 redo CHECKObject;
935 }
936 6 ▶ if (overload::Method($class,'${}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Method($class, "\${}")) 2 4 6
937 2 $item = _wrap_with_classname \${ $item };
938 2 ▶btw '@@@repl (overload ${} --> ', $item,')' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
939 2 redo CHECKObject;
940 }
941 4 ▶ if (overload::Method($class,'&{}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Method($class, "&{}")) 2 2 4
942 2 $item = _wrap_with_classname \&{ $item };
943 2 ▶btw '@@@repl (overload &{} --> ', $item,')' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
944 2 redo CHECKObject;
945 }
946 2 ▶ if (overload::Method($class,'*{}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Method($class, "*{}")) 2 0 2
947 2 $item = _wrap_with_classname \*{ $item };
948 2 ▶btw '@@@repl (overload *{} --> ', $item,')' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
949 2 redo CHECKObject;
950 }
951 }
952 145 ▶ if ($class eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'Regexp') { } 138 7 145
953 # D::D will just stringify it, which is fine except actual tabs etc.
954 # will be shown as themselves and not \t etc.
955 # We try to fix that in _postprocess_DD_result;
956 } else {
957 # No overloaded operator (that we care about);
958 # substitute addrvis(obj)
959 7 ▶btw '@@@repl (no overload repl, not Regexp)' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 7 7
960 7 $item = _MAGIC_NOQUOTES_PFX.addrvis($item);
961 }
962 }
963 }#CHECKObject
964 $item
965 409 }#_object_subst
966  
967 11190 ▶sub visit_value {
Subroutine visit_value: called CC=15 SCAR=27.2
Pod documented
968 11190 my ($self, $item) = @_;
969 # N.B. Not called for hash keys (short-circuited in visit_hash_key)
970  
971 my ($my_visit_depth, $my_maxdepth, $opt_refaddr, $listform,
972 $in_overload_replacement, $maxstringwidth, $truncsuffix,
973 11190 $trunctailwidth, $debug) = @{ $self->{_VisitState} }
974 11190 { qw/my_visit_depth my_maxdepth opt_refaddr listform
975 in_overload_replacement maxstringwidth truncsuffix
976 trunctailwidth debug/ };
977  
978 11190 ▶ say "!V value ",_dbravis2(@_)," depth:$my_visit_depth" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 11190 11190
979 11190 ▶ btw "! vd=$my_visit_depth my_maxdepth=$my_maxdepth" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 11190 11190
980  
981  
982 11190 ▶ return $item
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 188 11002 11190
983 if !defined($item);
984  
985 11002 ▶ return $self->_object_subst($item)
Branch: 1 branch
BranchTrueFalseTotal
if defined builtin::blessed($item) 409 10593 11002
986 if defined(blessed $item);
987  
988 10593 ▶ return $item
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($item) 4 10589 10593
989 if reftype($item); # some other (i.e. not blessed) reference
990  
991 # Prepend a "magic prefix" (later removed) to items which Data::Dumper is
992 # likely to represent wrongly or anyway not how we want:
993 #
994 # 1. Scalars set to strings like "6" will come out as a number 6 rather
995 # than "6" with Useqq(1) or Useperl(1) (string-ness is preserved
996 # with other options). IMO this is a Data::Dumper bug which the
997 # maintainers won't fix it because the difference isn't functionally
998 # relevant to correctly-written Perl code. However we want to help
999 # humans debug their software by showing the representation they
1000 # most likely used to create the datum.
1001 #
1002 # 2. Floating point values come out as "strings" to avoid some
1003 # cross-platform issue. For our purposes we want all numbers
1004 # to appear unquoted.
1005 #
1006 10589 ▶ if (looks_like_number($item) && $item !~ /^0\d/ && !_is_bool($item)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_number($item) and not $item =~ /^0\d/u and not &_is_bool($item)) { } 4265 6324 10589
elsif ($maxstringwidth and not &_show_as_number($item) and length $item > $maxstringwidth + length($truncsuffix)) { } 9 12453 12462
Condition100%6/6
&looks_like_number($item) and not $item =~ /^0\d/u and not &_is_bool($item)
!ll&&!rl&&r
632314265
&looks_like_number($item) and not $item =~ /^0\d/u
!ll&&!rl&&r
631944266
MC/DC100%3/3
&looks_like_number($item) and not $item =~ /^0\d/u and not &_is_bool($item)
&looks_like_number($item) not $item =~ /^0\d/u not &_is_bool($item)
Truth table100%4/4
A and not(B) and not(C)
A= &looks_like_number($item)B= not $item =~ /^0\d/uC= not &_is_bool($item)
ABCresult
0XX0
10X0
1100
1111
1007 4265 ▶ my $prefix = _show_as_number($item) ? _MAGIC_NOQUOTES_PFX
Branch: 1 branch
BranchTrueFalseTotal
&_show_as_number($item) ? : 3930 335 4265
1008 : _MAGIC_KEEPQUOTES_PFX ;
1009 4265 $item = $prefix.$item;
1010 4265 ▶btw '@@@repl prefixed item:',$item if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4265 4265
1011 }
1012  
1013 # Truncacte overly-long strings
1014 ▶ elsif ($maxstringwidth && !_show_as_number($item)
Condition83%5/6
$maxstringwidth and not &_show_as_number($item) and length $item > $maxstringwidth + length($truncsuffix)
!ll&&!rl&&r
61381779
$maxstringwidth and not &_show_as_number($item)
!ll&&!rl&&r
61380186
MC/DC66%2/3
$maxstringwidth and not &_show_as_number($item) and length $item > $maxstringwidth + length($truncsuffix)
$maxstringwidth not &_show_as_number($item) length $item > $maxstringwidth + length($truncsuffix)
Truth table75%3/4
A and not(B) and C
A= $maxstringwidthB= not &_show_as_number($item)C= length $item > $maxstringwidth + length($truncsuffix)
ABCresult
0XX0
10X0
1100
1111
1015 && length($item) > $maxstringwidth + length($truncsuffix)) {
1016 9 my $tail_offset = length($item) - $trunctailwidth;
1017 9 ▶btw '@@@repl truncating ',substr($item,0,10),"...","[ msw=$maxstringwidth l=",length($item)," ttw=$trunctailwidth to=$tail_offset]" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 9 9
1018 #$item = "".substr($item,0,$maxstringwidth).$truncsuffix;
1019 9 $item = "".substr($item,0,$maxstringwidth-$trunctailwidth).$truncsuffix.substr($item,$tail_offset,$trunctailwidth);
1020 }
1021 $item
1022 10589 }#visit_value
1023  
1024 1575 ▶sub visit_hash_key {
Subroutine visit_hash_key: called CC=2 SCAR=7.0
Pod documented
1025 1575 my ($self, $item) = @_;
1026 1575 my ($debug) = @{ $self->{_VisitState} } { qw/debug/ };
1027  
1028 1575 ▶ say "!V visit_hash_key ",_dbvis($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1575 1575
1029 1575 return $item; # don't truncate or otherwise munge
1030 }
1031  
1032 409 ▶sub visit_object {
Subroutine visit_object: called CC=5 SCAR=16.2
Pod documented
1033 409 my ($self, $item) = @_;
1034 409 my ($my_visit_depth, $debug) = @{ $self->{_VisitState} }
1035 409 { qw/my_visit_depth debug/ };
1036  
1037 409 ▶ say "!V object a=",_refaddrdechex($item)," depth:$my_visit_depth"," item=",_dbvis1($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 409 409
1038 409 my $original = $item;
1039  
1040 local $self->{_VisitState}->{my_visit_depth}
1041 409 = $self->{_VisitState}->{my_visit_depth} + 1;
1042  
1043 # FIXME: with Objects(0) we should visit object internals so $my_maxdepth
1044 # can be applied correctly. Currently we just leave object refs as-is
1045 # for D::D to expand, and Maxdepth will be handled incorrectly if this
1046 # is underneath a magic_refaddr wrapper or avis/hvis top wrapper.
1047  
1048 # First register the ref (to detect duplicates); this calls visit_seen()
1049 # which usually substitutes something.
1050 { # Suppress Refaddr treatment of the results of any overloads
1051 409 local $self->{_VisitState}->{in_overload_replacement}
1052 409 = $self->{_VisitState}->{in_overload_replacement} + 1;
1053  
1054 409 my $nitem = $self->SUPER::visit_object($item);
1055 # Can not compare object refs with != in case that op is not defined!
1056 # (and refaddr() returns undef if $nitem is e.g. a "magic string")
1057 409 ▶ if (u(refaddr($nitem)) ne u(refaddr($item))) {
Branch: 1 branch
BranchTrueFalseTotal
if (&u(scalar builtin::refaddr($nitem)) ne &u(scalar builtin::refaddr($item))) 247 162 409
1058 247 ▶ say "! (obj) new: $item --> ",_dbrvis2($nitem) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 247 247
1059 247 $item = $nitem;
1060 # Re-visit the replacement item, which might contain inner structure.
1061 247 $nitem = $self->SUPER::visit($item);
1062 247 ▶ say "! (obj) recursion on repl: $item --> $nitem" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 247 247
1063 247 $item = $nitem;
1064 }
1065 }
1066 409 $item = $self->_prefix_refaddr($item, $original);
1067 409 $item
1068 }#visit_object
1069  
1070 2038 ▶sub visit_ref {
Subroutine visit_ref: called CC=15 SCAR=27.5
Pod documented
1071 2038 my ($self, $item) = @_;
1072  
1073 2038 my ($my_visit_depth, $my_maxdepth, $debug) = @{ $self->{_VisitState} }
1074 2038 { qw/my_visit_depth my_maxdepth debug/ };
1075  
1076 2038 ▶ if (ref($item) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 631 1407 2038
1077 631 ▶ say "!V ref ",addrvis($item)," depth:$my_visit_depth max:$my_maxdepth item=",_dbavis2(@$item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 631 631
1078 } else {
1079 1407 ▶ say "!V ref ",addrvis($item)," depth:$my_visit_depth max:$my_maxdepth item=",_dbvis1($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1407 1407
1080 }
1081 2038 my $original = $item;
1082  
1083 # The Refaddr option introduces [...] wrappers in the tree and so
1084 # Data::Dumper's Maxdepth() option will not work as we intend.
1085 # Therefore we implement Maxdepth ourself
1086 2038 ▶ if ($my_visit_depth >= $my_maxdepth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_visit_depth >= $my_maxdepth) 1 2037 2038
1087 1 ▶ oops "[vd=$my_visit_depth maxd=$my_maxdepth debug=",_dbvis($debug),"]\n\n item=",_dbshow($item),"\n\n self=",_dbvis($self), "\n\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $my_visit_depth == $my_maxdepth 0 1 1
1088 unless $my_visit_depth == $my_maxdepth;
1089 1 $item = _MAGIC_NOQUOTES_PFX.addrvis($item);
1090 1 ▶ say "! maxdepth reached, returning ",_dbvis2($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
1091 1 return $item
1092 }
1093  
1094 # Show name of sub for CODE refs (using Sub::Identify)
1095 2037 ▶ if (ref($item) eq 'CODE' && ! $self->Deparse()) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq "CODE" and not $self->Deparse) 46 1991 2037
Condition100%3/3
ref $item eq "CODE" and not $self->Deparse
!ll&&!rl&&r
1987446
MC/DC100%2/2
ref $item eq "CODE" and not $self->Deparse
ref $item eq "CODE" not $self->Deparse
Truth table100%3/3
A and not(B)
A= ref $item eq "CODE"B= not $self->Deparse
ABresult
0X0
100
111
1096 #$item = _MAGIC_NOQUOTES_PFX.addrvis($item);
1097 46 my $subname = sub_fullname($item);
1098 46 ▶ if ($subname =~ /__ANON__/) { # add more info
Branch: 1 branch
BranchTrueFalseTotal
if ($subname =~ /__ANON__/u) 6 40 46
1099 6 my ($file, $line) = get_code_location($item);
1100 6 $subname .= "\@".basename($file).":$line";
1101 }
1102 46 $item = _MAGIC_NOQUOTES_PFX.'\&'.$subname;
1103 46 ▶ say "! CODEref without Deparse, returning ",_dbvis2($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 46 46
1104 #return $item;
1105 }
1106  
1107 # First descend into the structure, probably returning a clone
1108 local $self->{_VisitState}->{my_visit_depth}
1109 2037 = $self->{_VisitState}->{my_visit_depth} + 1;
1110  
1111 2037 ▶ if (ref($item)) { # not replaced above...
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item) 1991 46 2037
1112 #my $nitem = $self->SUPER::visit_ref($item);
1113 1991 ▶btw "# descending... vd=$my_visit_depth my_maxdepth=$my_maxdepth" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1991 1991
1114 1991 my $nitem = $self->SUPER::visit_ref($item);
1115 1991 ▶btw "# ...back up... vd=$my_visit_depth my_maxdepth=$my_maxdepth" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1991 1991
1116 1991 ▶ say "! (ref) new: ",_dbrvis2($item),
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1991 1991
1117 "\n --> ",_dbrvis2($nitem) if $debug;
1118 1991 $item = $nitem;
1119 }
1120  
1121 # Prepend the original address to whatever the representation is now
1122 2037 $item = $self->_prefix_refaddr($item, $original);
1123  
1124 2037 $item
1125 }#visit_ref
1126 610 ▶sub visit_hash_entries {
Subroutine visit_hash_entries: called CC=4 SCAR=14.8
Pod documented
1127 610 my ($self, $hash) = @_;
1128 610 my ($my_visit_depth, $my_maxdepth, $sortkeys, $debug) = @{ $self->{_VisitState} }
1129 610 { qw/my_visit_depth my_maxdepth sortkeys debug/ };
1130  
1131 610 ▶ say "!V hash_entries ",addrvis($hash) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 610 610
1132 610 ▶ btw "! vd=$my_visit_depth my_maxdepth=$my_maxdepth" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 610 610
1133 # Visit in sorted order
1134 1575 ▶ return map { $self->visit_hash_entry( $_, $hash->{$_}, $hash ) }
Branch: 1 branch
BranchTrueFalseTotal
ref $sortkeys ? : 0 610 610
1135 0 (ref($sortkeys) ? @{ $sortkeys->($hash) } : (sort keys %$hash));
1136 }
1137  
1138 5 ▶sub visit_glob {
Subroutine visit_glob: called CC=2 SCAR=7.0
Pod documented
1139 5 my ($self, $item) = @_;
1140 5 my ($my_visit_depth, $debug) = @{ $self->{_VisitState} }
1141 5 { qw/my_visit_depth debug/ };
1142  
1143 5 ▶ say "!V glob ref()=",ref($item)," depth:$my_visit_depth"," item=",_dbravis2($item) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 5 5
1144 # By default Data::Visitor will create a new anon glob in the output tree.
1145 # Instead, put the original into the output so the user can recognize
1146 # it e.g. "*main::STDOUT" instead of an anonymous from Symbol::gensym
1147 5 return $item
1148 }
1149  
1150 92 ▶sub visit_seen {
Subroutine visit_seen: called CC=6 SCAR=17.9
Pod documented
1151 92 my ($self, $data, $first_result) = @_;
1152 92 my ($my_visit_depth, $opt_refaddr, $debug) = @{ $self->{_VisitState} }
1153 92 { qw/my_visit_depth opt_refaddr debug/ };
1154  
1155 92 ▶ say "!V seen orig=",_dbrvis2($data)," depth:$my_visit_depth"," 1stres=",_dbrvis2($first_result)
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 92 92
1156 if $debug;
1157  
1158 # $data is a ref which has been visited before, i.e. there is a circularity.
1159 # Data::Dumper will display a $VAR->... expression.
1160 # With the Refaddr option the $VAR index may be incorrect due to the
1161 # temporary [...] wrappers inserted into the cloned tree.
1162 #
1163 # Therefore if Refaddr is in effect substitute an addrvis() string
1164 # which the user will be able to match with other refs to the same thing.
1165 92 ▶ if ($opt_refaddr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_refaddr) 7 85 92
1166 7 my $t = ref($data);
1167 7 ▶ return _MAGIC_NOQUOTES_PFX._refaddrdechex($data)."[...]" if $t eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "ARRAY" 2 5 7
1168 5 ▶ return _MAGIC_NOQUOTES_PFX._refaddrdechex($data)."{...}" if $t eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "HASH" 2 3 5
1169 3 ▶ return _MAGIC_NOQUOTES_PFX._refaddrdechex($data)."\\..." if $t eq "SCALAR";
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "SCALAR" 2 1 3
1170 1 return _MAGIC_NOQUOTES_PFX.addrvis($data);
1171 }
1172  
1173 $first_result
1174 85 }
1175  
1176 #---------------------------------------------------------------------
1177 0 ▶sub _preprocess { # Modify the cloned data
Subroutine _preprocess: not called CC=32 SCAR=68.8
1178 15 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
1179 0 my ($self, $cloned_itemref, $orig_itemref) = @_;
1180 0 my ($debug, $seenhash) = @$self{qw/Debug Seenhash/};
1181  
1182 0 ▶btw '##pp AAA cloned=",addrvis($cloned_itemref)," -> ',_dbvis($$cloned_itemref) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1183 0 ▶btw '## orig=",addrvis($orig_itemref)," -> ",_dbvis($$orig_itemref)' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1184  
1185 # Pop back if this item was visited previously
1186 0 ▶ if ($seenhash->{ _refaddrdechex($cloned_itemref) }++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$seenhash{&_refaddrdechex($cloned_itemref)}++) 0 0 0
1187 0 ▶ btw ' Seen already' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1188 return
1189 0 }
1190  
1191 # About TIED VARIABLES:
1192 # We must never modify a tied variable because of user-defined side-effects.
1193 # So when we want to replace a tied variable we untie it first, if possible.
1194 # N.B. The whole structure was cloned, so this does not untie the
1195 # user's variables.
1196 #
1197 # All modifications (untie and over-writing) is done in eval{...} in case
1198 # the data is read-only or an UNTIE handler throws -- in which case we leave
1199 # the cloned item as it is. This occurs e.g. with the 'Readonly' module;
1200 # I tried using Readonly::Clone (insterad of Clone::clone) to copy the input,
1201 # since it is supposed to make a mutable copy; but it has bugs with refs to
1202 # other refs, and doesn't actually make everything mutable; it was a big mess
1203 # so now taking the simple way out.
1204  
1205 # Side note: Taking a ref to a member of a tied container,
1206 # e.g. \$tiedhash{key}, actually returns an overloaded object or some other
1207 # magical thing which, every time it is de-referenced, FETCHes the datum
1208 # into a temporary.
1209 #
1210 # There is a bug somewhere which makes it unsafe to store these fake
1211 # references inside tied variables because after the variable is 'untie'd
1212 # bad things can happen (refcount problems?). So after a lot of mucking
1213 # around I gave up trying to do anything intelligent about tied data.
1214 # I still have to untie variables before over-writing them with substitute
1215 # content.
1216  
1217 # Note: Our Item is only ever a scalar, either the top-level item from the
1218 # user or a member of a container we unroll below. In either case the
1219 # scalar could be either a ref to something or a non-ref value.
1220  
1221 0 eval {
1222 0 ▶ if (tied($$cloned_itemref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied $$cloned_itemref) 0 0 0
1223 0 ▶ btw ' Item itself is tied' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1224 0 my $copy = $$cloned_itemref;
1225 0 untie $$cloned_itemref;
1226 0 $$cloned_itemref = $copy; # n.b. $copy might be a ref to a tied variable
1227 0 ▶ oops if tied($$cloned_itemref);
Branch: 1 branch
BranchTrueFalseTotal
if tied $$cloned_itemref 0 0 0
1228 }
1229  
1230 0 ▶ my $rt = reftype($$cloned_itemref) // ""; # "" if item is not a ref
Condition0%0/2
builtin::reftype($$cloned_itemref) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($$cloned_itemref) // ""
builtin::reftype($$cloned_itemref)
Truth table0%0/2
A
A= builtin::reftype($$cloned_itemref)
Aresult
11
00
1231 0 ▶ if (reftype($cloned_itemref) eq "SCALAR") {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($cloned_itemref) eq "SCALAR") 0 0 0
1232 0 ▶ oops if $rt;
Branch: 1 branch
BranchTrueFalseTotal
if $rt 0 0 0
1233 0 ▶ btw '##pp item is non-ref scalar; stop.' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1234 return
1235 0 }
1236  
1237 # Item is some kind of ref
1238 0 ▶ oops unless reftype($cloned_itemref) eq "REF";
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($cloned_itemref) eq "REF" 0 0 0
1239 0 ▶ oops unless reftype($orig_itemref) eq "REF";
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($orig_itemref) eq "REF" 0 0 0
1240  
1241 0 ▶ if ($rt eq "SCALAR" || $rt eq "LVALUE" || $rt eq "REF") {
Branch: 3 branches
BranchTrueFalseTotal
if ($rt eq 'SCALAR' or $rt eq 'LVALUE' or $rt eq 'REF') { } 0 0 0
elsif ($rt eq 'ARRAY') { } 0 0 0
elsif ($rt eq 'HASH') { } 0 0 0
Condition0%0/6
$rt eq "SCALAR" or $rt eq "LVALUE" or $rt eq "REF"
l!l&&r!l&&!r
000
$rt eq "SCALAR" or $rt eq "LVALUE"
l!l&&r!l&&!r
000
MC/DC0%0/3
$rt eq "SCALAR" or $rt eq "LVALUE" or $rt eq "REF"
$rt eq "SCALAR" $rt eq "LVALUE" $rt eq "REF"
Truth table0%0/4
A or B or C
A= $rt eq "SCALAR"B= $rt eq "LVALUE"C= $rt eq "REF"
ABCresult
1XX1
01X1
0011
0000
1242 0 ▶ btw '##pp dereferencing ref-to-scalarish $rt' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1243 0 $self->_preprocess($$cloned_itemref, $$orig_itemref);
1244 }
1245 elsif ($rt eq "ARRAY") {
1246 0 ▶ btw '##pp ARRAY ref' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1247 0 ▶ if (tied @$$cloned_itemref) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied @$$cloned_itemref) 0 0 0
1248 0 ▶ btw ' aref to *tied* ARRAY' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1249 0 my $copy = [ @$$cloned_itemref ]; # only 1 level
1250 0 untie @$$cloned_itemref;
1251 0 @$$cloned_itemref = @$copy;
1252 }
1253 0 for my $ix (0..$#{$$cloned_itemref}) {
1254 0 $self->_preprocess(\$$cloned_itemref->[$ix], \$$orig_itemref->[$ix]);
1255 }
1256 }
1257 elsif ($rt eq "HASH") {
1258 0 ▶ btw '##pp HASH ref' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1259 0 ▶ if (tied %$$cloned_itemref) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied %$$cloned_itemref) 0 0 0
1260 0 ▶ btw ' href to *tied* HASH' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1261 0 my $copy = { %$$cloned_itemref }; # only 1 level
1262 0 untie %$$cloned_itemref;
1263 0 %$$cloned_itemref = %$copy;
1264 0 ▶ die if tied %$$cloned_itemref;
Branch: 1 branch
BranchTrueFalseTotal
if tied %$$cloned_itemref 0 0 0
1265 }
1266 #For easier debugging, do in sorted order
1267 0 ▶ btw ' #### iterating hash values...' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1268 0 for my $key (sort keys %$$cloned_itemref) {
1269 0 $self->_preprocess(\$$cloned_itemref->{$key}, \$$orig_itemref->{$key});
1270 }
1271 }
1272 };#eval
1273 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1274 0 ▶ btw "*EXCEPTION*, just returning\n$@\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
1275 }
1276 }
1277  
1278 9763 ▶sub _is_bool(_) {
Subroutine _is_bool: called CC=1 SCAR=0.0
1279 9763 _SUPPORTS_CORE_BOOLS && builtin::is_bool($_[0])
1280 }
1281  
1282 5513 ▶sub _show_as_number(_) {
Subroutine _show_as_number: called CC=21 SCAR=37.4
1283 5513 my $value = shift;
1284  
1285 # IMPORTANT: We must not do any numeric ops or comparisions
1286 # on $value because that may set some magic which defeats our attempt
1287 # to try bitstring unary & below (after a numeric compare, $value is
1288 # apparently assumed to be numeric or dual-valued even if it
1289 # is/was just a "string").
1290  
1291 5513 ▶ return 0 if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 5512 5513
1292  
1293 # if the utf8 flag is on, it almost certainly started as a string
1294 5512 ▶ return 0 if (ref($value) eq "") && utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "" and utf8::is_utf8($value) 15 5497 5512
Condition100%3/3
ref $value eq "" and utf8::is_utf8($value)
!ll&&!rl&&r
258523915
MC/DC100%2/2
ref $value eq "" and utf8::is_utf8($value)
ref $value eq "" utf8::is_utf8($value)
Truth table100%3/3
A and B
A= ref $value eq ""B= utf8::is_utf8($value)
ABresult
0X0
100
111
1295  
1296 5497 ▶ return 0 if _is_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
if &_is_bool($value) 1 5496 5497
1297  
1298 # There was a Perl bug where looks_like_number() provoked a warning from
1299 # BigRat.pm if it is called under 'use bigrat;' so we must not do that.
1300 # https://github.com/Perl/perl5/issues/20685
1301 #return 0 unless looks_like_number($value);
1302  
1303 # JSON::PP uses these tricks:
1304 # string & "" -> "" # bitstring AND, truncating to shortest operand
1305 # number & "" -> 0 (with warning)
1306 # number * 0 -> 0 unless number is nan or inf
1307  
1308 # Attempt uniary & with "string" and see what happens
1309 5496 my $uand_str_result = eval {
1310 15 ▶ use warnings "FATAL" => "all"; # Convert warnings into exceptions
Subroutine BEGIN: called CC=1 SCAR=0.0
1311 15 ▶ no if $bitwise_supported, "feature", "bitwise";
Subroutine BEGIN: called CC=1 SCAR=0.0
1312 15 ▶ no warnings "once";
Subroutine BEGIN: called CC=1 SCAR=0.0
1313 # Use FF... so we can see what $value was in debug messages below
1314 5496 my $dummy = ($value & "\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}");
1315 };
1316 5496 ▶ btw '##_san $value \$@=$@' if $Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Data::Dumper::Interp::Debug 0 5496 5496
1317 5496 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 3956 1540 5496
elsif (ref $uand_str_result ne '' and $uand_str_result =~ /NaN|Inf/u) { } 241 2598 2839
1318 3956 ▶ if ($@ =~ /".*" isn't numeric/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /".*" isn't numeric/u) 3954 2 3956
1319 3954 return 1; # Ergo $value must be numeric
1320 }
1321 2 ▶ if ($@ =~ /\& not supported/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /\& not supported/u) 0 2 2
1322 # If it is an object then it probably (but not necessarily)
1323 # is numeric but just doesn't support bitwise operators,
1324 # for example BigRat.
1325 0 ▶ return 1 if defined blessed($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined builtin::blessed($value) 0 0 0
1326 }
1327 2 ▶ if ($@ =~ /no method found/) { # overloaded but does not do '&'
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /no method found/u) 2 0 2
1328 # It must use overloads, but does not implement '&'
1329 # Assume it is string-ish
1330 2 ▶ return 0 if defined blessed($value); # else our mistake, isn't overloaded
Branch: 1 branch
BranchTrueFalseTotal
if defined builtin::blessed($value) 2 0 2
1331 }
1332 0 ▶ warn "# ".__PACKAGE__." : value=",_dbshow($value),
Branch: 1 branch
BranchTrueFalseTotal
if $Data::Dumper::Interp::Debug 0 0 0
1333 "\n Unhandled warn/exception from unary & :$@\n"
1334 if $Debug;
1335 # Unknown problem, treat as a string
1336 0 return 0;
1337 }
1338 ▶ elsif (ref($uand_str_result) ne "" && $uand_str_result =~ /NaN|Inf/) {
Condition66%2/3
ref $uand_str_result ne "" and $uand_str_result =~ /NaN|Inf/u
!ll&&!rl&&r
12990241
MC/DC50%1/2
ref $uand_str_result ne "" and $uand_str_result =~ /NaN|Inf/u
ref $uand_str_result ne "" $uand_str_result =~ /NaN|Inf/u
Truth table66%2/3
A and B
A= ref $uand_str_result ne ""B= $uand_str_result =~ /NaN|Inf/u
ABresult
0X0
100
111
1339 # unary & returned an object representing Nan or Inf
1340 # (e.g. Math::BigFloat) so $value must be numberish.
1341 241 return 1;
1342 }
1343 1299 ▶ warn "# ".__PACKAGE__." : (value & \"...\") succeeded\n",
Branch: 1 branch
BranchTrueFalseTotal
if $Data::Dumper::Interp::Debug 0 1299 1299
1344 " value=", _dbshow($value), "\n",
1345 " uand_str_result=", _dbvis($uand_str_result),"\n"
1346 if $Debug;
1347 # Sigh. With Perl 5.32 (at least) $value & "..." stringifies $value
1348 # or so it seems.
1349 1299 ▶ if (blessed($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value)) { } 0 1299 1299
1350 # If $value is garbage perl will print compile-error warnings
1351 # but not die, so eval won't swallow them
1352 0 ▶ local $SIG{__WARN__} = sub {die @_};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1353 0 ▶ if (blessed( eval{ $value+42 } )) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed(eval { do { $value + 42 } })) { } 0 0 0
1354 0 ▶ warn " Object and value+42 is still an object, so probably numberish\n"
Branch: 1 branch
BranchTrueFalseTotal
if $Data::Dumper::Interp::Debug 0 0 0
1355 if $Debug;
1356 0 return 1
1357 } else {
1358 0 ▶ warn " Object and value+42 is NOT an object, so it must be stringish\n"
Branch: 1 branch
BranchTrueFalseTotal
if $Data::Dumper::Interp::Debug 0 0 0
1359 if $Debug;
1360 0 return 0
1361 }
1362 } else {
1363 1299 ▶ warn " NOT an object, so must be a string\n",
Branch: 1 branch
BranchTrueFalseTotal
if $Data::Dumper::Interp::Debug 0 1299 1299
1364 if $Debug;
1365 1299 return 0;
1366 }
1367 }# _show_as_number
1368  
1369 # Split keys into "components" (e.g. 2_16.A has 3 components) and sort
1370 # components containing only digits numerically.
1371 600 ▶sub __sortkeys {
Subroutine __sortkeys: called CC=7 SCAR=20.5
1372 600 my $hash = shift;
1373 my $r = [
1374 600 sort { my @a = split /(?<=\d)(?=\D)|(?<=\D)(?=\d)/,$a;
1375 2270 my @b = split /(?<=\d)(?=\D)|(?<=\D)(?=\d)/,$b;
1376 2270 ▶ for (my $i=0; $i <= $#a; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#a) 2076 194 2270
1377 2076 ▶ return 1 if $i > $#b; # a is longer
Branch: 1 branch
BranchTrueFalseTotal
if $i > $#b 202 1874 2076
1378 1874 ▶ my $r = ($a[$i] =~ /^\d+$/ && $b[$i] =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
$a[$i] =~ /^\d+$/u && $b[$i] =~ /^\d+$/u ? : 0 1874 1874
Condition33%1/3
$a[$i] =~ /^\d+$/u and $b[$i] =~ /^\d+$/u
!ll&&!rl&&r
187400
MC/DC0%0/2
$a[$i] =~ /^\d+$/u and $b[$i] =~ /^\d+$/u
$a[$i] =~ /^\d+$/u $b[$i] =~ /^\d+$/u
Truth table33%1/3
A and B
A= $a[$i] =~ /^\d+$/uB= $b[$i] =~ /^\d+$/u
ABresult
0X0
100
111
1379 ? ($a[$i] <=> $b[$i]) : ($a[$i] cmp $b[$i]) ;
1380 1874 ▶ return $r if $r != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $r != 0 1874 0 1874
1381 }
1382 194 ▶ return -1 if $#a < $#b; # a is shorter
Branch: 1 branch
BranchTrueFalseTotal
if $#a < $#b 194 0 194
1383 0 return 0;
1384 }
1385 keys %$hash
1386 ];
1387 600 $r
1388 }
1389  
1390 15 my $quoted_re = RE_quoted(-delim => q{'"});
1391  
1392 15 my $balanced_re = RE_balanced(-parens=>'{}[]()');
1393  
1394 # cf man perldata
1395 15 my $userident_re = qr/ (?: (?=\p{Word})\p{XID_Start} | _ )
1396 (?: (?=\p{Word})\p{XID_Continue} )* /x;
1397  
1398 15 my $pkgname_re = qr/ ${userident_re} (?: :: ${userident_re} )* /x;
1399  
1400 15 our $curlies_re = RE_balanced(-parens=>'{}');
1401 15 our $parens_re = RE_balanced(-parens=>'()');
1402 15 our $curliesorsquares_re = RE_balanced(-parens=>'{}[]');
1403  
1404 15 my $anyvname_re =
1405 qr/ ${pkgname_re} | [0-9]+ | \^[A-Z]
1406 | [-+!\$\&\;i"'().,\@\/:<>?\[\]\~\^\\] /x;
1407  
1408 15 my $anyvname_or_refexpr_re = qr/ ${anyvname_re} | ${curlies_re} /x;
1409  
1410 15 my $addrvis_re = qr/\<\d+:(?:\Q${\_ADDRVIS_SHARED_MARK}\E)?[\da-fA-F]+\>/;
1411  
1412 21354 ▶sub __unmagic_atom() { # edits $_
Subroutine __unmagic_atom: called CC=1 SCAR=0.0
1413 ## # FIXME this probably could omit the ([^'"]*?) bc there is never anything
1414 ## # between the open quote and the _MAGIC_NOQUOTES_PFX
1415 ## s/(['"])([^'"]*?)
1416 ## (?:\Q${\_MAGIC_NOQUOTES_PFX}\E)
1417 ## (.*?)(\1)/$2$3/xgs;
1418  
1419 21354 s/(['"])
1420 21354 (?:\Q${\_MAGIC_NOQUOTES_PFX}\E) (.*?)
1421 4221 (\1)/do{ local $_ = $2;
1422 4221 s!\\(.)!$1!g; # undo double-quotish backslash escapes
1423 4221 $_ }/xegs;
1424  
1425 21354 s/\Q${\_MAGIC_KEEPQUOTES_PFX}\E//gs;
1426 }
1427  
1428 17322 ▶sub __unesc_unicode() { # edits $_
Subroutine __unesc_unicode: called CC=6 SCAR=17.9
1429 17322 ▶ if (/^"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^"/u) 5134 12188 17322
1430 # Data::Dumper with Useqq(1) outputs wide characters as hex escapes;
1431 # turn them back into the original characters if "printable".
1432 # That means "Graph" category EXCEPT:
1433 # BOM (which is ZERO WIDTH NO-BREAK SPACE so is considered "Graphical")
1434 # and any other "Format" category Unicode characters; we want see those
1435 # in hex.
1436 5134 s{
1437 \G (?: [^\\]++ | \\[^x] )*+ \K (?<w> \\x\x{7B} (?<hex>[a-fA-F0-9]+) \x{7D} )
1438 }{
1439 312 my $orig = $+{w};
1440 312 ▶ local $_ = hex( length($+{hex}) > 6 ? '0' : $+{hex} );
Branch: 1 branch
BranchTrueFalseTotal
length $+{'hex'} > 6 ? : 1 311 312
1441 312 ▶ $_ = $_ > 0x10FFFF ? "\0" : chr($_); # 10FFFF is Unicode limit
Branch: 1 branch
BranchTrueFalseTotal
$_ > 1114111 ? : 2 310 312
1442 # Using 'lc' so regression tests do not depend on Data::Dumper's
1443 # choice of case when escaping wide characters.
1444 312 ▶ (m<\P{XPosixGraph}|[\0-\177]>
Branch: 1 branch
BranchTrueFalseTotal
/\P{XPosixGraph}|[\0-\177]/u || /\p{General_Category=Format}/u ? : 3 309 312
Condition66%2/3
/\P{XPosixGraph}|[\0-\177]/u or /\p{General_Category=Format}/u
l!l&&r!l&&!r
30309
MC/DC50%1/2
/\P{XPosixGraph}|[\0-\177]/u or /\p{General_Category=Format}/u
/\P{XPosixGraph}|[\0-\177]/u /\p{General_Category=Format}/u
Truth table66%2/3
A or B
A= /\P{XPosixGraph}|[\0-\177]/uB= /\p{General_Category=Format}/u
ABresult
1X1
011
000
1445 || m<\p{General_Category=Format}>) ? lc($orig) : $_
1446 }xesg;
1447 }
1448 }
1449  
1450 15 my %ctlesc2codepoint = (
1451 '\\a' => ord("\a"),
1452 '\\b' => ord("\b"),
1453 '\\t' => ord("\t"),
1454 '\\n' => ord("\n"),
1455 '\\f' => ord("\f"),
1456 '\\r' => ord("\r"),
1457 '\\e' => ord("\e"),
1458 );
1459 0 ▶sub __unesc_nonoctal () { # edits $_
Subroutine __unesc_nonoctal: not called CC=5 SCAR=34.0
1460 # Change backslash escapes like \n back to octal escapes.
1461 # This is to better visualize binary octet streams
1462 0 ▶ if (/^"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^"/u) 0 0 0
1463 0 s{
1464 \G (?: [^\\]++ | \\[x0-7] )*+ \K (?<w> \\[abtnfre])(?<digitnext>\d?)
1465 }{
1466 $+{digitnext}
1467 ? sprintf("\\%03o", ($ctlesc2codepoint{$+{w}} // oops))
1468 0 ▶ : sprintf("\\%01o", ($ctlesc2codepoint{$+{w}} // oops))
Branch: 1 branch
BranchTrueFalseTotal
$+{'digitnext'} ? : 0 0 0
Condition0%0/6
$ctlesc2codepoint{$+{"w"}} // &oops()
l!l&&r!l&&!r
000
$ctlesc2codepoint{$+{"w"}} // &oops()
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctlesc2codepoint{$+{"w"}} // &oops()
$ctlesc2codepoint{$+{"w"}} &oops()
MC/DC0%0/2
$ctlesc2codepoint{$+{"w"}} // &oops()
$ctlesc2codepoint{$+{"w"}} &oops()
Truth table0%0/3
A // B
A= $ctlesc2codepoint{$+{"w"}}B= &oops()
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $ctlesc2codepoint{$+{"w"}}B= &oops()
ABresult
1X1
011
000
1469 }xesg;
1470 }
1471 }
1472  
1473 1653 ▶sub __change_quotechars($$$) { # edits $_
Subroutine __change_quotechars: called CC=5 SCAR=17.0
1474 1653 ▶ if (s/^"//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^"//u) 1653 0 1653
1475 1653 ▶ oops unless s/"$//;
Branch: 1 branch
BranchTrueFalseTotal
unless s/"$//u 0 1653 1653
1476 1653 my ($pfx, $l, $r) = @_;
1477 1653 s/\\"/"/g;
1478 1653 ▶ s/([\Q$l\E])/\\$1/g if length($l)==1; # assume traditional qqLR
Branch: 1 branch
BranchTrueFalseTotal
if length $l == 1 1653 0 1653
1479 1653 ▶ s/([\Q$r\E])/\\$1/g if length($r)==1; # with single-character brackets
Branch: 1 branch
BranchTrueFalseTotal
if length $r == 1 1653 0 1653
1480 1653 $_ = $pfx.$l.$_.$r;
1481 }
1482 }
1483  
1484 15 my %qqesc2controlpic = (
1485 15 ▶ '\0' => "\N{SYMBOL FOR NULL}", # occurs if next char is not a digit
Subroutine BEGIN: called CC=1 SCAR=0.0
1486 '\000' => "\N{SYMBOL FOR NULL}", # occurs if next char is a digit
1487 '\a' => "\N{SYMBOL FOR BELL}",
1488 '\b' => "\N{SYMBOL FOR BACKSPACE}",
1489 '\e' => "\N{SYMBOL FOR ESCAPE}",
1490 '\f' => "\N{SYMBOL FOR FORM FEED}",
1491 '\n' => "\N{SYMBOL FOR NEWLINE}",
1492 '\r' => "\N{SYMBOL FOR CARRIAGE RETURN}",
1493 '\t' => "\N{SYMBOL FOR HORIZONTAL TABULATION}",
1494 );
1495 my %char2controlpic = (
1496 map{
1497 15 my $cp = $qqesc2controlpic{$_};
1498 135 ▶ my $char = eval(qq("$_")) // die;
Condition50%1/2
eval qq["$_"] // die()
l!l
1350
MC/DC0%0/1
eval qq["$_"] // die()
eval qq["$_"]
Truth table50%1/2
A
A= eval qq["$_"]
Aresult
11
00
1499 135 ▶ die "XX<<$_>> YY<<$char>>" unless length($char) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless length $char == 1 0 135 135
1500 135 ($char => $cp)
1501 } keys %qqesc2controlpic
1502 );
1503 551 ▶sub __subst_controlpic_backesc() { # edits $_
Subroutine __subst_controlpic_backesc: called CC=3 SCAR=12.5
1504 # Replace '\t' '\n' etc. escapes with "control picture" characters
1505 551 ▶ return unless/^"/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^"/u 0 551 551
1506 551 s{ \G (?: [^\\]++ | \\[^0abefnrt] )*+ \K
1507 ( \\[abefnrt] | \\0(?![0-7]) | \\[0-3][0-7][0-7] )
1508 }{
1509 1623 ▶ $qqesc2controlpic{$1} // $1
Condition33%1/3
$qqesc2controlpic{$1} // $1
l!l&&r!l&&!r
162300
MC/DC0%0/2
$qqesc2controlpic{$1} // $1
$qqesc2controlpic{$1} $1
Truth table33%1/3
A // B
A= $qqesc2controlpic{$1}B= $1
ABresult
1X1
011
000
1510 }xesg;
1511 }
1512 0 ▶sub __subst_visiblespaces() { # edits $_
Subroutine __subst_visiblespaces: not called CC=2 SCAR=17.9
1513 0 ▶ if (/^"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^"/u) 0 0 0
1514 #s{\N{MIDDLE DOT}}{\N{BLACK LARGE CIRCLE}}g;
1515 #s{ }{\N{MIDDLE DOT}}g;
1516 0 s{ }{\N{OPEN BOX}}g; # ␣
1517 }
1518 }
1519  
1520 236 ▶sub __condense_strings($) { # edits $_
Subroutine __condense_strings: called CC=2 SCAR=6.9
1521 236 ▶ if (/^"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^"/u) 204 32 236
1522 204 my $minrep_m1 = $_[0] - 1;
1523 204 my $singlechar_restr = "[^\\\\${COND_LB}${COND_RB}${COND_MULT}]";
1524  
1525 # Special case a string of nul represented as \n\n\n...\00n (n=0..7)
1526 # D::D generates this to avoid ambiguity if a digit follows
1527 204 s<( (\\([0-7])){$minrep_m1,}\\00\g{-1} )>
1528 4 < $COND_LB."${2}${COND_MULT}".((length($1)-2)/length($2)).$COND_RB >xge;
1529  
1530 # \0 \1 ... if there is no digit following, which makes it ambiguous
1531 204 s<( (\\\d) \g{-1}{$minrep_m1,} ) (?![0-7]) >
1532 8 < $COND_LB."${2}${COND_MULT}".(length($1)/length($2)).$COND_RB >xge;
1533  
1534 # \x for almost any x besides a digit or \
1535 204 s<( ($singlechar_restr | \\\D | \\[0-3][0-7][0-7] | \\x\{[^\{\}]+\})
1536 \g{-1}{$minrep_m1,} )
1537 >
1538 174 < $COND_LB."${2}${COND_MULT}".(length($1)/length($2)).$COND_RB >xge;
1539 }
1540 }
1541  
1542 0 ▶sub __nums_in_hex() {
Subroutine __nums_in_hex: not called CC=2 SCAR=17.9
1543 0 ▶ if (looks_like_number($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($_)) 0 0 0
1544 0 s/^([1-9]\d+)$/ sprintf("%#x", $1) /e; # Leave single-digit numbers as-is
1545 }
1546 }
1547 108 ▶sub __nums_with_underscores() {
Subroutine __nums_with_underscores: called CC=3 SCAR=11.1
1548 108 ▶ if (looks_like_number($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($_)) 108 0 108
1549 108 ▶ while( s/^([^\._]*?\d)(\d\d\d)(?=$|\.|_)/$1_$2/ ) { }
Branch: 1 branch
BranchTrueFalseTotal
if (s/^([^\._]*?\d)(\d\d\d)(?=$|\.|_)/$1_$2/u) 162 108 270
1550 }
1551 }
1552  
1553 15 my $indent_unit;
1554  
1555 0 ▶sub _mycallloc(;@) {
Subroutine _mycallloc: not called CC=2 SCAR=17.9
1556 0 my ($lno, $subcalled) = (caller(1))[2,3];
1557 0 ▶ ":".$lno.(@_ ? _dbavis(@_) : "")." "
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
1558 }
1559  
1560 15 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
1561 15 _WRAP_ALWAYS => 1,
1562 _WRAP_ALLHASH => 2,
1563 15 };
1564 15 ▶use constant _WRAP_STYLE => (_WRAP_ALLHASH);
Subroutine BEGIN: called CC=1 SCAR=0.0
1565  
1566 9604 ▶sub _get_useqq_set_widechars {
Subroutine _get_useqq_set_widechars: called CC=6 SCAR=18.0
1567 9604 my ($self) = @_;
1568 9604 my $useqq = $self->Useqq();
1569 9604 my $unesc_unicode;
1570 9604 ▶ if ($useqq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($useqq) 9356 248 9604
1571  
1572 9356 ▶ carp "WARNING: The Useqq specification string ",_dbvis($useqq)," contains a non-ASCII character but 'use utf8;' was not in effect when the literal was compiled; the intended chracter was probably not used.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $useqq =~ /[^\x{0}-\x{7F}]/u and not utf8::is_utf8($useqq) 0 9356 9356
Condition33%1/3
$useqq =~ /[^\x{0}-\x{7F}]/u and not utf8::is_utf8($useqq)
!ll&&!rl&&r
935600
MC/DC0%0/2
$useqq =~ /[^\x{0}-\x{7F}]/u and not utf8::is_utf8($useqq)
$useqq =~ /[^\x{0}-\x{7F}]/u not utf8::is_utf8($useqq)
Truth table33%1/3
A and not(B)
A= $useqq =~ /[^\x{0}-\x{7F}]/uB= not utf8::is_utf8($useqq)
ABresult
0X0
100
111
1573 if $useqq =~ /[^\x{0}-\x{7F}]/ && !utf8::is_utf8($useqq);
1574  
1575 9356 my $unesc_unicode = $useqq =~ /utf|unic/;
1576 9356 ▶ if ($unesc_unicode && _utfoutput()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unesc_unicode and &_utfoutput()) { } 7085 2271 9356
Condition100%3/3
$unesc_unicode and &_utfoutput()
!ll&&!rl&&r
14308417085
MC/DC100%2/2
$unesc_unicode and &_utfoutput()
$unesc_unicode &_utfoutput()
Truth table100%3/3
A and B
A= $unesc_unicodeB= &_utfoutput()
ABresult
0X0
100
111
1577 # STDOUT is using a UTF encoding -- wide characters should be safe
1578 7085 $COND_LB = "\N{LEFT DOUBLE PARENTHESIS}"; # left bracket for 'condense' form
1579 7085 $COND_RB = "\N{RIGHT DOUBLE PARENTHESIS}";
1580 7085 $COND_MULT = "\N{MULTIPLICATION SIGN}";
1581 7085 $LQ = "«";
1582 7085 $RQ = "»";
1583 } else {
1584 2271 $COND_LB = "(";
1585 2271 $COND_RB = ")";
1586 2271 $COND_MULT = "x";
1587 2271 $LQ = "<<";
1588 2271 $RQ = ">>";
1589 }
1590 }
1591 9604 return $useqq;
1592 }
1593  
1594 8147 ▶sub _postprocess_DD_result {
Subroutine _postprocess_DD_result: called CC=59 SCAR=44.5
1595 8147 (my $self, local $_, my $original) = @_;
1596 15 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
1597 my ($debug, $listform, $foldwidth, $foldwidth1)
1598 8147 = @$self{qw/Debug _Listform Foldwidth Foldwidth1/};
1599 8147 my $useqq = $self->_get_useqq_set_widechars();
1600  
1601 8147 my ($unesc_unicode,$condense_strings,$octet_strings,$nums_in_hex,
1602 $controlpics,$showspaces,$underscores,$q_pfx,$q_lq,$q_rq);
1603 8147 ▶ if ($useqq && $useqq ne "1") {
Branch: 1 branch
BranchTrueFalseTotal
if ($useqq and $useqq ne 1) 7274 873 8147
Condition100%3/3
$useqq and $useqq ne 1
!ll&&!rl&&r
1926817274
MC/DC100%2/2
$useqq and $useqq ne 1
$useqq $useqq ne 1
Truth table100%3/3
A and B
A= $useqqB= $useqq ne 1
ABresult
0X0
100
111
1604 7274 my @useqq = split /(?<!\\):/, $useqq;
1605 7274 foreach (@useqq) {
1606 9065 ▶ $unesc_unicode = 1,next if /utf|unic/;
Branch: 1 branch
BranchTrueFalseTotal
if /utf|unic/u 6525 2540 9065
1607 2540 ▶ $condense_strings = 1,next if /cond/;
Branch: 1 branch
BranchTrueFalseTotal
if /cond/u 228 2312 2540
1608 2312 ▶ $octet_strings = 1,next if /octet/;
Branch: 1 branch
BranchTrueFalseTotal
if /octet/u 0 2312 2312
1609 2312 ▶ $nums_in_hex = 1,next if /hex/;
Branch: 1 branch
BranchTrueFalseTotal
if /hex/u 0 2312 2312
1610 2312 ▶ $controlpics = 1,next if /pic/;
Branch: 1 branch
BranchTrueFalseTotal
if /pic/u 551 1761 2312
1611 1761 ▶ $showspaces = 1,next if /space/;
Branch: 1 branch
BranchTrueFalseTotal
if /space/u 0 1761 1761
1612 1761 ▶ $underscores = 1,next if /under/;
Branch: 1 branch
BranchTrueFalseTotal
if /under/u 108 1653 1761
1613 1653 ▶ $_ = "qq={}" if $_ eq "qq"; # deprecated
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "qq" 1102 551 1653
1614 1653 ▶ if (/^qq=(.)(.)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^qq=(.)(.)$/u) 1653 0 1653
1615 1653 $q_pfx = "qq"; $q_lq = $1; $q_rq = $2;
1616 next
1617 1653 }
1618 0 ▶ next if $_ eq ""; # null specifier
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 0 0
1619 0 ▶ if (/style=((?:[^:,]+|\\.)+),((?:[^:]|\\.)+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/style=((?:[^:,]+|\\.)+),((?:[^:]|\\.)+)/u) 0 0 0
1620 0 $q_pfx = ""; $q_lq = $1; $q_rq = $2;
1621 0 $q_lq =~ s/\\(.)/$1/g; $q_rq =~ s/\\(.)/$1/g;
1622 next
1623 0 }
1624 0 oops "Invalid ",_dbvis($_)," in Useqq specifier ",_dbvis($useqq),"\n";
1625 }
1626 }
1627  
1628 8147 ▶ my $pad = $self->Pad() // "";
Condition50%1/2
$self->Pad // ""
l!l
81470
MC/DC0%0/1
$self->Pad // ""
$self->Pad
Truth table50%1/2
A
A= $self->Pad
Aresult
11
00
1629  
1630 8147 $indent_unit = 2; # make configurable?
1631  
1632 8147 ▶ my $maxlinelen = $foldwidth1 || $foldwidth || INT_MAX;
Condition100%5/5
$foldwidth1 || $foldwidth || 2147483647
l!l
7883264
$foldwidth1 or $foldwidth
l!l&&r!l&&!r
23755508264
MC/DC100%2/2
$foldwidth1 || $foldwidth || 2147483647
$foldwidth1 $foldwidth
Truth table100%3/3
A or B
A= $foldwidth1B= $foldwidth
ABresult
1X1
011
000
1633 8147 ▶ my $maxlineNlen = ($foldwidth // INT_MAX) - length($pad);
Condition50%1/2
$foldwidth // 2147483647
l!l
81470
MC/DC0%0/1
$foldwidth // 2147483647
$foldwidth
Truth table50%1/2
A
A= $foldwidth
Aresult
11
00
1634  
1635 8147 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 8147 8147
1636 0 our $_dbmaxlen = INT_MAX;
1637 0 btw "## DD result: fw1=",u($foldwidth1)," fw=",u($foldwidth)," pad='${pad}' maxll=$maxlinelen maxlNl=$maxlineNlen\n result=",_dbrawstr($_);
1638 }
1639  
1640 8147 my $top = { tlen => 0, children => [] };
1641 8147 my $context = $top;
1642 8147 my $prepending = "";
1643  
1644 21354 ▶ my sub atom($;$) {
Subroutine atom: called CC=25 SCAR=32.7
1645 21354 (local $_, my $mode) = @_;
1646 21354 ▶ $mode //= "";
Condition100%2/2
$mode //= ""
l!l
679014564
MC/DC100%1/1
$mode //= ""
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
1647  
1648 21354 __unmagic_atom ;
1649 21354 ▶ __unesc_unicode if $unesc_unicode;
Branch: 1 branch
BranchTrueFalseTotal
if $unesc_unicode 17322 4032 21354
1650 21354 ▶ __unesc_nonoctal if $octet_strings;
Branch: 1 branch
BranchTrueFalseTotal
if $octet_strings 0 21354 21354
1651 21354 ▶ __subst_controlpic_backesc if $controlpics;
Branch: 1 branch
BranchTrueFalseTotal
if $controlpics 551 20803 21354
1652 21354 ▶ __subst_visiblespaces if $showspaces;
Branch: 1 branch
BranchTrueFalseTotal
if $showspaces 0 21354 21354
1653 21354 ▶ __condense_strings(8) if $condense_strings;
Branch: 1 branch
BranchTrueFalseTotal
if $condense_strings 236 21118 21354
1654 21354 ▶ __change_quotechars($q_pfx, $q_lq, $q_rq) if defined($q_pfx);
Branch: 1 branch
BranchTrueFalseTotal
if defined $q_pfx 1653 19701 21354
1655 21354 ▶ __nums_in_hex if $nums_in_hex;
Branch: 1 branch
BranchTrueFalseTotal
if $nums_in_hex 0 21354 21354
1656 21354 ▶ __nums_with_underscores if $underscores;
Branch: 1 branch
BranchTrueFalseTotal
if $underscores 108 21246 21354
1657  
1658 21354 ▶ if ($prepending) { $_ = $prepending . $_; $prepending = ""; }
Branch: 1 branch
BranchTrueFalseTotal
if ($prepending) 799 20555 21354
1659  
1660 btwN 1,"###atom",_mycallloc(), _dbrawstr($_),"($mode)"
1661 0 ▶ ,"\n context:",_dbvisnew($context)->Sortkeys(sub{[grep{exists $_[0]->{$_}} qw/O C tlen children CLOSE_AFTER_NEXT/]})->Dump()
Subroutine __ANON__: not called CC=1 SCAR=2.0
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 21354 21354
1662 if $debug;
1663 21354 ▶ if ($mode eq "prepend_to_next") {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'prepend_to_next') { } 799 20555 21354
1664 799 $prepending .= $_;
1665 } else {
1666 20555 ▶ if ($mode eq "") {
Branch: 4 branches
BranchTrueFalseTotal
if ($mode eq '') { } 14564 5991 20555
elsif ($mode eq 'open') { } 1349 4642 5991
elsif ($mode eq 'close') { } 1349 3293 4642
elsif ($mode eq 'append_to_prev') { } 3293 0 3293
1667 14564 push @{ $context->{children} }, $_;
1668 }
1669 elsif ($mode eq "open") {
1670 1349 my $child = {
1671 O => $_,
1672 tlen => 0, # incremented below
1673 children => [],
1674 C => undef,
1675 parent => $context,
1676 };
1677 1349 weaken( $child->{parent} );
1678 1349 push @{ $context->{children} }, $child;
1679 1349 $context = $child;
1680 }
1681 elsif ($mode eq "close") {
1682 1349 ▶ oops if defined($context->{C});
Branch: 1 branch
BranchTrueFalseTotal
if defined $context->{"C"} 0 1349 1349
1683 1349 $context->{C} = $_;
1684 1349 $context->{tlen} += length;
1685 1349 $context = $context->{parent}; # undef if closing the top item
1686 }
1687 elsif ($mode eq "append_to_prev") {
1688 3293 my $prev = $context;
1689 { #block for 'redo'
1690 3293 ▶ oops "No previous!" unless @{$prev->{children}} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$prev->{"children"};} > 0 0 4412 4412
1691 4412 ▶ if (ref($prev->{children}->[-1] // oops)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($prev->{'children'}[-1] // &oops())) { } 1657 2755 4412
Condition33%1/3
$prev->{"children"}[-1] // &oops()
l!l&&r!l&&!r
441200
MC/DC0%0/2
$prev->{"children"}[-1] // &oops()
$prev->{"children"}[-1] &oops()
Truth table33%1/3
A // B
A= $prev->{"children"}[-1]B= &oops()
ABresult
1X1
011
000
1692 1657 $prev = $prev->{children}->[-1];
1693 1657 ▶ if (! $prev->{C}) { # empty or not-yet-read closer?
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev->{"C"}) 1119 538 1657
1694 1119 redo; # ***
1695 }
1696 538 $prev->{C} .= $_;
1697 } else {
1698 2755 $prev->{children}->[-1] .= $_;
1699 }
1700 }
1701 }
1702 else {
1703 0 oops "mode=",_dbvis($mode);
1704 }
1705 20555 my $c = $context;
1706 20555 ▶ while(defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 48446 20555 69001
1707 48446 $c->{tlen} += length($_);
1708 48446 $c = $c->{parent};
1709 }
1710 20555 ▶ if ($context->{CLOSE_AFTER_NEXT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"CLOSE_AFTER_NEXT"}) 1632 18923 20555
1711 1632 ▶ oops(_dbvis($context)) if defined($context->{C});
Branch: 1 branch
BranchTrueFalseTotal
if defined $context->{"C"} 0 1632 1632
1712 1632 $context->{C} = "";
1713 1632 $context = $context->{parent};
1714 }
1715 }
1716 }#atom
1717  
1718 1632 ▶ my sub fat_arrow($) { # =>
Subroutine fat_arrow: called CC=4 SCAR=14.5
1719 1632 ▶ my $lhs = $context->{children}->[-1] // oops;
Condition33%1/3
$context->{"children"}[-1] // &oops()
l!l&&r!l&&!r
163200
MC/DC0%0/2
$context->{"children"}[-1] // &oops()
$context->{"children"}[-1] &oops()
Truth table33%1/3
A // B
A= $context->{"children"}[-1]B= &oops()
ABresult
1X1
011
000
1720 1632 ▶ oops if ref($lhs);
Branch: 1 branch
BranchTrueFalseTotal
if ref $lhs 0 1632 1632
1721 1632 my $newchild = {
1722 O => "",
1723 tlen => length($lhs),
1724 children => [ $lhs ],
1725 C => undef,
1726 parent => $context,
1727 };
1728 1632 weaken($newchild->{parent});
1729 1632 $context->{children}->[-1] = $newchild;
1730 1632 $context = $newchild;
1731 1632 atom($_[0]); # the " => "
1732 1632 ▶ oops unless $context == $newchild;
Branch: 1 branch
BranchTrueFalseTotal
unless $context == $newchild 0 1632 1632
1733 1632 $context->{CLOSE_AFTER_NEXT} = 1;
1734 }
1735  
1736 # There is a trade-off between compactness (e.g. want a single line when
1737 # possible), and ease of reading large structures.
1738 #
1739 # At any nesting level, if everything (including any nested levels) fits
1740 # on a single line, then that part is output without folding;
1741 #
1742 # 4/25/2023: Now controlled by constant _WRAP_STYLE:
1743 #
1744 # (_WRAP_STYLE == _WRAP_ALWAYS):
1745 # If folding is necessary, then *every* member of the folded block
1746 # appears on a separate line, so members all vertically align.
1747 #
1748 # *(_WRAP_STYLE & _WRAP_ALLHASH): Members of a hash (key => value)
1749 # are shown on separate lines, but not members of an array.
1750 #
1751 # Otherwise:
1752 #
1753 # When folding is necessary, every member appears on a separate
1754 # line if ANY of them will not fit on a single line; however if
1755 # they all fit individually, then shorter members will be run
1756 # together on the same line. For example:
1757 #
1758 # [aaa,bbb,[ccc,ddd,[eee,fff,hhhhhhhhhhhhhhhhhhhhh,{key => value}]]]
1759 #
1760 # might be shown as
1761 # [ aaa,bbb, # N.B. space inserted before aaa to line up with next level
1762 # [ ccc,ddd, # packed because all siblings fit individually
1763 # [eee,fff,hhhhhhhhhhhhhhhhhhhhh,{key => value}] # entirely fits
1764 # ]
1765 # ]
1766 # but if Foldwidth is smaller then like this:
1767 # [ aaa,bbb,
1768 # [ ccc, # sibs vertically-aligned because not all of them fit
1769 # ddd,
1770 # [ eee,fff, # but within this level, all siblings fit
1771 # hhhhhhhhhhhhhhhhhhhhh,
1772 # {key => value}
1773 # ]
1774 # ]
1775 # ]
1776 # or if Foldwidth is very small then:
1777 # [ aaa,
1778 # bbb,
1779 # [ ccc,
1780 # ddd,
1781 # [ eee,
1782 # fff,
1783 # hhhhhhhhhhhhhhhhhhhhh,
1784 # { key
1785 # =>
1786 # value
1787 # }
1788 # ]
1789 # ]
1790 # ]
1791 #
1792 # Note: Indentation is done regardless of Foldwidth, so deeply nested
1793 # structures may extend beyond Foldwidth even if all elements are short.
1794  
1795 8147 my $outstr;
1796 my $linelen;
1797 8147 our $level;
1798 11128 ▶ my sub expand_children($) {
Subroutine expand_children: called CC=35 SCAR=35.9
1799 11128 my $parent = shift;
1800 # $level is already set appropriately for $parent->{children},
1801 # and the parent's {opener} is at the end of $outstr.
1802 #
1803 # Intially we are called with a fake parent ($top) containing
1804 # no {opener} and the top-most item as its only child, with $level==0;
1805 # this puts the top item at the left margin.
1806 #
1807 # If all children individually fit then run them all together,
1808 # wrapping only between siblings; otherwise start each sibling on
1809 # it's own line so they line up vertically.
1810 # [4/25/2023: Now controlled by _WRAP_STYLE]
1811  
1812 11128 my $available = $maxlinelen - $linelen;
1813 11128 my $indent_width = $level * $indent_unit;
1814  
1815 my $run_together =
1816 (_WRAP_STYLE & _WRAP_ALWAYS)==0
1817 &&
1818 11128 ▶ all{ (ref() ? $_->{tlen} : length) <= $available } @{$parent->{children}}
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2665 13668 16333
1819 ;
1820  
1821 11128 ▶ if (!$run_together
Branch: 1 branch
BranchTrueFalseTotal
if (not $run_together and @{$parent->{"children"};} == 3 and not ref(my $item = $parent->{"children"}[1])) 158 10970 11128
Condition83%5/6
not $run_together and @{$parent->{"children"};} == 3 and not ref(my $item = $parent->{"children"}[1])
!ll&&!rl&&r
109700158
not $run_together and @{$parent->{"children"};} == 3
!ll&&!rl&&r
68874083158
MC/DC66%2/3
not $run_together and @{$parent->{"children"};} == 3 and not ref(my $item = $parent->{"children"}[1])
not $run_together @{$parent->{"children"};} == 3 not ref(my $item = $parent->{"children"}[1])
Truth table75%3/4
not(A) and B and not(C)
A= not $run_togetherB= @{$parent->{"children"};} == 3C= not ref(my $item = $parent->{"children"}[1])
ABCresult
0XX0
10X0
1100
1111
1822 4241 && @{$parent->{children}}==3
1823 && !ref(my $item=$parent->{children}->[1])) {
1824 # Concatenate (key,=>) if possible
1825 158 ▶ if ($item =~ /\A *=> *\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /\A *=> *\z/u) 154 4 158
1826 154 $run_together = 1;
1827 154 ▶ btw "# (level $level): Running together $parent->{children}->[0] => value" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 154 154
1828 }
1829 }
1830  
1831 11128 my $indent = ' ' x $indent_width;
1832  
1833 btw "###expand",_mycallloc(), "level $level, avail=$available",
1834 " rt=",_tf($run_together),
1835 " indw=$indent_width ll=$linelen maxll=$maxlinelen : ",
1836 #"{ tlen=",$parent->{tlen}," }",
1837 0 ▶ " p=",_dbvisnew($parent)->Sortkeys(sub{[grep{exists $_[0]->{$_}} qw/O C tlen CLOSE_AFTER_NEXT/]})->Dump(),
Subroutine __ANON__: not called CC=1 SCAR=2.0
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 11128 11128
1838 "\n os=",_dbstr($outstr) if $debug;
1839  
1840 #oops(_dbavis($linelen,$indent_width)) unless $linelen >= $indent_width;
1841  
1842 11128 my $first = 1;
1843 11128 for my $child (@{$parent->{children}}) {
1844 17545 ▶ my $child_len = ref($child) ? $child->{tlen} : length($child);
Branch: 1 branch
BranchTrueFalseTotal
ref $child ? : 2981 14564 17545
1845 17545 ▶ my $fits = ($child_len <= $available) || 0;
Condition100%2/2
$child_len <= $available || 0
l!l
125375008
MC/DC100%1/1
$child_len <= $available || 0
$child_len <= $available
Truth table100%2/2
A
A= $child_len <= $available
Aresult
11
00
1846  
1847 17545 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 10921 6624 17545
1848 } else {
1849 6624 ▶ if(!$fits && !ref($child)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fits or ref $child) 718 5906 6624
Condition100%3/3
$fits or ref $child
l!l&&r!l&&!r
5608298718
MC/DC100%2/2
$fits or ref $child
$fits ref $child
Truth table100%3/3
A or B
A= $fitsB= ref $child
ABresult
1X1
011
000
1850 718 ▶ if ($child =~ /( +)\z/ && ($child_len-length($1)) <= $available) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child =~ /( +)\z/u and $child_len - length($1) <= $available) 2 716 718
Condition100%3/3
$child =~ /( +)\z/u and $child_len - length($1) <= $available
!ll&&!rl&&r
5661502
MC/DC100%2/2
$child =~ /( +)\z/u and $child_len - length($1) <= $available
$child =~ /( +)\z/u $child_len - length($1) <= $available
Truth table100%3/3
A and B
A= $child =~ /( +)\z/uB= $child_len - length($1) <= $available
ABresult
0X0
100
111
1851 # remove trailing space(s) e.g. in ' => '
1852 2 substr($child,-length($1),INT_MAX,"");
1853 2 $child_len -= length($1);
1854 2 ▶ oops unless $child_len <= $available;
Branch: 1 branch
BranchTrueFalseTotal
unless $child_len <= $available 0 2 2
1855 2 $fits = 2;
1856 2 ▶ btw "# (level $level): Chopped ",_dbstr($1)," from child" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
1857 }
1858 718 ▶ if (!$fits && $linelen <= $indent_width && $run_together) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fits and $linelen <= $indent_width and $run_together) 18 700 718
Condition83%5/6
not $fits and $linelen <= $indent_width and $run_together
!ll&&!rl&&r
700018
not $fits and $linelen <= $indent_width
!ll&&!rl&&r
269818
MC/DC66%2/3
not $fits and $linelen <= $indent_width and $run_together
not $fits $linelen <= $indent_width $run_together
Truth table75%3/4
not(A) and B and C
A= not $fitsB= $linelen <= $indent_widthC= $run_together
ABCresult
0XX0
10X0
1100
1111
1859 # If we wrap we'll end up at the same or worse position after
1860 # indenting, so don't bother wrapping if running together
1861 18 $fits = 3;
1862 18 ▶ btw "# (level $level): Wrap would not help" if $debug
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 18 18
1863 }
1864 }
1865 6624 ▶ if (!$fits || !$run_together) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fits && $run_together) { } 2155 4469 6624
Condition100%3/3
$fits && $run_together
!ll&&!rl&&r
99611594469
MC/DC100%2/2
$fits && $run_together
$fits $run_together
Truth table100%3/3
A && B
A= $fitsB= $run_together
ABresult
0X0
100
111
1866 # start a second+ line
1867 2155 $outstr =~ s/ +\z//;
1868 2155 $outstr .= "\n$indent";
1869 2155 $linelen = $indent_width;
1870 2155 $maxlinelen = $maxlineNlen;
1871  
1872 # elide any initial spaces after wrapping, e.g. in " => "
1873 2155 ▶ $child =~ s/^ +// unless ref($child);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $child 939 1216 2155
1874  
1875 2155 $available = $maxlinelen - $linelen;
1876 2155 ▶ $child_len = ref($child) ? $child->{tlen} : length($child);
Branch: 1 branch
BranchTrueFalseTotal
ref $child ? : 1216 939 2155
1877 2155 $fits = ($child_len <= $available);
1878 2155 ▶ btw "# (level $level): 2nd+ Pre-WRAP; ",_dbstr($child)," cl=$child_len av=$available ll=$linelen f=$fits rt=",_tf($run_together)," os=",_dbstr($outstr) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2155 2155
1879 } else {
1880 4469 ▶ btw "# (level $level): (no 2nd+ pre-wrap); ",_dbstr($child)," cl=$child_len av=$available ll=$linelen f=$fits rt=",_tf($run_together) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4469 4469
1881 }
1882 }
1883  
1884 17545 ▶ if (ref($child)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $child) { } 2981 14564 17545
1885 2981 ++$level;
1886 2981 $outstr .= $child->{O};
1887 2981 $linelen += length($child->{O});
1888 2981 ▶ if (! $fits && $child->{O} ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fits and $child->{"O"} ne "") 343 2638 2981
Condition100%3/3
not $fits and $child->{"O"} ne ""
!ll&&!rl&&r
2474164343
MC/DC100%2/2
not $fits and $child->{"O"} ne ""
not $fits $child->{"O"} ne ""
Truth table100%3/3
not(A) and B
A= not $fitsB= $child->{"O"} ne ""
ABresult
0X0
100
111
1889 # Wrap before first child, if there is a real opener (not for '=>')
1890 343 $outstr =~ s/ +\z//;
1891 343 $outstr .= "\n$indent" . (' ' x $indent_unit);
1892 343 $linelen = $indent_width + $indent_unit;
1893 343 $maxlinelen = $maxlineNlen;
1894 343 ▶ btw "# (l $level): Wrap after opener: os=",_dbstr($outstr) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 343 343
1895 }
1896 2981 __SUB__->($child);
1897 2981 ▶ if (! $fits && $child->{O} ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fits and $child->{"O"} ne "") 343 2638 2981
Condition100%3/3
not $fits and $child->{"O"} ne ""
!ll&&!rl&&r
2474164343
MC/DC100%2/2
not $fits and $child->{"O"} ne ""
not $fits $child->{"O"} ne ""
Truth table100%3/3
not(A) and B
A= not $fitsB= $child->{"O"} ne ""
ABresult
0X0
100
111
1898 # Wrap before closer if we wrapped after opener
1899 343 $outstr =~ s/ +\z//;
1900 343 $outstr .= "\n$indent";
1901 343 $linelen = $indent_width;
1902 343 $maxlinelen = $maxlineNlen;
1903 343 ▶ btw "# (l $level): Wrap after closer; ll=$linelen os=",_dbstr($outstr) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 343 343
1904 }
1905 2981 $outstr .= $child->{C};
1906 2981 $linelen += length($child->{C});
1907 2981 --$level;
1908 } else {
1909 14564 $outstr .= $child;
1910 14564 $linelen += length($child);
1911 14564 ▶ btw "# (level $level): appended SCALAR ",_dbstr($child)," os=",_dbstr($outstr) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 14564 14564
1912 }
1913 17545 $available = $maxlinelen - $linelen;
1914 17545 $first = 0;
1915 }
1916 }#expand_children
1917  
1918 # Remove the [array wrapper] used to prepend a string to the
1919 # representation of a ref, e.g. as created by _prefix_refaddr().
1920 #
1921 # The original $ref was replaced by
1922 #
1923 # [ _MAGIC_REFPFX."prefix", $ref, _MAGIC_ELIDE_NEXT ];
1924 #
1925 # Whieh Data::Dumper formatted as
1926 #
1927 # ["_MAGIC_REFPFXprefix", <representation of $ref> "_MAGIC_ELIDE_NEXT"]
1928 #
1929 # and we want to end up with
1930 #
1931 # prefix<representation of $ref> e.g. <984:ef8>[42,77]
1932 #
1933 8147 s/\[\s*(["'])\Q${\_MAGIC_REFPFX}\E(.*?)\1,\s*/$2/gs;
1934 8147 ▶ s/,\s*(["'])\Q${\_MAGIC_ELIDE_NEXT}\E\1,?\s*\]//gs
Branch: 1 branch
BranchTrueFalseTotal
s/,\s*(["'])\Q${\"|ENMagic77408|";}\E\1,?\s*\]//gsu and $debug and &btw("Unwrapped REFPFX ", &_dbvis($_)) 0 8147 8147
Condition66%2/3
s/,\s*(["'])\Q${\"|ENMagic77408|";}\E\1,?\s*\]//gsu and $debug
!ll&&!rl&&r
8116310
MC/DC0%0/2
s/,\s*(["'])\Q${\"|ENMagic77408|";}\E\1,?\s*\]//gsu and $debug
s/,\s*(["'])\Q${\"|ENMagic77408|";}\E\1,?\s*\]//gsu $debug
Truth table66%2/3
A and B
A= s/,\s*(["'])\Q${\"|ENMagic77408|";}\E\1,?\s*\]//gsuB= $debug
ABresult
0X0
100
111
1935 && $debug && btw "Unwrapped REFPFX ",_dbvis($_);
1936  
1937 8147 ▶ while ((pos()//0) < length) {
Branch: 1 branch
BranchTrueFalseTotal
if ((pos $_ // 0) < length $_) 21507 8147 29654
Condition100%2/2
pos $_ // 0
l!l
215078147
MC/DC100%1/1
pos $_ // 0
pos $_
Truth table100%2/2
A
A= pos $_
Aresult
11
00
1938 21507 ▶ if (/\G[\\\*\!]/gc) { atom($&, "prepend_to_next") }
Branch: 16 branches
BranchTrueFalseTotal
if (/\G[\\\*\!]/cgu) { } 761 20746 21507
elsif (/\G[,;]/cgu) { } 3293 17453 20746
elsif (/\G"(?:[^"\\]++|\\.)*+"/cgsu) { } 10722 6731 17453
elsif (/\G'(?:[^'\\]++|\\.)*+'/cgsu) { } 279 6452 6731
elsif (m[\Gqr/(?:[^\\\/]++|\\.)*+/[a-z]*]cgsu) { } 138 6314 6452
elsif (/\G$addrvis_re/cgsu) { } 38 6276 6314
elsif (/\Gsub\s*(?:$Data::Dumper::Interp::parens_re\s*)?$Data::Dumper::Interp::curlies_re/cgu) { } 4 6272 6276
elsif (/\G(?:my\s+)?\$(?:$userident_re|\s*->\s*|$balanced_re+)++/cgsu) { } 85 6187 6272
elsif (/\G\b[A-Za-z_][A-Za-z0-9_]*+\b/cgu) { } 1525 4662 6187
elsif (/\G-?\d[\deE\.]*+\b/cgu) { } 169 4493 4662
elsif (/\G\s*=>\s*/cgu) { } 1632 2861 4493
elsif (/\G\s*=(?=[\w\s'"])\s*/cgu) { } 2 2859 2861
elsif (/\G:*$pkgname_re/cgu) { } 8 2851 2859
elsif (/\G[\[\{\(]/cgu) { } 1349 1502 2851
elsif (/\G[\]\}\)]/cgu) { } 1349 153 1502
elsif (/\G\s+/cgsu) { } 153 0 153
1939 3293 elsif (/\G[,;]/gc) { atom($&, "append_to_prev") }
1940 10722 elsif (/\G"(?:[^"\\]++|\\.)*+"/gsc) { atom($&) } # "quoted"
1941 279 elsif (/\G'(?:[^'\\]++|\\.)*+'/gsc) { atom($&) } # 'quoted'
1942 elsif (m(\Gqr/(?:[^\\\/]++|\\.)*+/[a-z]*)gsc){ # Regexp
1943 138 local $_ = $&;
1944 # Data::Dumper just stringifies a compiled regex, and Perl (v5.34)
1945 # does not stringify actual tab as \t etc. probably because the result
1946 # would be ambiguous if preceeded by another backslash, e.g.
1947 # \<tab> -> \\t would be wrong (backslash character + 't').
1948 #
1949 # If 'controlpics' is enabled, they are always substituted and then
1950 # a preceding backslash is not a problem; otherwise \-escapes are
1951 # substituted only if not preceded by another backslash.
1952 138 ▶ if ($controlpics) {
Branch: 1 branch
BranchTrueFalseTotal
if ($controlpics) { } 0 138 138
1953 0 ▶ s{([\x{0}\a\b\e\f\n\r\t])}{ $char2controlpic{$1} // $1 }esg;
Condition0%0/3
$char2controlpic{$1} // $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$char2controlpic{$1} // $1
$char2controlpic{$1} $1
Truth table0%0/3
A // B
A= $char2controlpic{$1}B= $1
ABresult
1X1
011
000
1954 } else {
1955 138 ▶ if (/[\x{0}\a\b\e\f\n\r\t]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/[\x{0}\a\b\e\f\n\r\t]/u) 0 138 138
1956 0 s/(?<!\\)\x{0}/\\0/g;
1957 0 s/(?<!\\)[\b]/\N{SYMBOL FOR BACKSPACE}/; # Bare \b matches boundaries
1958 0 s/(?<!\\)\e/\\e/g;
1959 0 s/(?<!\\)\f/\\f/g;
1960 0 s/(?<!\\)\x{0A}/\\n/g;
1961 0 s/(?<!\\)\x{0D}/\\r/g;
1962 0 s/(?<!\\)\t/\\t/g;
1963 }
1964 }
1965 138 atom($_)
1966 }
1967 38 elsif (/\G${addrvis_re}/gsc) { atom($&, "prepend_to_next") }
1968  
1969 # With Deparse(1) the body has arbitrary Perl code, which we can't parse
1970 4 elsif (/\Gsub\s*(?:${parens_re}\s*)?${curlies_re}/gc) { atom($&) } # sub{...}
1971  
1972 # $VAR1->[ix] $VAR1->{key} or just $varname
1973 85 elsif (/\G(?:my\s+)?\$(?:${userident_re}|\s*->\s*|${balanced_re}+)++/gsc) { atom($&) }
1974  
1975 1525 elsif (/\G\b[A-Za-z_][A-Za-z0-9_]*+\b/gc) { atom($&) } # bareword?
1976 169 elsif (/\G-?\d[\deE\.]*+\b/gc) { atom($&) } # number
1977 1632 elsif (/\G\s*=>\s*/gc) { fat_arrow($&) }
1978 2 elsif (/\G\s*=(?=[\w\s'"])\s*/gc) { atom($&) }
1979 8 elsif (/\G:*${pkgname_re}/gc) { atom($&) }
1980 1349 elsif (/\G[\[\{\(]/gc) { atom($&, "open") }
1981 1349 elsif (/\G[\]\}\)]/gc) { atom($&, "close") }
1982 elsif (/\G\s+/sgc) { }
1983 else {
1984 0 ▶ my $remnant = substr($_,pos//0);
Condition0%0/2
pos $_ // 0
l!l
00
MC/DC0%0/1
pos $_ // 0
pos $_
Truth table0%0/2
A
A= pos $_
Aresult
11
00
1985 0 ▶ Carp::cluck "UNPARSED at ${\_dbstrposn($_,pos()//0)}\n",
Condition0%0/2
pos $_ // 0
l!l
00
MC/DC0%0/1
pos $_ // 0
pos $_
Truth table0%0/2
A
A= pos $_
Aresult
11
00
1986 " (Using remainder as-is)\n",
1987 0 "FULL STRING: ${\_dbstr($_)}\n",
1988 0 "original: ${\_dbstr($original)}\n" ;
1989 0 atom($remnant);
1990 0 ▶ while (defined $context->{parent}) { atom("", "close"); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context->{"parent"}) 0 0 0
1991 0 last;
1992 }
1993 }
1994 8147 ▶ oops "Dangling prepend ",_dbstr($prepending) if $prepending;
Branch: 1 branch
BranchTrueFalseTotal
if $prepending 0 8147 8147
1995  
1996 0 ▶ btw "--------top-------\n",_dbvisnew($top)->Sortkeys(sub{[qw/O C tlen children/]})->Dump,"\n-----------------" if $debug;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 8147 8147
1997  
1998 8147 $outstr = "";
1999 8147 $linelen = 0;
2000 8147 $level = 0;
2001 8147 expand_children($top);
2002  
2003 8147 ▶ if (index($listform,'a') >= 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($listform, 'a') != -1) { } 269 7878 8147
elsif (index($listform, 'h') != -1) { } 105 7773 7878
elsif (index($listform, 'l') != -1) { } 93 7680 7773
2004 # show [...] as (val1,val2,...) array initializer
2005 # Remove any initial Addrvis prefix
2006 269 ▶ $outstr =~ s/\A(?:${addrvis_re})?\[/(/ && $outstr =~ s/\]\z/)/s or oops _dbvis($outstr);
Branch: 1 branch
BranchTrueFalseTotal
$outstr =~ s/\A(?:$addrvis_re)?\[/(/u and $outstr =~ s/\]\z/)/su or &oops(&_dbvis($outstr)) 269 0 269
Condition33%1/3
$outstr =~ s/\A(?:$addrvis_re)?\[/(/u and $outstr =~ s/\]\z/)/su
!ll&&!rl&&r
00269
MC/DC0%0/2
$outstr =~ s/\A(?:$addrvis_re)?\[/(/u and $outstr =~ s/\]\z/)/su
$outstr =~ s/\A(?:$addrvis_re)?\[/(/u $outstr =~ s/\]\z/)/su
Truth table33%1/3
A and B
A= $outstr =~ s/\A(?:$addrvis_re)?\[/(/uB= $outstr =~ s/\]\z/)/su
ABresult
0X0
100
111
2007 }
2008 elsif (index($listform,'h') >= 0) {
2009 # show {...} as (key => val, ...) hash initializer
2010 105 ▶ $outstr =~ s/\A(?:${addrvis_re})?\{/(/ && $outstr =~ s/\}\z/)/s or oops;
Branch: 1 branch
BranchTrueFalseTotal
$outstr =~ s/\A(?:$addrvis_re)?\{/(/u and $outstr =~ s/\}\z/)/su or &oops() 105 0 105
Condition33%1/3
$outstr =~ s/\A(?:$addrvis_re)?\{/(/u and $outstr =~ s/\}\z/)/su
!ll&&!rl&&r
00105
MC/DC0%0/2
$outstr =~ s/\A(?:$addrvis_re)?\{/(/u and $outstr =~ s/\}\z/)/su
$outstr =~ s/\A(?:$addrvis_re)?\{/(/u $outstr =~ s/\}\z/)/su
Truth table33%1/3
A and B
A= $outstr =~ s/\A(?:$addrvis_re)?\{/(/uB= $outstr =~ s/\}\z/)/su
ABresult
0X0
100
111
2011 }
2012 elsif (index($listform,'l') >= 0) {
2013 # show as a bare list without brackets; the brackets might be on own lines.
2014 93 ▶ $outstr =~ s/\A(?:${addrvis_re})?\[\s*(.*?)\s*\]\z/$1/s
Branch: 1 branch
BranchTrueFalseTotal
$outstr =~ s/\A(?:$addrvis_re)?\[\s*(.*?)\s*\]\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\{\s*(.*?)\s*\}\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\(\s*(.*?)\s*\)\z/$1/su or $outstr =~ s/\A$quoted_re\z/substr $&, 1, length($&) - 2;/esu 90 3 93
Condition83%5/6
$outstr =~ s/\A(?:$addrvis_re)?\[\s*(.*?)\s*\]\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\{\s*(.*?)\s*\}\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\(\s*(.*?)\s*\)\z/$1/su
l!l&&r!l&&!r
9003
$outstr =~ s/\A(?:$addrvis_re)?\[\s*(.*?)\s*\]\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\{\s*(.*?)\s*\}\z/$1/su
l!l&&r!l&&!r
54363
MC/DC66%2/3
$outstr =~ s/\A(?:$addrvis_re)?\[\s*(.*?)\s*\]\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\{\s*(.*?)\s*\}\z/$1/su or $outstr =~ s/\A(?:$addrvis_re)?\(\s*(.*?)\s*\)\z/$1/su
$outstr =~ s/\A(?:$addrvis_re)?\[\s*(.*?)\s*\]\z/$1/su $outstr =~ s/\A(?:$addrvis_re)?\{\s*(.*?)\s*\}\z/$1/su $outstr =~ s/\A(?:$addrvis_re)?\(\s*(.*?)\s*\)\z/$1/su
Truth table75%3/4
A or B or C
A= $outstr =~ s/\A(?:$addrvis_re)?\[\s*(.*?)\s*\]\z/$1/suB= $outstr =~ s/\A(?:$addrvis_re)?\{\s*(.*?)\s*\}\z/$1/suC= $outstr =~ s/\A(?:$addrvis_re)?\(\s*(.*?)\s*\)\z/$1/su
ABCresult
1XX1
01X1
0011
0000
2015 or
2016 $outstr =~ s/\A(?:${addrvis_re})?\{\s*(.*?)\s*\}\z/$1/s
2017 or
2018 $outstr =~ s/\A(?:${addrvis_re})?\(\s*(.*?)\s*\)\z/$1/s # from 'a' conversion above
2019 or
2020 3 $outstr =~ s/\A${quoted_re}\z/substr($&,1,length($&)-2)/es # a single string without "quote marks"
2021 ;
2022 }
2023  
2024 # Insert user-specified padding after each embedded newline
2025 8147 ▶ if ($pad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pad) 2 8145 8147
2026 2 $outstr =~ s/\n\K(?=[^\n])/$pad/g;
2027 }
2028  
2029 $outstr
2030 8147 } #_postprocess_DD_result {
2031  
2032 1460 ▶sub _Interpolate {
Subroutine _Interpolate: called CC=25 SCAR=33.0
2033 1460 my ($self, $input, $i_or_d) = @_;
2034 1460 ▶ _croak_or_confess $i_or_d."vis called in void context.\nDid you forget to 'say ...'?"
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 1460 1460
2035 unless defined wantarray;
2036  
2037 1460 ▶ return "<undef arg>" if ! defined $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 3 1457 1460
2038  
2039 1457 &_SaveAndResetPunct;
2040  
2041 1457 my $debug = $self->Debug;
2042 1457 my $useqq = $self->_get_useqq_set_widechars();
2043 #my $useqq = $self->Useqq(); ###TEMP FOR TEST DEBUG
2044  
2045 1457 ▶ my $q = $useqq ? "" : "q";
Branch: 1 branch
BranchTrueFalseTotal
$useqq ? : 1401 56 1457
2046 1457 my $funcname = $i_or_d . "vis" .$q;
2047  
2048 1457 my @pieces; # list of [visfuncname or 'p' or 'e', inputstring]
2049 1457 { local $_ = $input;
2050 1457 ▶ if (/\b((?:ARRAY|HASH|SCALAR)\(0x[a-fA-F0-9]+\))/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\b((?:ARRAY|HASH|SCALAR)\(0x[a-fA-F0-9]+\))/u) 0 1457 1457
2051 0 state $warned=0;
2052 0 ▶ carp("Warning: String passed to $funcname may have been interpolated by Perl\n(use 'single quotes' to avoid this)\n") unless $warned++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warned++ 0 0 0
2053 }
2054 1457 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (/\G ( # Stuff without variable references (might include \n etc. escapes) #This gets "recursion limit exceeded" #( (?: [^\\\$\@\%] | \\[^\$\@\%] )++ ) #| (?: [^\\\$\@\%]++ ) | #(?: (?: \\[^\$\@\%] )++ ) (?: (?: \\. )++ ) | # $#arrayvar $#$$...refvarname $#{aref expr} $#$$...{ref2ref expr} # (?: \$\#\$*+\K $anyvname_or_refexpr_re ) | # $scalarvar $$$...refvarname ${sref expr} $$$...{ref2ref expr} # followed by [] {} ->[] ->{} ->method() ... \302\253zero or more\302\273 # EXCEPT $$<punctchar> is parsed as $$ followed by <punctchar> (?: (?: \$\$++ $pkgname_re \K | \$ $anyvname_or_refexpr_re \K ) (?: (?: ->\K(?: $Data::Dumper::Interp::curliesorsquares_re|$userident_re$Data::Dumper::Interp::parens_re? )) | $Data::Dumper::Interp::curliesorsquares_re )* ) | # @arrayvar @$$...varname @{aref expr} @$$...{ref2ref expr} # followed by [] {} \302\253zero or one\302\273 # (?: \@\$*+\K $anyvname_or_refexpr_re ${$Data::Dumper::Interp::curliesorsquares_re;}? ) | # %hash %$hrefvar %{href expr} %$$...sref2hrefvar \302\253no follow-ons\302\273 (?: \%\$*+\K $anyvname_or_refexpr_re ) ) /cgsux) 4407 1457 5864
2055 /\G (
2056 # Stuff without variable references (might include \n etc. escapes)
2057  
2058 #This gets "recursion limit exceeded"
2059 #( (?: [^\\\$\@\%] | \\[^\$\@\%] )++ )
2060 #|
2061  
2062 (?: [^\\\$\@\%]++ )
2063 |
2064 #(?: (?: \\[^\$\@\%] )++ )
2065 (?: (?: \\. )++ )
2066 |
2067  
2068 # $#arrayvar $#$$...refvarname $#{aref expr} $#$$...{ref2ref expr}
2069 #
2070 (?: \$\#\$*+\K ${anyvname_or_refexpr_re} )
2071 |
2072  
2073 # $scalarvar $$$...refvarname ${sref expr} $$$...{ref2ref expr}
2074 # followed by [] {} ->[] ->{} ->method() ... «zero or more»
2075 # EXCEPT $$<punctchar> is parsed as $$ followed by <punctchar>
2076  
2077 (?:
2078 (?: \$\$++ ${pkgname_re} \K | \$ ${anyvname_or_refexpr_re} \K )
2079 (?:
2080 (?: ->\K(?: ${curliesorsquares_re}|${userident_re}${parens_re}? ))
2081 |
2082 ${curliesorsquares_re}
2083 )*
2084 )
2085 |
2086  
2087 # @arrayvar @$$...varname @{aref expr} @$$...{ref2ref expr}
2088 # followed by [] {} «zero or one»
2089 #
2090 5864 (?: \@\$*+\K ${anyvname_or_refexpr_re} ${$curliesorsquares_re}? )
2091 |
2092 # %hash %$hrefvar %{href expr} %$$...sref2hrefvar «no follow-ons»
2093 (?: \%\$*+\K ${anyvname_or_refexpr_re} )
2094 ) /xsgc)
2095 {
2096 4407 ▶ local $_ = $1; oops unless length() > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ > 0 0 4407 4407
2097 4407 ▶ if (/^[\$\@\%]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[\$\@\%]/u) { } 1951 2456 4407
2098 1951 my $sigl = substr($_,0,1);
2099 1951 ▶ if ($i_or_d eq 'd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_or_d eq "d") 1922 29 1951
2100 # Inject a "plain text" fragment containing the "expr=" prefix,
2101 # omitting the '$' sigl if the expr is a plain '$name'.
2102 1922 ▶ push @pieces, ['P', (/^\$(?!_)(${userident_re})\z/ ? $1 : $_)."="];
Branch: 1 branch
BranchTrueFalseTotal
/^\$(?!_)($userident_re)\z/u ? : 796 1126 1922
2103 }
2104 1951 ▶ if ($sigl eq '$') {
Branch: 3 branches
BranchTrueFalseTotal
if ($sigl eq '$') { } 1683 268 1951
elsif ($sigl eq '@') { } 203 65 268
elsif ($sigl eq '%') { } 65 0 65
2105 1683 push @pieces, ["vis", $_];
2106 }
2107 elsif ($sigl eq '@') {
2108 203 push @pieces, ["avis", $_];
2109 }
2110 elsif ($sigl eq '%') {
2111 65 push @pieces, ["hvis", $_];
2112 }
2113 0 else { oops }
2114 }
2115 else {
2116 2456 ▶ if (/^.+?(?<!\\)([\$\@\%])/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^.+?(?<!\\)([\$\@\%])/u) 0 2456 2456
2117 0 confess __PACKAGE__." bug: Missed '$1' in ${LQ}$_${RQ}"
2118 }
2119 # Due to the need to simplify the big regexp above, \x{abcd} is now
2120 # split into "\x" and "{abcd}". Combine consecutive pass-thrus
2121 # into a single passthru ('p'), converted later to 'e' if an eval
2122 # is needed.
2123 2456 ▶ if (@pieces && $pieces[-1]->[0] eq 'p') {
Branch: 1 branch
BranchTrueFalseTotal
if (@pieces and $pieces[-1][0] eq 'p') { } 107 2349 2456
Condition100%3/3
@pieces and $pieces[-1][0] eq "p"
!ll&&!rl&&r
7521597107
MC/DC100%2/2
@pieces and $pieces[-1][0] eq "p"
@pieces $pieces[-1][0] eq "p"
Truth table100%3/3
A and B
A= @piecesB= $pieces[-1][0] eq "p"
ABresult
0X0
100
111
2124 107 $pieces[-1]->[1] .= $_;
2125 } else {
2126 2349 push @pieces, [ 'p', $_ ];
2127 }
2128 }
2129 }
2130 1457 ▶ if (!defined(pos) || pos() < length($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined pos $_ or pos $_ < length $_) 1 1456 1457
Condition66%2/3
not defined pos $_ or pos $_ < length $_
l!l&&r!l&&!r
011456
MC/DC50%1/2
not defined pos $_ or pos $_ < length $_
not defined pos $_ pos $_ < length $_
Truth table66%2/3
not(A) or B
A= not defined pos $_B= pos $_ < length $_
ABresult
1X1
011
000
2131 1 ▶ my $leftover = substr($_,pos()//0);
Condition50%1/2
pos $_ // 0
l!l
10
MC/DC0%0/1
pos $_ // 0
pos $_
Truth table50%1/2
A
A= pos $_
Aresult
11
00
2132 1 my $e;
2133 # Try to recognize user syntax errors
2134 1 ▶ if ($leftover =~ /^[\$\@\%][\s\%\@]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($leftover =~ /^[\$\@\%][\s\%\@]/u) { } 0 1 1
2135 0 $e = "Invalid expression syntax starting at '$leftover' in $funcname arg"
2136 } else {
2137 # Otherwise we may have a parser bug
2138 1 $e = "Invalid expression (or ".__PACKAGE__." bug):\n${LQ}$leftover${RQ}";
2139 }
2140 1 carp "$e\n";
2141 1 push @pieces, ['p',"<INVALID EXPRESSION>".$leftover];
2142 }
2143 1457 foreach (@pieces) {
2144 6223 my ($meth, $str) = @$_;
2145 # If the user uses 'single quoted' strings then backslash escapes
2146 # can not be emulated exactly as they would work in double-quoted strings
2147 # because \ is inconsistently passed through, namely only when not
2148 # followed by another backslash (or a quote character).
2149 # say ivis '\015'; # octal escape for CR intended?
2150 # say ivis '\\015'; # four literal characters \015 intended?
2151 # We can not tell the difference because we get \015 in both cases.
2152 #
2153 # Currently we interpolate all \-escapes we see, so to get a literal
2154 # backslash users must double them, e.g.
2155 # say ivis 'The four char escape sequence \\\\015 produces \015';
2156 # Here-docs do not treat \ specially and so avoid this problem:
2157 # say ivis <<\END;
2158 # The four char escape sequence \\015 produces \015
2159 # END
2160 #
2161 # 0/18/23: Now really *all* \-escapes are interpolated, so this works:
2162 # say ivis '\$foo = $foo' # $foo = <value>
2163  
2164 #next unless $meth eq 'p' && $str =~ /\\[abtnfrexXN0-7]/;
2165 #$str =~ s/([()\$\@\%])/\\$1/g; # dont hide \-escapes to be interpolated!
2166  
2167 6223 ▶ if ($meth eq 'p') {
Branch: 2 branches
BranchTrueFalseTotal
if ($meth eq 'p') { } 2350 3873 6223
elsif ($meth eq 'P') { } 1922 1951 3873
2168 2350 ▶ if ($str =~ /\\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\\./u) 463 1887 2350
2169 463 $str =~ s/\$\\/\$\\\\/g; # Assume the punct var $\ is not intended
2170 463 $str =~ s/([()])/\\$1/g;
2171 463 $_->[1] = "qq(" . $str . ")";
2172 463 $_->[0] = 'e';
2173 }
2174 }
2175 elsif ($meth eq 'P') {
2176 1922 $_->[0] = 'p';
2177 }
2178 }
2179 } #local $_
2180  
2181 1457 @_ = ($self, $funcname, \@pieces);
2182 1457 goto &DB::DB_Vis_Interpolate
2183 }
2184  
2185 0 ▶sub quotekey(_) { # Quote a hash key if not a valid bareword
Subroutine quotekey: not called CC=5 SCAR=34.0
Pod documented
2186 0 ▶ $_[0] =~ /\A${userident_re}\z/s ? $_[0] :
Branch: 3 branches
BranchTrueFalseTotal
$_[0] =~ /\A$userident_re\z/su ? : 0 0 0
$_[0] =~ /(?!.*')["\$\@]/u ? : 0 0 0
$_[0] =~ /\W/u && !&looks_like_number($_[0]) ? : 0 0 0
Condition0%0/3
$_[0] =~ /\W/u and not &looks_like_number($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] =~ /\W/u and not &looks_like_number($_[0])
$_[0] =~ /\W/u not &looks_like_number($_[0])
Truth table0%0/3
A and not(B)
A= $_[0] =~ /\W/uB= not &looks_like_number($_[0])
ABresult
0X0
100
111
2187 $_[0] =~ /(?!.*')["\$\@]/ ? visq("$_[0]") :
2188 $_[0] =~ /\W/ && !looks_like_number($_[0]) ? vis("$_[0]") :
2189 "\"$_[0]\""
2190 }
2191  
2192 1 ▶sub _install_CarpRefArgFormatter() {
Subroutine _install_CarpRefArgFormatter: called CC=3 SCAR=13.3
2193 1 my $prev = $Carp::RefArgFormatter;
2194 1 ▶ if ($prev && $prev != \&RefArgFormatter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev != \&Data::Dumper::Interp::RefArgFormatter) 0 1 1
Condition33%1/3
$prev and $prev != \&Data::Dumper::Interp::RefArgFormatter
!ll&&!rl&&r
100
MC/DC0%0/2
$prev and $prev != \&Data::Dumper::Interp::RefArgFormatter
$prev $prev != \&Data::Dumper::Interp::RefArgFormatter
Truth table33%1/3
A and B
A= $prevB= $prev != \&Data::Dumper::Interp::RefArgFormatter
ABresult
0X0
100
111
2195 0 croak("\$Carp::RefArgFormatter was previously set to another handler: $prev = ",visnew->vis($prev))
2196 }
2197 1 $Carp::RefArgFormatter = \&RefArgFormatter;
2198 }
2199  
2200 # Must be declared after global like $Debug etc.
2201 46 ▶sub import {
Subroutine import: called CC=32 SCAR=36.4
2202 46 my $class = shift;
2203 46 my @input_args = @_;
2204  
2205 46 ▶ @input_args = (':DEFAULT') if @input_args == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @input_args == 0 11 35 46
2206  
2207 46 my $import_debug = $Debug;
2208  
2209 46 my @args;
2210 46 foreach (@input_args) {
2211 52 ▶ if (/^:debug(.*)/) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^:debug(.*)/u) { } 0 52 52
elsif (/^:DEFAULT/u) { } 12 40 52
elsif (/^:carp/u) { } 1 39 40
elsif (/^:all/u) { } 4 35 39
elsif (/^:(Debug|MaxStringwidth|Truncsuffix|Trunctailwidth|Objects|Refaddr|Foldwidth|Foldwidth1|Useqq|Quotekeys|Sortkeys|Maxdepth|Maxrecurse|Deparse|Deepcopy)=(.*)/u) { } 28 7 35
2212 0 my $rhs = $1;
2213 0 ▶ my $level = $rhs eq "" ? 1 : $rhs =~ /^=(\d+)$/ ? $1 : croak "INVALID import $_";
Branch: 2 branches
BranchTrueFalseTotal
$rhs eq '' ? : 0 0 0
$rhs =~ /^=(\d+)$/u ? : 0 0 0
2214 0 $import_debug = $AUTOLOAD_debug = $level; # show generated code
2215 }
2216 elsif (/^:DEFAULT/) {
2217 12 push @args, @EXPORT;
2218 }
2219 elsif (/^:carp/) {
2220 1 _install_CarpRefArgFormatter();
2221 }
2222 elsif (/^:all/) {
2223 # Generate all modifier combinations as suffixes in alphabetical order.
2224 0 my %already = map{$_ => 1} @args;
2225 #WRONG: push @args, ":DEFAULT" unless $already{':DEFAULT'};
2226 4 ▶ foreach (@EXPORT) { push @args, $_ unless $already{$_}++; }
Branch: 1 branch
BranchTrueFalseTotal
unless $already{$_}++ 128 0 128
2227 4 for my $v1 (qw/avis hvis vis ivis dvis/) { # avisl hvisl ?
2228 20 for my $v2 ('1', '2', "") {
2229 60 for my $v3 ('l', "") {
2230 120 ▶ next if $v3 && $v1 !~ /^[ah]/; # 'l' only with avis or hvis
Branch: 1 branch
BranchTrueFalseTotal
if $v3 and not $v1 =~ /^[ah]/u 36 84 120
Condition100%3/3
$v3 and not $v1 =~ /^[ah]/u
!ll&&!rl&&r
602436
MC/DC100%2/2
$v3 and not $v1 =~ /^[ah]/u
$v3 not $v1 =~ /^[ah]/u
Truth table100%3/3
A and not(B)
A= $v3B= not $v1 =~ /^[ah]/u
ABresult
0X0
100
111
2231 84 for my $v4 ('o', "") {
2232 168 for my $v5 ('q', "") {
2233 336 for my $v6 ('r', "") {
2234 672 my $subname = $v1.$v2.$v3.$v4.$v5.$v6;
2235 672 ▶ push @args, $subname unless $already{$subname}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $already{$subname}++ 592 80 672
2236 }
2237 }
2238 }
2239 }
2240 }
2241 }
2242 }
2243 elsif (/^:(Debug|MaxStringwidth|Truncsuffix|Trunctailwidth|Objects|Refaddr|Foldwidth|Foldwidth1|Useqq|Quotekeys|Sortkeys|Maxdepth|Maxrecurse|Deparse|Deepcopy)=(.*)/) {
2244 # Set a global option variable
2245 28 my ($name, $rhs) = ($1, $2);
2246 28 ▶ if ($rhs !~ /^${quoted_re}$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rhs =~ /^$quoted_re$/u) 25 3 28
2247 # ?? auto-quote non-numbers which don't look like Perl code??
2248 # No, that would complicate the interface unnecessarily; make the
2249 # user include quotes around strings e.g. ':Truncsuffix="(truncated)"'
2250 }
2251 28 eval "\$Data::Dumper::Interp::$name = $rhs";
2252 28 ▶ croak "Error eval'ing import option $_\n$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 28 28
2253 28 ▶ warn "Eval'd $_\n" if $import_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $import_debug 0 28 28
2254 }
2255 else {
2256 7 push @args, $_; # a subname to generate and pass to Exporter
2257 }
2258 }
2259  
2260 46 foreach my $subname (@args) {
2261 1111 ▶ next unless $subname =~ /^[a-zA-Z]/a; # skip :tag or $var
Branch: 1 branch
BranchTrueFalseTotal
unless $subname =~ /^[a-zA-Z]/a 0 1111 1111
2262 1111 push @EXPORT_OK, $subname;
2263 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2264 1111 ▶ if (defined(*$subname{CODE})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$subname{'CODE'}) { } 181 930 1111
2265 181 ▶ warn "# $subname ALREADY DEFINED\n" if ($import_debug//0) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if ($import_debug // 0) > 1 0 181 181
Condition50%1/2
$import_debug // 0
l!l
1810
MC/DC0%0/1
$import_debug // 0
$import_debug
Truth table50%1/2
A
A= $import_debug
Aresult
11
00
2266 } else {
2267 # Only generate a 'forward' stub to allow prototype checks.
2268 # Subs actually called will be defined via AUTOLOAD
2269 930 _generate_sub($subname, 1);
2270 }
2271 }
2272  
2273 46 ▶ @args = (':null') if @_ && !@args;
Branch: 1 branch
BranchTrueFalseTotal
if @_ and not @args 29 17 46
Condition100%3/3
@_ and not @args
!ll&&!rl&&r
11629
MC/DC100%2/2
@_ and not @args
@_ not @args
Truth table100%3/3
A and not(B)
A= @_B= not @args
ABresult
0X0
100
111
2274  
2275 46 ▶ warn "Passing to Exporter::import ",&_dbavis(@args),"\n"
Branch: 1 branch
BranchTrueFalseTotal
if $import_debug 0 46 46
2276 if $import_debug;
2277  
2278 46 __PACKAGE__->export_to_level(1, $class, @args);
2279 }
2280  
2281 package
2282 DB;
2283  
2284 1457 ▶sub DB_Vis_Interpolate {
Subroutine DB_Vis_Interpolate: called CC=7 SCAR=19.6
Pod undocumented
2285 1457 my ($self, $funcname, $pieces) = @_;
2286 1457 my $result = "";
2287 1457 foreach my $p (@$pieces) {
2288 6223 my ($methname, $arg) = @$p;
2289 #say "III methname=$methname arg='$arg'";
2290 6223 ▶ if ($methname eq 'p') {
Branch: 2 branches
BranchTrueFalseTotal
if ($methname eq 'p') { } 3809 2414 6223
elsif ($methname eq 'e') { } 463 1951 2414
2291 3809 $result .= $arg;
2292 }
2293 elsif ($methname eq 'e') {
2294 463 $result .= DB::DB_Vis_Eval($funcname, $arg);
2295 } else {
2296 # Reduce width before first wrap to account for stuff already on the line
2297 1951 my $leftwid = length($result) - rindex($result,"\n") - 1;
2298 1951 my $foldwidth = $self->{Foldwidth};
2299 1951 ▶ local $self->{Foldwidth1} = $self->{Foldwidth1} // $foldwidth;
Condition33%1/3
$self->{"Foldwidth1"} // $foldwidth
l!l&&r!l&&!r
019510
MC/DC0%0/2
$self->{"Foldwidth1"} // $foldwidth
$self->{"Foldwidth1"} $foldwidth
Truth table33%1/3
A // B
A= $self->{"Foldwidth1"}B= $foldwidth
ABresult
1X1
011
000
2300 1951 ▶ if ($foldwidth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foldwidth) 1865 86 1951
2301 $self->{Foldwidth1} -= $leftwid if $leftwid < $self->{Foldwidth1}
2302 1865 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if $leftwid < $self->{"Foldwidth1"} 1865 0 1865
2303 1951 $result .= $self->$methname(
2304 DB::DB_Vis_Eval($funcname, $arg)
2305 );
2306 }
2307 }
2308  
2309 1457 &Data::Dumper::Interp::_RestorePunct; # saved in _Interpolate
2310 1457 $result
2311 }# DB_Vis_Interpolate
2312  
2313 # eval a string in the user's context and return the result. The nearest
2314 # non-DB frame must be the original user's call; this is accomplished by
2315 # dvis() and friends using "goto &_Interpolate", which in turn
2316 # does "goto &DB::DB_Vis_Interpolate" to enter package DB.
2317 2414 ▶sub DB_Vis_Eval($$) {
Subroutine DB_Vis_Eval: called CC=10 SCAR=23.9
Pod undocumented
2318 2414 my ($label_for_errmsg, $evalarg) = @_;
2319 2414 ▶ Carp::confess("Data::Dumper::Interp bug:empty evalarg") if $evalarg eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $evalarg eq "" 0 2414 2414
2320 # Originally inspired by perl5db.pl but at this point has been rewritten
2321  
2322 # Find the closest non-DB caller. The eval will be done in that package.
2323 #
2324 # We want @_ to refer to the arguments to *that* caller, not to e.g. dvis;
2325 # find the next caller further up which has arguments (i.e. wasn't doing
2326 # "&subname;"), and make @_ contain those arguments.
2327 2414 my ($distance, $pkg, $fname, $lno);
2328 2414 for ($distance = 0 ; ; $distance++) {
2329 4828 ($pkg, $fname, $lno) = caller($distance);
2330 4828 ▶ last if $pkg ne "DB";
Branch: 1 branch
BranchTrueFalseTotal
if $pkg ne "DB" 2414 2414 4828
2331 }
2332 2414 local @_; # = ("*DDI:Should not see*");
2333 2414 while() {
2334 4049 $distance++;
2335 4049 my ($p, $hasargs) = (caller($distance))[0,4];
2336 4049 ▶ if (! defined $p){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $p) 789 3260 4049
2337 789 @_ = ( '<@_ is not defined in the outer block>' );
2338 last
2339 789 }
2340 3260 ▶ if ($hasargs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasargs) 1625 1635 3260
2341 #WAS: @_ = @{ [ @DB::args ] }; # copy in case of recursion
2342 #4/26/24: This sometimes gets "panic: attempt to copy freed scalar"
2343 #
2344 # N.B. We can not copy args using +0 or ."" because then objects
2345 # will numify/stringify and we can't display their internals.
2346 #
2347 # I tried cloning DB::args with Clone::clone but still got SEGV somewhere
2348 # or "Attempt to free unreferenced scalar".
2349 #
2350 # Trying code lifted from Carp.pm :
2351 @_ = map {
2352 1625 my $arg;
2353 3249 local $@= $@;
2354 eval {
2355 3249 $arg = $_;
2356 3249 1;
2357 3249 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $arg = $_; 1 } } or do { $arg = "** argument not available anymore **" } 3249 0 3249
2358 0 $arg = '** argument not available anymore **';
2359 };
2360 3249 $arg;
2361 } @DB::args;
2362 last
2363 1625 }
2364 }
2365  
2366 2414 local @Data::Dumper::Interp::result;
2367 2414 local $Data::Dumper::Interp::string_to_eval =
2368 "package $pkg; "
2369 # N.B. eval first clears $@ so we must restore $@ inside the eval
2370 .' &Data::Dumper::Interp::_RestorePunct_NoPop();' # saved in _Interpolate
2371 # In case something carps or croaks (e.g. because of ${\(somefunc())}
2372 # or a tie handler), force a full backtrace so the user's call location
2373 # is visible. Unfortunately there is no way to make carp() show only
2374 # the location of the user's call because we must force the eval'd
2375 # string into in e.g. package main so user functions can be found.
2376 .' local $Carp::Verbose = 1;'
2377 .' @Data::Dumper::Interp::result = '.$evalarg.';'
2378 .' $Data::Dumper::Interp::save_stack[-1]->[0] = $@;' # possibly changed by a tie handler
2379 ;
2380 2414 &DB_Vis_Evalwrapper;
2381 2414 my $errmsg = $@;
2382 2414 my @result = @Data::Dumper::Interp::result;
2383  
2384 2414 ▶ if ($errmsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errmsg) 0 2414 2414
2385 0 $errmsg = Data::Dumper::Interp::_chop_ateval($errmsg);
2386 0 $errmsg =~ s/Global symbol "([^"]*)" requires explicit package name.*/$1 does not exist (or has been optimized out)/;
2387 0 Carp::carp("${label_for_errmsg} interpolation error: $errmsg\n");
2388 0 ▶ @result = ( (defined($result[0]) ? $result[0] : "")."<invalid/error>"
Branch: 1 branch
BranchTrueFalseTotal
defined $result[0] ? : 0 0 0
2389 , "" # second item in case this ends up in %{ ... }
2390 );
2391 }
2392  
2393 2414 ▶ wantarray ? @result : (do{Carp::confess("bug",Data::Dumper::Interp::_dbavis(@result)) if @result>1}, $result[0])
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 1951 463 2414
if @result > 1 0 463 463
2394 }# DB_Vis_Eval
2395  
2396 15 1;
2397 __END__
↑ Summary