blib/lib/Devel/MAT/Tool/Show.pm

filter: Statementstmt 28.1% 70 / 249 Branchbran 0.0% 0 / 166 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 48.9% 23 / 47 Podpod 0.0% 0 / 20 totaltotal 17.8% 93 / 522 CC 109 SCAR 47.7
CC
109
Cov
16%
show_PAD_contents
420.0
show_CODE
272.0
show_GLOB
132.0
CRAP 118.3
« blib/lib/Devel/MAT/Tool/Callers.pm ↑ Summary blib/lib/Devel/MAT/Tool/Reachability.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2016-2026 -- leonerd@leonerd.org.uk
5  
6 package Devel::MAT::Tool::Show 0.56;
7  
8 5 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use feature qw( postderef signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶no warnings qw( experimental::postderef experimental::signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use List::Util qw( max );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 ▶use constant CMD => "show";
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use constant CMD_DESC => "Show information about a given SV";
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 ▶use constant CMD_OPTS => (
Subroutine BEGIN: called CC=1 SCAR=0.0
21 full_pv => { help => "show the full captured PV",
22 alias => "F" },
23 pad => { help => "show the first PAD of a CODE",
24 alias => "P" },
25 5 );
26  
27 =head1 NAME
28  
29 C<Devel::MAT::Tool::Show> - show information about a given SV
30  
31 =head1 DESCRIPTION
32  
33 This C<Devel::MAT> tool provides a command that prints interesting information
34 from within an SV. Its exact output will depend on the type of SV it is
35 applied to.
36  
37 =cut
38  
39 =head1 COMMANDS
40  
41 =for highlighter
42  
43 =cut
44  
45 =head2 show
46  
47 pmat> show 0x1bbf598
48 IO() at 0x1bbf598 with refcount 2
49 blessed as IO::File
50 ifileno=2
51 ofileno=2
52  
53 Prints information about the given SV.
54  
55 =cut
56  
57 5 ▶use constant CMD_ARGS_SV => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 5 my @SHOW_EXTRA;
60 0 ▶sub register_extra ( $pkg, $code )
Subroutine register_extra: not called CC=1 SCAR=6.9
Pod undocumented
61 {
62 0 push @SHOW_EXTRA, $code;
63 }
64  
65 0 ▶sub run ( $self, $optsref, $sv )
Subroutine run: not called CC=9 SCAR=45.0
Pod undocumented
66 {
67 0 my %opts = $optsref->%*;
68  
69 0 ▶ Devel::MAT::Cmd->printf( "%s with refcount %d%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$sv->is_mortal ? : 0 0 0
70 Devel::MAT::Cmd->format_sv( $sv ),
71 $sv->refcnt,
72 $sv->is_mortal ? ( " " . Devel::MAT::Cmd->format_note( "(mortalized)", 1 ) ) : "",
73 );
74  
75 0 my $size = $sv->size;
76 0 ▶ if( $size < 1024 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size < 1024) { } 0 0 0
77 0 Devel::MAT::Cmd->printf( " size %d bytes\n",
78 $size,
79 );
80 }
81 else {
82 0 Devel::MAT::Cmd->printf( " size %s (%d bytes)\n",
83 Devel::MAT::Cmd->format_bytes( $size ),
84 $size,
85 );
86 }
87  
88 0 ▶ if( my $stash = $sv->blessed ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stash = $sv->blessed) 0 0 0
89 0 Devel::MAT::Cmd->printf( " blessed as %s\n", $stash->stashname );
90 }
91  
92 0 ▶ if( my $symname = $sv->symname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $symname = $sv->symname) 0 0 0
93 0 Devel::MAT::Cmd->printf( " named as %s\n",
94 Devel::MAT::Cmd->format_symbol( $symname )
95 );
96 }
97  
98 0 foreach my $magic ( $sv->magic ) {
99 0 my $ver = $magic->ver;
100 0 my $method = "show_magicv$ver";
101 0 $self->$method( $magic );
102 }
103  
104 0 ▶ if( defined( my $serial = $sv->debug_serial ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $serial = $sv->debug_serial)) 0 0 0
105 0 Devel::MAT::Cmd->printf( " debug serial %d\n", $serial );
106  
107 0 my $file = $sv->debug_file;
108 0 ▶ Devel::MAT::Cmd->printf( " created at %s:%d\n", $file, $sv->debug_line )
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 0 0 0
109 if defined $file;
110 }
111  
112 0 foreach my $extra ( @SHOW_EXTRA ) {
113 0 $extra->( $sv ); # TODO: consider opts?
114 }
115  
116 0 my $type = $sv->type;
117 0 my $method = "show_$type";
118 0 $self->$method( $sv, \%opts );
119 }
120  
121 0 ▶sub say_with_sv ( $str, @args )
Subroutine say_with_sv: not called CC=1 SCAR=6.9
Pod undocumented
122 {
123 0 my $sv = pop @args;
124  
125 0 Devel::MAT::Cmd->printf( $str . "%s\n",
126 @args,
127 Devel::MAT::Cmd->format_sv( $sv ),
128 );
129 }
130  
131 0 ▶sub show_magicv1 ( $self, $magic )
Subroutine show_magicv1: not called CC=5 SCAR=34.0
Pod undocumented
132 {
133 0 my $type = $magic->type;
134 0 ▶ $type = "^" . chr( 0x40 + ord $type ) if ord $type < 0x20;
Branch: 1 branch
BranchTrueFalseTotal
if ord $type < 32 0 0 0
135  
136 0 Devel::MAT::Cmd->printf( " has %s magic",
137 Devel::MAT::Cmd->format_note( $type, 1 ),
138 );
139  
140 0 ▶ Devel::MAT::Cmd->printf( " with object at %s",
Branch: 1 branch
BranchTrueFalseTotal
if $magic->obj 0 0 0
141 Devel::MAT::Cmd->format_sv( $magic->obj )
142 ) if $magic->obj;
143  
144 0 ▶ Devel::MAT::Cmd->printf( " with pointer at %s",
Branch: 1 branch
BranchTrueFalseTotal
if $magic->ptr 0 0 0
145 Devel::MAT::Cmd->format_sv( $magic->ptr )
146 ) if $magic->ptr;
147  
148 0 ▶ Devel::MAT::Cmd->printf( "\n with virtual table at %s",
Branch: 1 branch
BranchTrueFalseTotal
if $magic->vtbl 0 0 0
149 Devel::MAT::Cmd->format_value( $magic->vtbl, addr => 1 )
150 ) if $magic->vtbl;
151  
152 0 Devel::MAT::Cmd->printf( "\n" );
153 }
154  
155 0 ▶sub show_magicv2 ( $self, $magic )
Subroutine show_magicv2: not called CC=8 SCAR=42.8
Pod undocumented
156 {
157 0 Devel::MAT::Cmd->printf( " has MagicV2 with funcs at %s",
158 Devel::MAT::Cmd->format_value( $magic->funcs, addr => 1 )
159 );
160  
161 0 ▶ Devel::MAT::Cmd->printf( "\n with auxsv at %s",
Branch: 1 branch
BranchTrueFalseTotal
if $magic->auxsv 0 0 0
162 Devel::MAT::Cmd->format_sv( $magic->auxsv )
163 ) if $magic->auxsv;
164  
165 0 ▶ if( $magic->ptr and $magic->ptrlen ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($magic->ptr and $magic->ptrlen) { } 0 0 0
elsif ($magic->ptr) { } 0 0 0
elsif ($magic->ptrlen) { } 0 0 0
Condition0%0/3
$magic->ptr and $magic->ptrlen
!ll&&!rl&&r
000
MC/DC0%0/2
$magic->ptr and $magic->ptrlen
$magic->ptr $magic->ptrlen
Truth table0%0/3
A and B
A= $magic->ptrB= $magic->ptrlen
ABresult
0X0
100
111
166 0 Devel::MAT::Cmd->printf( "\n with ptr %s len %s",
167 Devel::MAT::Cmd->format_value( $magic->ptr, addr => 1 ),
168 Devel::MAT::Cmd->format_value( $magic->ptrlen ),
169 );
170 }
171 elsif( $magic->ptr ) {
172 0 Devel::MAT::Cmd->printf( "\n with ptr %s",
173 Devel::MAT::Cmd->format_value( $magic->ptr, addr => 1 ),
174 );
175 }
176 elsif( $magic->ptrlen ) {
177 0 Devel::MAT::Cmd->printf( "\n with ptrlen %s",
178 Devel::MAT::Cmd->format_value( $magic->ptrlen ),
179 );
180 }
181  
182 0 ▶ Devel::MAT::Cmd->printf( "\n with keyiv %s",
Branch: 1 branch
BranchTrueFalseTotal
if defined $magic->keyiv 0 0 0
183 Devel::MAT::Cmd->format_value( $magic->keyiv )
184 ) if defined $magic->keyiv;
185  
186 0 ▶ Devel::MAT::Cmd->printf( "\n with keysv at %s",
Branch: 1 branch
BranchTrueFalseTotal
if $magic->keysv 0 0 0
187 Devel::MAT::Cmd->format_sv( $magic->keysv )
188 ) if $magic->keysv;
189  
190 0 Devel::MAT::Cmd->printf( "\n" );
191 }
192  
193 sub show_UNDEF ( $self, $, $ ) { }
194  
195 0 ▶sub show_GLOB ( $self, $gv, $ )
Subroutine show_GLOB: not called CC=11 SCAR=48.8
Pod undocumented
196 {
197 0 ▶ if( $gv->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gv->name) 0 0 0
198 0 Devel::MAT::Cmd->printf( " name=%s\n", $gv->name );
199 0 ▶ Devel::MAT::Cmd->printf( " name_hek=%s\n", Devel::MAT::Cmd->format_value( $gv->name_hek, addr => 1 ) ) if $gv->name_hek;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->name_hek 0 0 0
200 }
201  
202 0 ▶ say_with_sv ' stash=', $gv->stash if $gv->stash;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->stash 0 0 0
203  
204 0 ▶ say_with_sv ' SCALAR=', $gv->scalar if $gv->scalar;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->scalar 0 0 0
205 0 ▶ say_with_sv ' ARRAY=', $gv->array if $gv->array;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->array 0 0 0
206 0 ▶ say_with_sv ' HASH=', $gv->hash if $gv->hash;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->hash 0 0 0
207 0 ▶ say_with_sv ' CODE=', $gv->code if $gv->code;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->code 0 0 0
208 0 ▶ say_with_sv ' EGV=', $gv->egv if $gv->egv;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->egv 0 0 0
209 0 ▶ say_with_sv ' IO=', $gv->io if $gv->io;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->io 0 0 0
210 0 ▶ say_with_sv ' FORM=', $gv->form if $gv->form;
Branch: 1 branch
BranchTrueFalseTotal
if $gv->form 0 0 0
211 }
212  
213 0 ▶sub show_SCALAR ( $self, $sv, $opts )
Subroutine show_SCALAR: not called CC=7 SCAR=40.3
Pod undocumented
214 {
215 0 ▶ Devel::MAT::Cmd->printf( " UV=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
if defined $sv->uv 0 0 0
216 Devel::MAT::Cmd->format_value( $sv->uv, nv => 1 ),
217 ) if defined $sv->uv;
218 0 ▶ Devel::MAT::Cmd->printf( " IV=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
if defined $sv->iv 0 0 0
219 Devel::MAT::Cmd->format_value( $sv->iv, nv => 1 ),
220 ) if defined $sv->iv;
221 0 ▶ Devel::MAT::Cmd->printf( " NV=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
if defined $sv->nv 0 0 0
222 Devel::MAT::Cmd->format_value( $sv->nv, nv => 1 ),
223 ) if defined $sv->nv;
224  
225 0 ▶ if( defined( my $pv = $sv->pv ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $pv = $sv->pv)) 0 0 0
226 Devel::MAT::Cmd->printf( " PV=%s\n",
227 Devel::MAT::Cmd->format_value( $pv, pv => 1,
228 0 ▶ ( $opts->{full_pv} ? ( maxlen => 0 ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'full_pv'} ? : 0 0 0
229 ),
230 );
231 0 Devel::MAT::Cmd->printf( " PVLEN %d\n", $sv->pvlen );
232  
233 0 ▶ Devel::MAT::Cmd->printf( " SHARED_HEK=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
if $sv->shared_hek 0 0 0
234 Devel::MAT::Cmd->format_value( $sv->shared_hek, addr => 1 ),
235 ) if $sv->shared_hek;
236 }
237 }
238  
239 0 ▶sub show_BOOL ( $self, $sv, $ )
Subroutine show_BOOL: not called CC=2 SCAR=17.9
Pod undocumented
240 {
241 0 ▶ Devel::MAT::Cmd->printf( " BOOL=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$sv->uv ? : 0 0 0
242 Devel::MAT::Cmd->format_value( $sv->uv ? "true" : "false" )
243 );
244 }
245  
246 0 ▶sub show_REF ( $self, $sv, $ )
Subroutine show_REF: not called CC=2 SCAR=17.9
Pod undocumented
247 {
248 0 ▶ say_with_sv ' RV=', $sv->rv if $sv->rv;
Branch: 1 branch
BranchTrueFalseTotal
if $sv->rv 0 0 0
249 }
250  
251 0 ▶sub show_ARRAY ( $self, $av, $ )
Subroutine show_ARRAY: not called CC=1 SCAR=6.9
Pod undocumented
252 {
253 0 Devel::MAT::Cmd->printf( " %d elements (use 'elems' command to show)\n",
254 $av->n_elems,
255 );
256 }
257  
258 0 ▶sub show_STASH ( $self, $hv, $ = undef )
Subroutine show_STASH: not called CC=2 SCAR=17.9
Pod undocumented
259 0 {
260 0 Devel::MAT::Cmd->printf( " stashname=%s\n", $hv->stashname );
261 0 $self->show_HASH( $hv );
262 }
263  
264 0 ▶sub show_HASH ( $self, $hv, $ = undef )
Subroutine show_HASH: not called CC=2 SCAR=17.9
Pod undocumented
265 0 {
266 0 Devel::MAT::Cmd->printf( " %d values (use 'values' command to show)\n",
267 $hv->n_values,
268 );
269 }
270  
271 0 ▶sub show_CODE ( $self, $cv, $opts )
Subroutine show_CODE: not called CC=16 SCAR=56.1
Pod undocumented
272 {
273 0 ▶ $cv->name_hek ? Devel::MAT::Cmd->printf( " name_hek=%s\n", Devel::MAT::Cmd->format_value( $cv->name_hek, addr => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
$cv->name_hek ? : 0 0 0
274 : ();
275  
276 0 ▶ $cv->hekname ? Devel::MAT::Cmd->printf( " hekname=%s\n", $cv->hekname )
Branch: 1 branch
BranchTrueFalseTotal
$cv->hekname ? : 0 0 0
277 : Devel::MAT::Cmd->printf( " no hekname\n" );
278  
279 0 ▶ $cv->stash ? say_with_sv( " stash=", $cv->stash )
Branch: 1 branch
BranchTrueFalseTotal
$cv->stash ? : 0 0 0
280 : Devel::MAT::Cmd->printf( " no stash\n" );
281  
282 0 ▶ $cv->glob ? say_with_sv( " glob=", $cv->glob )
Branch: 1 branch
BranchTrueFalseTotal
$cv->glob ? : 0 0 0
283 : Devel::MAT::Cmd->printf( " no glob\n" );
284  
285 0 ▶ $cv->location ? Devel::MAT::Cmd->printf( " location=%s\n", $cv->location )
Branch: 1 branch
BranchTrueFalseTotal
$cv->location ? : 0 0 0
286 : Devel::MAT::Cmd->printf( " no location\n" );
287  
288 0 ▶ $cv->scope ? say_with_sv( " scope=", $cv->scope )
Branch: 1 branch
BranchTrueFalseTotal
$cv->scope ? : 0 0 0
289 : Devel::MAT::Cmd->printf( " no scope\n" );
290  
291 0 ▶ $cv->padlist ? say_with_sv( " padlist=", $cv->padlist )
Branch: 1 branch
BranchTrueFalseTotal
$cv->padlist ? : 0 0 0
292 : ();
293  
294 0 ▶ $cv->padnames_av ? say_with_sv( " padnames_av=", $cv->padnames_av )
Branch: 1 branch
BranchTrueFalseTotal
$cv->padnames_av ? : 0 0 0
295 : ();
296  
297 0 ▶ $cv->protosub ? say_with_sv( " protosub=", $cv->protosub )
Branch: 1 branch
BranchTrueFalseTotal
$cv->protosub ? : 0 0 0
298 : ();
299  
300 0 my @pads = $cv->pads;
301 0 foreach my $depth ( 0 .. $#pads ) {
302 0 ▶ next unless $pads[$depth];
Branch: 1 branch
BranchTrueFalseTotal
unless $pads[$depth] 0 0 0
303 0 say_with_sv( " pad[$depth]=", $pads[$depth] );
304 }
305  
306 0 ▶ if( $opts->{pad} and my $pad0 = ( $cv->pads )[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"pad"} and my $pad0 = ($cv->pads)[0]) 0 0 0
Condition0%0/3
$opts->{"pad"} and my $pad0 = ($cv->pads)[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"pad"} and my $pad0 = ($cv->pads)[0]
$opts->{"pad"} my $pad0 = ($cv->pads)[0]
Truth table0%0/3
A and B
A= $opts->{"pad"}B= my $pad0 = ($cv->pads)[0]
ABresult
0X0
100
111
307 0 Devel::MAT::Cmd->printf( "PAD[0]:\n" );
308 0 $self->show_PAD_contents( $pad0, $opts );
309 }
310  
311 0 ▶ if( my @globs = $cv->globrefs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@globs) = $cv->globrefs) 0 0 0
312 0 Devel::MAT::Cmd->printf( "Referenced globs:\n " );
313 0 Devel::MAT::Cmd->printf( "%s, ", Devel::MAT::Cmd->format_sv( $_ ) ) for @globs;
314 0 Devel::MAT::Cmd->printf( "\n" );
315 }
316 }
317  
318 0 ▶sub show_PAD ( $self, $pad, $ )
Subroutine show_PAD: not called CC=2 SCAR=17.9
Pod undocumented
319 {
320 0 my $padcv = $pad->padcv;
321 0 ▶ $padcv ? say_with_sv( " padcv=", $padcv )
Branch: 1 branch
BranchTrueFalseTotal
$padcv ? : 0 0 0
322 : Devel::MAT::Cmd->printf( " no padcv\n" );
323  
324 0 $self->show_PAD_contents( $pad );
325 }
326  
327 0 ▶sub _join ( $sep, $ret, @elems )
Subroutine _join: not called CC=2 SCAR=17.9
328 {
329 # Like CORE::join but respects string concat operator
330 0 $ret = $ret . $sep . $_ for @elems;
331 0 return $ret;
332 }
333  
334 0 ▶sub show_PAD_contents ( $self, $pad, $ = undef )
Subroutine show_PAD_contents: not called CC=20 SCAR=60.4
Pod undocumented
335 0 {
336 0 my $padcv = $pad->padcv;
337  
338 0 my @elems = $pad->elems;
339 my @padnames = map {
340 0 my $padname = $padcv->padname( $_ );
341 # is_outer is always set for is_our; it's only interesting without is_our
342 0 ▶ my $is_just_outer = $padname && $padname->is_outer && !$padname->is_our;
Condition0%0/6
$padname && $padname->is_outer && !$padname->is_our
!ll&&!rl&&r
000
$padname and $padname->is_outer
!ll&&!rl&&r
000
MC/DC0%0/3
$padname && $padname->is_outer && !$padname->is_our
$padname $padname->is_outer !$padname->is_our
Truth table0%0/4
A and B && not(C)
A= $padnameB= $padname->is_outerC= !$padname->is_our
ABCresult
0XX0
10X0
1100
1111
343  
344 0 ▶ $padname ? _join( " ",
Branch: 5 branches
BranchTrueFalseTotal
$padname ? : 0 0 0
$padname->is_state ? : 0 0 0
$padname->is_our ? : 0 0 0
$padname->is_field ? : 0 0 0
$is_just_outer ? : 0 0 0
345 ( $padname->is_state ? Devel::MAT::Cmd->format_note( "state" ) : () ),
346 ( $padname->is_our ? Devel::MAT::Cmd->format_note( "our" ) : () ),
347 ( $padname->is_field ? Devel::MAT::Cmd->format_note( "field" ) : () ),
348 Devel::MAT::Cmd->format_note( $padname->name, 1 ),
349 ( $is_just_outer ? Devel::MAT::Cmd->format_note( "*OUTER", 2 ) : () ),
350 # is_typed and is_lvalue not indicated
351 ) : undef
352 } 0 .. $#elems;
353 0 my $idxlen = length $#elems;
354 0 ▶ my $namelen = max map { defined $_ ? length $_ : 0 } @padnames;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
355  
356 0 my %padtype;
357 0 ▶ if( my $gvix = $padcv->{gvix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $gvix = $padcv->{"gvix"}) 0 0 0
358 0 $padtype{$_} = "GLOB" for @$gvix;
359 }
360 0 ▶ if( my $constix = $padcv->{constix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $constix = $padcv->{"constix"}) 0 0 0
361 0 $padtype{$_} = "CONST" for @$constix;
362 }
363  
364 0 ▶ Devel::MAT::Cmd->printf( " [%*d/%-*s]=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$elems[0] ? : 0 0 0
365 $idxlen, 0,
366 $namelen, Devel::MAT::Cmd->format_note( '@_', 1 ),
367 ( $elems[0] ? Devel::MAT::Cmd->format_sv_with_value( $elems[0] ) : "NULL" ),
368 );
369  
370 0 foreach my $padix ( 1 .. $#elems ) {
371 0 my $sv = $elems[$padix];
372 0 ▶ if( $padnames[$padix] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padnames[$padix]) { } 0 0 0
373 0 ▶ Devel::MAT::Cmd->printf( " [%*d/%-*s]=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$sv ? : 0 0 0
374 $idxlen, $padix,
375 $namelen, $padnames[$padix],
376 ( $sv ? Devel::MAT::Cmd->format_sv_with_value( $sv ) : "NULL" ),
377 );
378 }
379 else {
380 Devel::MAT::Cmd->printf( " [%*d %-*s]=%s\n",
381 $idxlen, $padix,
382 0 ▶ $namelen, $padtype{$padix} // "",
Branch: 1 branch
BranchTrueFalseTotal
$sv ? : 0 0 0
Condition0%0/2
$padtype{$padix} // ""
l!l
00
MC/DC0%0/1
$padtype{$padix} // ""
$padtype{$padix}
Truth table0%0/2
A
A= $padtype{$padix}
Aresult
11
00
383 ( $sv ? Devel::MAT::Cmd->format_sv_with_value( $sv ) : "NULL" ),
384 );
385 }
386 }
387 }
388  
389 # TODO: PADLIST
390  
391 0 ▶sub show_PADNAMES ( $self, $padnames, $ )
Subroutine show_PADNAMES: not called CC=5 SCAR=34.0
Pod undocumented
392 {
393 0 ▶ $padnames->padcv ? say_with_sv( " padcv=", $padnames->padcv )
Branch: 1 branch
BranchTrueFalseTotal
$padnames->padcv ? : 0 0 0
394 : Devel::MAT::Cmd->printf( " no padcv\n" );
395  
396 0 my @elems = $padnames->elems;
397 # Every PADNAMES element is either NULL or a SCALAR(PV)
398 # PADIX 0 is always @_
399 0 foreach my $padix ( 1 .. $#elems ) {
400 0 my $slot = $elems[$padix];
401 0 ▶ if( $slot and $slot->type eq "SCALAR" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slot and $slot->type eq "SCALAR") 0 0 0
Condition0%0/3
$slot and $slot->type eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
$slot and $slot->type eq "SCALAR"
$slot $slot->type eq "SCALAR"
Truth table0%0/3
A and B
A= $slotB= $slot->type eq "SCALAR"
ABresult
0X0
100
111
402 0 Devel::MAT::Cmd->printf( " [%d] is %s\n", $padix, Devel::MAT::Cmd->format_note( $slot->pv, 1 ) );
403 }
404 }
405 }
406  
407 0 ▶sub show_IO ( $self, $io, $ )
Subroutine show_IO: not called CC=3 SCAR=24.8
Pod undocumented
408 {
409 0 ▶ Devel::MAT::Cmd->printf( " ifileno=%d\n", $io->ifileno ) if defined $io->ifileno;
Branch: 1 branch
BranchTrueFalseTotal
if defined $io->ifileno 0 0 0
410 0 ▶ Devel::MAT::Cmd->printf( " ofileno=%d\n", $io->ofileno ) if defined $io->ofileno;
Branch: 1 branch
BranchTrueFalseTotal
if defined $io->ofileno 0 0 0
411 }
412  
413 0 ▶sub show_OBJECT ( $self, $obj, $ )
Subroutine show_OBJECT: not called CC=2 SCAR=17.9
Pod undocumented
414 {
415 0 my @fields = $obj->fields;
416  
417 0 foreach my $field ( $obj->blessed->fields ) {
418 0 my $val = $obj->field( $field->fieldix );
419  
420 0 Devel::MAT::Cmd->printf( " %s=%s\n",
421 Devel::MAT::Cmd->format_note( $field->name, 1 ),
422 Devel::MAT::Cmd->format_sv_with_value( $val )
423 );
424 }
425 }
426  
427 0 ▶sub show_CLASS ( $self, $cls, $ )
Subroutine show_CLASS: not called CC=2 SCAR=17.9
Pod undocumented
428 {
429 0 Devel::MAT::Cmd->printf( " is CLASS\n" );
430  
431 0 ▶ $cls->adjust_blocks ? say_with_sv( " adjust_blocks=", $cls->adjust_blocks )
Branch: 1 branch
BranchTrueFalseTotal
$cls->adjust_blocks ? : 0 0 0
432 : ();
433  
434 0 $self->show_STASH( $cls );
435 }
436  
437 0 ▶sub show_C_STRUCT ( $self, $struct, $ )
Subroutine show_C_STRUCT: not called CC=6 SCAR=37.4
Pod undocumented
438 {
439 0 my @fields = $struct->fields;
440  
441 0 ▶ while( @fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) 0 0 0
442 0 my $field = shift @fields;
443 0 my $val = shift @fields;
444  
445 0 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
446  
447 0 ▶ if( $field->type == 0x00 ) { # PTR
Branch: 2 branches
BranchTrueFalseTotal
if ($field->type == 0) { } 0 0 0
elsif ($field->type == 1) { } 0 0 0
448 0 Devel::MAT::Cmd->printf( " %s=%s\n",
449 $field->name,
450 Devel::MAT::Cmd->format_sv_with_value( $val )
451 );
452 }
453 elsif( $field->type == 0x01 ) { # BOOL
454 0 ▶ Devel::MAT::Cmd->printf( " %s=%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
455 $field->name,
456 Devel::MAT::Cmd->format_value( $val ? "true" : "false" )
457 );
458 }
459 else { # various number types
460 0 Devel::MAT::Cmd->printf( " %s=%s\n",
461 $field->name,
462 Devel::MAT::Cmd->format_value( $val ),
463 );
464 }
465 }
466 }
467  
468 package # hide
469 Devel::MAT::Tool::Show::_elems;
470 5 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
471  
472 5 ▶use List::Util qw( min );
Subroutine BEGIN: called CC=1 SCAR=0.0
473  
474 5 ▶use constant CMD => "elems";
Subroutine BEGIN: called CC=1 SCAR=0.0
475 5 ▶use constant CMD_DESC => "List the elements of an ARRAY SV";
Subroutine BEGIN: called CC=1 SCAR=0.0
476  
477 =head2 elems
478  
479 pmat> elems endav
480 [0] CODE(PP) at 0x562e93222dc8
481  
482 Prints elements of an ARRAY SV.
483  
484 Takes the following named options:
485  
486 =over 4
487  
488 =item --count, -c MAX
489  
490 Show at most this number of elements (default 50).
491  
492 =item --start, -s COUNT
493  
494 Start at the given index.
495  
496 =back
497  
498 =cut
499  
500 5 ▶use constant CMD_OPTS => (
Subroutine BEGIN: called CC=1 SCAR=0.0
501 count => { help => "maximum count of elements to print",
502 type => "i",
503 alias => "c",
504 default => 50 },
505 start => { help => "starting index",
506 type => "i",
507 alias => "s" },
508 5 );
509  
510 5 ▶use constant CMD_ARGS_SV => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
511 5 ▶use constant CMD_ARGS => (
Subroutine BEGIN: called CC=1 SCAR=0.0
512 5 );
513  
514 0 ▶sub run ( $self, $optsref, $av )
Subroutine run: not called CC=8 SCAR=42.8
515 {
516 0 my %opts = $optsref->%*;
517  
518 0 my $type = $av->type;
519 0 ▶ if( $type eq "HASH" or $type eq "STASH" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'HASH' or $type eq 'STASH') { } 0 0 0
elsif ($type ne 'ARRAY') { } 0 0 0
Condition0%0/3
$type eq "HASH" or $type eq "STASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "HASH" or $type eq "STASH"
$type eq "HASH" $type eq "STASH"
Truth table0%0/3
A or B
A= $type eq "HASH"B= $type eq "STASH"
ABresult
1X1
011
000
520 0 die "Cannot 'elems' of a $type - maybe you wanted 'values'?\n";
521 }
522 elsif( $type ne "ARRAY" ) {
523 0 die "Cannot 'elems' of a non-ARRAY\n";
524 }
525  
526 0 ▶ my $startidx = $opts{start} // 0;
Condition0%0/2
$opts{"start"} // 0
l!l
00
MC/DC0%0/1
$opts{"start"} // 0
$opts{"start"}
Truth table0%0/2
A
A= $opts{"start"}
Aresult
11
00
527 0 my $stopidx = min( $startidx + $opts{count}, $av->n_elems );
528  
529 0 my @rows;
530 0 foreach my $idx ( $startidx .. $stopidx-1 ) {
531 0 my $sv = $av->elem( $idx );
532 0 ▶ push @rows, [
Branch: 1 branch
BranchTrueFalseTotal
$sv ? : 0 0 0
533 Devel::MAT::Cmd->format_value( $idx, index => 1 ),
534 $sv ? Devel::MAT::Cmd->format_sv_with_value( $sv ) : "NULL",
535 ];
536 }
537  
538 0 Devel::MAT::Cmd->print_table( \@rows, indent => 2 );
539  
540 0 my $morecount = $av->n_elems - $stopidx;
541 0 ▶ Devel::MAT::Cmd->printf( " ... (%d more)\n", $morecount ) if $morecount;
Branch: 1 branch
BranchTrueFalseTotal
if $morecount 0 0 0
542 }
543  
544 package # hide
545 Devel::MAT::Tool::Show::_values;
546 5 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
547  
548 5 ▶use constant CMD => "values";
Subroutine BEGIN: called CC=1 SCAR=0.0
549 5 ▶use constant CMD_DESC => "List the values of a HASH-like SV";
Subroutine BEGIN: called CC=1 SCAR=0.0
550  
551 =head2 values
552  
553 pmat> values defstash
554 {"\b"} GLOB($%*) at 0x562e93114eb8
555 {"\017"} GLOB($*) at 0x562e9315a428
556 ...
557  
558 Prints values of a HASH or STASH SV.
559  
560 Takes the following named options:
561  
562 =over 4
563  
564 =item --count, -c MAX
565  
566 Show at most this number of values (default 50).
567  
568 =item --skip, -s COUNT
569  
570 Skip over this number of keys initially before starting to print.
571  
572 =item --no-sort, -n
573  
574 Don't bother to sort keys before printing. Keys will be printed in no
575 particular order (though the order will at least be stable between successive
576 invocations of the command during the same session).
577  
578 =back
579  
580 Takes the following positional arguments:
581  
582 =over 4
583  
584 =item *
585  
586 Optional filter pattern. If present, will only count and display keys matching
587 the given regexp. Must be specified in the form C</PATTERN/> with optional
588 trailing flags. The only permitted flags are C<adilmsux>.
589  
590 =back
591  
592 =cut
593  
594 5 ▶use constant CMD_OPTS => (
Subroutine BEGIN: called CC=1 SCAR=0.0
595 count => { help => "maximum count of values to print",
596 type => "i",
597 alias => "c",
598 default => 50 },
599 skip => { help => "count of keys to skip initially before printing",
600 type => "i",
601 alias => "s" },
602 no_sort => { help => "don't sort keys before printing",
603 alias => "n" },
604 hek => { help => "also show HEK pointers",
605 alias => "H" },
606 5 );
607  
608 5 ▶use constant CMD_ARGS_SV => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
609 5 ▶use constant CMD_ARGS => (
Subroutine BEGIN: called CC=1 SCAR=0.0
610 { name => "filter", help => "optional pattern to filter keys by" },
611 5 );
612  
613 0 ▶sub run ( $self, $optsref, $hv, $filter = undef )
Subroutine run: not called CC=9 SCAR=45.0
614 0 {
615 0 my %opts = $optsref->%*;
616  
617 0 my $type = $hv->type;
618 0 ▶ if( $type eq "ARRAY" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 0 0 0
elsif ($type ne 'HASH' and $type ne 'STASH') { } 0 0 0
619 0 die "Cannot 'values' of a $type - maybe you wanted 'elems'?\n";
620 }
621 ▶ elsif( $type ne "HASH" and $type ne "STASH" ) {
Condition0%0/3
$type ne "HASH" and $type ne "STASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$type ne "HASH" and $type ne "STASH"
$type ne "HASH" $type ne "STASH"
Truth table0%0/3
A and B
A= $type ne "HASH"B= $type ne "STASH"
ABresult
0X0
100
111
622 0 die "Cannot 'elems' of a non-HASHlike\n";
623 }
624  
625 0 my $skipcount = $opts{skip};
626 0 my $show_heks = $opts{hek};
627  
628 0 my @keys = $hv->keys;
629 0 ▶ if( length $filter ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $filter) 0 0 0
630 0 ▶ $filter =~ m/^\/(.*)\/([adilmsux]*)$/ or
Branch: 1 branch
BranchTrueFalseTotal
$filter =~ m[^/(.*)/([adilmsux]*)$]u or die "Filter must be a /PATTERN.../ with optional flags" 0 0 0
631 die "Filter must be a /PATTERN.../ with optional flags";
632 0 my ( $pattern, $flags ) = ( $1, $2 );
633 0 my $re = qr/(?$flags:$pattern)/;
634 0 @keys = grep { $_ =~ $re } @keys;
635 }
636 0 ▶ @keys = sort @keys unless $opts{no_sort};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"no_sort"} 0 0 0
637 0 ▶ splice @keys, 0, $skipcount if $skipcount;
Branch: 1 branch
BranchTrueFalseTotal
if $skipcount 0 0 0
638  
639 0 ▶ Devel::MAT::Tool::more->paginate( { pagesize => $opts{count} }, sub ( $count ) {
Subroutine __ANON__: not called CC=6 SCAR=37.4
640 0 my @rows;
641 0 foreach my $key ( splice @keys, 0, $count ) {
642 0 my $sv = $hv->value( $key );
643 0 ▶ my $hek = $show_heks ? $hv->hek_at( $key ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$show_heks ? : 0 0 0
644  
645 0 ▶ push @rows, [
Branch: 2 branches
BranchTrueFalseTotal
$hek ? : 0 0 0
$sv ? : 0 0 0
646 Devel::MAT::Cmd->format_value( $key, key => 1,
647 stash => ( $type eq "STASH" ) ),
648 ( $hek ? "HEK at " . Devel::MAT::Cmd->format_value( $hek, addr => 1 ) : () ),
649 $sv ? Devel::MAT::Cmd->format_sv_with_value( $sv ) : "NULL",
650 ];
651 }
652  
653 0 Devel::MAT::Cmd->print_table( \@rows, indent => 2 );
654  
655 0 my $morecount = @keys;
656 0 ▶ Devel::MAT::Cmd->printf( " ... (%d more)\n", $morecount ) if $morecount;
Branch: 1 branch
BranchTrueFalseTotal
if $morecount 0 0 0
657 0 return $morecount;
658 0 } );
659 }
660  
661 =head1 AUTHOR
662  
663 Paul Evans <leonerd@leonerd.org.uk>
664  
665 =cut
666  
667 5 0x55AA;
« blib/lib/Devel/MAT/Tool/Callers.pm ↑ Summary blib/lib/Devel/MAT/Tool/Reachability.pm »