File Coverage

blib/lib/Devel/MAT/Tool/Outrefs.pm
Criterion Covered Total %
statement 23 40 57.5
branch 0 4 0.0
condition 0 3 0.0
subroutine 8 12 66.6
pod 0 2 0.0
total 31 61 50.8


line stmt bran cond sub pod time code
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 -- leonerd@leonerd.org.uk
5              
6             package Devel::MAT::Tool::Outrefs 0.49;
7              
8 5     5   3173 use v5.14;
  5         17  
9 5     5   24 use warnings;
  5         10  
  5         123  
10 5     5   22 use base qw( Devel::MAT::Tool );
  5         9  
  5         487  
11              
12 5     5   30 use List::UtilsBy qw( sort_by );
  5         10  
  5         234  
13              
14             =head1 NAME
15              
16             C - show SVs referred to by a given SV
17              
18             =head1 COMANDS
19              
20             =cut
21              
22             =head2 outrefs
23              
24             pmat> outrefs defstash
25             ...
26              
27             Shows the outgoing references that refer to other SVs.
28              
29             Takes the following named options:
30              
31             =over 4
32              
33             =item --weak
34              
35             Include weak direct references in the output (by default only strong direct
36             ones will be included).
37              
38             =item --all
39              
40             Include both weak and indirect references in the output.
41              
42             =back
43              
44             =cut
45              
46 5     5   21 use constant CMD => "outrefs";
  5         8  
  5         328  
47 5     5   31 use constant CMD_DESC => "Show outgoing references from a given SV";
  5         10  
  5         304  
48              
49 5         312 use constant CMD_OPTS => (
50             weak => { help => "include weak references" },
51             all => { help => "include weak and indirect references",
52             alias => "a" },
53 5     5   40 );
  5         9  
54              
55 5     5   30 use constant CMD_ARGS_SV => 1;
  5         9  
  5         1747  
56              
57             my %NOTES_BY_STRENGTH = (
58             strong => Devel::MAT::Cmd->format_note( "s" ),
59             weak => Devel::MAT::Cmd->format_note( "w", 1 ),
60             indirect => Devel::MAT::Cmd->format_note( "i", 2 ),
61             inferred => Devel::MAT::Cmd->format_note( "~", 2 ),
62             );
63              
64             sub run
65             {
66 0     0 0   my $self = shift;
67 0           my %opts = %{ +shift };
  0            
68 0           my ( $sv ) = @_;
69              
70             my $method = $opts{all} ? "outrefs" :
71 0 0         $opts{weak} ? "outrefs_direct" :
    0          
72             "outrefs_strong";
73              
74 0           $self->show_refs_by_method( $method, $sv );
75             }
76              
77             sub show_refs_by_method
78             {
79 0     0 0   my $self = shift;
80 0           my ( $method, $sv ) = @_;
81              
82 0     0     my @refs = grep { $_->sv } sort_by { $_->name } $sv->$method;
  0            
  0            
83              
84             Devel::MAT::Tool::more->paginate( sub {
85 0     0     my ( $count ) = @_;
86              
87 0           my @table;
88              
89             my $ref;
90             $ref = shift @refs and
91             push @table, [
92 0   0       $NOTES_BY_STRENGTH{ $ref->strength },
93             $ref->name,
94             Devel::MAT::Cmd->format_sv( $ref->sv ),
95             ] while $count--;
96              
97 0           Devel::MAT::Cmd->print_table( \@table, sep => " " );
98 0           return scalar @refs;
99 0           } );
100             }
101              
102             =head1 AUTHOR
103              
104             Paul Evans
105              
106             =cut
107              
108             0x55AA;
109