| 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, 2020-2026 -- leonerd@leonerd.org.uk | ||||||||||||||
| 5 | |||||||||||||||
| 6 | package Devel::MAT::Tool::Outrefs 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::UtilsBy qw( sort_by ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 NAME | ||||||||||||||
| 18 | |||||||||||||||
| 19 | C<Devel::MAT::Tool::Outrefs> - show SVs referred to by a given SV | ||||||||||||||
| 20 | |||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||
| 22 | |||||||||||||||
| 23 | This C<Devel::MAT> tool provides a command to list the other SVs that a given | ||||||||||||||
| 24 | SV retains a reference to. | ||||||||||||||
| 25 | |||||||||||||||
| 26 | =head1 COMANDS | ||||||||||||||
| 27 | |||||||||||||||
| 28 | =for highlighter | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =cut | ||||||||||||||
| 31 | |||||||||||||||
| 32 | =head2 outrefs | ||||||||||||||
| 33 | |||||||||||||||
| 34 | pmat> outrefs defstash | ||||||||||||||
| 35 | ... | ||||||||||||||
| 36 | |||||||||||||||
| 37 | Shows the outgoing references that refer to other SVs. | ||||||||||||||
| 38 | |||||||||||||||
| 39 | Takes the following named options: | ||||||||||||||
| 40 | |||||||||||||||
| 41 | =over 4 | ||||||||||||||
| 42 | |||||||||||||||
| 43 | =item --weak | ||||||||||||||
| 44 | |||||||||||||||
| 45 | Include weak direct references in the output (by default only strong direct | ||||||||||||||
| 46 | ones will be included). | ||||||||||||||
| 47 | |||||||||||||||
| 48 | =item --all | ||||||||||||||
| 49 | |||||||||||||||
| 50 | Include both weak and indirect references in the output. | ||||||||||||||
| 51 | |||||||||||||||
| 52 | =back | ||||||||||||||
| 53 | |||||||||||||||
| 54 | =cut | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 5 | ▶ | use constant CMD => "outrefs"; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 57 | 5 | ▶ | use constant CMD_DESC => "Show outgoing references from a given SV"; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 58 | |||||||||||||||
| 59 | 5 | ▶ | use constant CMD_OPTS => ( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 60 | weak => { help => "include weak references" }, | ||||||||||||||
| 61 | all => { help => "include weak and indirect references", | ||||||||||||||
| 62 | alias => "a" }, | ||||||||||||||
| 63 | 5 | ); | |||||||||||||
| 64 | |||||||||||||||
| 65 | 5 | ▶ | use constant CMD_ARGS_SV => 1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 5 | my %NOTES_BY_STRENGTH = ( | |||||||||||||
| 68 | strong => Devel::MAT::Cmd->format_note( "s" ), | ||||||||||||||
| 69 | weak => Devel::MAT::Cmd->format_note( "w", 1 ), | ||||||||||||||
| 70 | indirect => Devel::MAT::Cmd->format_note( "i", 2 ), | ||||||||||||||
| 71 | inferred => Devel::MAT::Cmd->format_note( "~", 2 ), | ||||||||||||||
| 72 | ); | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | ▶ | sub run ( $self, $optsref, $sv ) | ||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 75 | { | ||||||||||||||
| 76 | 0 | my %opts = $optsref->%*; | |||||||||||||
| 77 | |||||||||||||||
| 78 | my $method = $opts{all} ? "outrefs" : | ||||||||||||||
| 79 | 0 | ▶ | $opts{weak} ? "outrefs_direct" : | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 80 | "outrefs_strong"; | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | $self->show_refs_by_method( $method, $sv ); | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | ▶ | sub show_refs_by_method ( $self, $method, $sv ) | ||||||||||||
|
Subroutine
show_refs_by_method: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 86 | { | ||||||||||||||
| 87 | 0 | ▶ | my @refs = grep { $_->sv } sort_by { $_->name } $sv->$method; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 88 | |||||||||||||||
| 89 | 0 | ▶ | Devel::MAT::Tool::more->paginate( sub ( $count ) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||
| 90 | 0 | my @table; | |||||||||||||
| 91 | |||||||||||||||
| 92 | my $ref; | ||||||||||||||
| 93 | $ref = shift @refs and | ||||||||||||||
| 94 | push @table, [ | ||||||||||||||
| 95 | 0 | ▶ | $NOTES_BY_STRENGTH{ $ref->strength }, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 96 | $ref->name, | ||||||||||||||
| 97 | Devel::MAT::Cmd->format_sv( $ref->sv ), | ||||||||||||||
| 98 | ] while $count--; | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | Devel::MAT::Cmd->print_table( \@table, sep => " " ); | |||||||||||||
| 101 | 0 | return scalar @refs; | |||||||||||||
| 102 | 0 | } ); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | =head1 AUTHOR | ||||||||||||||
| 106 | |||||||||||||||
| 107 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||
| 108 | |||||||||||||||
| 109 | =cut | ||||||||||||||
| 110 | |||||||||||||||
| 111 | 5 | 0x55AA; | |||||||||||||
| 112 | |||||||||||||||