blib/lib/Devel/MAT/InternalTools.pm

filter: Statementstmt 46.6% 55 / 118 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 62.0% 18 / 29 Podpod n/a totaltotal 38.8% 73 / 188 CC 26 SCAR 44.3
CC
26
Cov
35%
help_cmd
272.0
run
12.0
_join
12.0
CRAP 84.2
« blib/lib/Devel/MAT/Tool/ListDanglingPtrs.pm ↑ Summary blib/lib/Devel/MAT.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-2018 -- leonerd@leonerd.org.uk
5  
6 package Devel::MAT::InternalTools 0.56;
7  
8 10 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use feature qw( postderef signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶no warnings qw( experimental::postderef experimental::signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 package Devel::MAT::Tool::help;
15  
16 10 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 10 ▶use constant CMD => "help";
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶use constant CMD_DESC => "Display a list of available commands";
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 10 ▶use constant CMD_ARGS => (
Subroutine BEGIN: called CC=1 SCAR=0.0
22 { name => "cmdname", help => "name of a command to display more help",
23 slurpy => 1 },
24 10 );
25  
26 0 ▶sub run ( $self, $cmdname = undef, @subnames )
Subroutine run: not called CC=3 SCAR=24.8
27 {
28 0 ▶ if( defined $cmdname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cmdname) { } 0 0 0
29 0 $self->help_cmd( $cmdname, @subnames );
30 }
31 else {
32 0 $self->help_summary;
33 }
34 }
35  
36 0 ▶sub help_summary ( $self )
Subroutine help_summary: not called CC=2 SCAR=17.9
37 {
38 0 my $pmat = $self->{pmat};
39  
40 my @commands = sort map {
41 0 my $class = "Devel::MAT::Tool::$_";
42 0 ▶ $class->can( "CMD" ) ? [ $class->CMD => $class->CMD_DESC ] : ()
Branch: 1 branch
BranchTrueFalseTotal
$class->can('CMD') ? : 0 0 0
43 } $pmat->available_tools;
44  
45 Devel::MAT::Cmd->print_table(
46 [
47 map { [
48 0 Devel::MAT::Cmd->format_note( $_->[0] ),
49 $_->[1],
50 0 ] } sort { $a->[0] cmp $b->[0] } @commands
51 ],
52 sep => " - ",
53 );
54 }
55  
56 # A join() that respects stringify overloading
57 0 ▶sub _join ( $sep, $ret = "", @s )
Subroutine _join: not called CC=3 SCAR=24.8
58 {
59 0 $ret .= "$sep$_" for @s;
60 0 return $ret;
61 }
62  
63 0 ▶sub help_cmd ( $self, $cmdname, @subnames )
Subroutine help_cmd: not called CC=16 SCAR=56.1
64 {
65 0 my $fullname = join " ", $cmdname, @subnames;
66  
67 0 my $tool = $self->{pmat}->load_tool_for_command( $cmdname );
68 0 $tool = $tool->find_subcommand( $_ ) for @subnames;
69  
70 0 Devel::MAT::Cmd->printf( "%s - %s\n",
71 Devel::MAT::Cmd->format_note( $fullname ),
72 $tool->CMD_DESC,
73 );
74  
75 0 ▶ if( my $code = $tool->can( "help_cmd" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $tool->can("help_cmd")) 0 0 0
76 0 $tool->$code();
77 0 return;
78 }
79  
80 0 my %optspec = $tool->CMD_OPTS;
81 0 my @argspec = $tool->CMD_ARGS;
82  
83 0 Devel::MAT::Cmd->printf( "\nSYNOPSIS:\n" );
84 Devel::MAT::Cmd->printf( " %s\n", join " ",
85 $fullname,
86 %optspec ? "[OPTIONS...]" : (),
87 $tool->CMD_ARGS_SV ? "[SV ADDR]" : (),
88 0 ▶ @argspec ? ( map { "\$\U$_->{name}" } @argspec ) : (),
Branch: 3 branches
BranchTrueFalseTotal
%optspec ? : 0 0 0
$tool->CMD_ARGS_SV ? : 0 0 0
@argspec ? : 0 0 0
89 );
90  
91 0 ▶ if( %optspec ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%optspec) 0 0 0
92 0 Devel::MAT::Cmd->printf( "\nOPTIONS:\n" );
93  
94 Devel::MAT::Cmd->print_table(
95 [ map {
96 0 my $optname = $_;
97 0 my $opt = $optspec{$_};
98  
99 0 my @names = $optname;
100 0 ▶ push @names, $opt->{alias} if $opt->{alias};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"alias"} 0 0 0
101 0 s/_/-/g for @names;
102  
103 my $synopsis = _join ", ", map {
104 0 ▶ Devel::MAT::Cmd->format_note( length > 1 ? "--$_" : "-$_", 1 )
Branch: 1 branch
BranchTrueFalseTotal
length $_ > 1 ? : 0 0 0
105 } @names;
106  
107 0 ▶ if( my $type = $opt->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $opt->{"type"}) 0 0 0
108 0 ▶ $synopsis .= " INT" if $type eq "i";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "i" 0 0 0
109 0 ▶ $synopsis .= " STR" if $type eq "s";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "s" 0 0 0
110 }
111  
112 0 [ $synopsis, $opt->{help} ],
113 } sort keys %optspec ],
114 sep => " ",
115 indent => 2,
116 );
117 }
118  
119 0 ▶ if( @argspec ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@argspec) 0 0 0
120 0 Devel::MAT::Cmd->printf( "\nARGUMENTS:\n" );
121  
122 Devel::MAT::Cmd->print_table(
123 [ map {
124 0 my $arg = $_;
125  
126 [ "\$\U$arg->{name}" . ( $arg->{slurpy} ? "..." :
127 0 ▶ $arg->{repeated} ? "*" : "" ), $arg->{help} ],
Branch: 2 branches
BranchTrueFalseTotal
$arg->{'slurpy'} ? : 0 0 0
$arg->{'repeated'} ? : 0 0 0
128 } @argspec ],
129 sep => " ",
130 indent => 2,
131 );
132 }
133 }
134  
135 package Devel::MAT::Tool::more;
136  
137 10 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 10 ▶use constant CMD => "more";
Subroutine BEGIN: called CC=1 SCAR=0.0
140 10 ▶use constant CMD_DESC => "Continue the previous listing";
Subroutine BEGIN: called CC=1 SCAR=0.0
141  
142 10 my $more;
143  
144 0 ▶sub run ( $self )
Subroutine run: not called CC=3 SCAR=24.8
145 {
146 0 ▶ if( $more ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more) { } 0 0 0
147 0 ▶ $more->() or undef $more;
Branch: 1 branch
BranchTrueFalseTotal
&$more() or undef $more 0 0 0
148 }
149 else {
150 0 Devel::MAT::Cmd->printf( "%s\n", Devel::MAT::Cmd->format_note( "No more" ) );
151 }
152 }
153  
154 0 ▶sub paginate ( $self, @args )
Subroutine paginate: not called CC=3 SCAR=24.8
155 {
156 0 ▶ my $opts = ( ref $args[0] eq "HASH" ) ? shift @args : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 0 0 0
157 0 my ( $func ) = @args;
158  
159 0 ▶ $more = sub () { $func->( $opts->{pagesize} // 30 ) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$opts->{"pagesize"} // 30
l!l
00
MC/DC0%0/1
$opts->{"pagesize"} // 30
$opts->{"pagesize"}
Truth table0%0/2
A
A= $opts->{"pagesize"}
Aresult
11
00
160  
161 0 ▶ $more->() or undef $more;
Branch: 1 branch
BranchTrueFalseTotal
&$more() or undef $more 0 0 0
162 }
163  
164 0 ▶sub stop ( $self )
Subroutine stop: not called CC=1 SCAR=6.9
165 {
166 0 undef $more;
167 }
168  
169 0 ▶sub can_more ( $self )
Subroutine can_more: not called CC=1 SCAR=6.9
170 {
171 0 return defined $more;
172 }
173  
174 package Devel::MAT::Tool::stop;
175  
176 10 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
177  
178 10 ▶use constant CMD => "stop";
Subroutine BEGIN: called CC=1 SCAR=0.0
179 10 ▶use constant CMD_DESC => "Stops pagination";
Subroutine BEGIN: called CC=1 SCAR=0.0
180  
181 0 ▶sub run ( $self )
Subroutine run: not called CC=1 SCAR=6.9
182 {
183 0 Devel::MAT::Tool::more->stop;
184 }
185  
186 package Devel::MAT::Tool::time;
187  
188 10 ▶use base qw( Devel::MAT::Tool );
Subroutine BEGIN: called CC=1 SCAR=0.0
189  
190 10 ▶use constant CMD => "time";
Subroutine BEGIN: called CC=1 SCAR=0.0
191 10 ▶use constant CMD_DESC => "Measure the runtime of a command";
Subroutine BEGIN: called CC=1 SCAR=0.0
192  
193 10 ▶use Time::HiRes qw( gettimeofday tv_interval );
Subroutine BEGIN: called CC=1 SCAR=0.0
194  
195 0 ▶sub run_cmd ( $self, $inv )
Subroutine run_cmd: not called CC=1 SCAR=6.9
196 {
197 0 my $cmd = $inv->pull_token;
198  
199 0 my $starttime = [gettimeofday];
200  
201 0 my $tool = $self->pmat->load_tool_for_command( $cmd );
202 0 my $loadtime = tv_interval( $starttime );
203  
204 0 $tool->run_cmd( $inv );
205  
206 0 my $runtime = tv_interval( $starttime );
207  
208 0 Devel::MAT::Cmd->printf( "\nLoaded in %.03fs, ran in %.03fs\n",
209 $loadtime, $runtime - $loadtime,
210 );
211 }
212  
213 10 0x55AA;
« blib/lib/Devel/MAT/Tool/ListDanglingPtrs.pm ↑ Summary blib/lib/Devel/MAT.pm »