blib/lib/Devel/MAT/Tool.pm

filter: Statementstmt 41.6% 45 / 108 Branchbran 5.0% 3 / 60 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 66.6% 16 / 24 Podpod 0.0% 0 / 10 totaltotal 27.0% 64 / 237 CC 43 SCAR 52.4
CC
43
Cov
25%
get_opts_from_inv
491.0
get_args_from_inv
72.0
get_sv_from_inv
55.9
CRAP 189.1
« blib/lib/Devel/MAT/Tool/Count.pm ↑ Summary blib/lib/Devel/MAT/Tool/Callers.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::Tool 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 10 ▶use Syntax::Keyword::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 ▶use List::Util qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Commandable::Invocation;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 Commandable::Invocation->VERSION( '0.04' ); # ->peek_remaining
19  
20 4 ▶sub new ( $class, $pmat, %args )
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
21 {
22 my $self = bless {
23 pmat => $pmat,
24 df => $pmat->dumpfile,
25 progress => $args{progress},
26 4 }, $class;
27  
28 4 ▶ $self->init_tool if $self->can( 'init_tool' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("init_tool") 2 2 4
29  
30 4 return $self;
31 }
32  
33 0 ▶sub pmat ( $self )
Subroutine pmat: not called CC=1 SCAR=6.9
Pod undocumented
34 {
35 0 return $self->{pmat};
36 }
37  
38 2 ▶sub df ( $self )
Subroutine df: called CC=1 SCAR=0.0
Pod undocumented
39 {
40 2 return $self->{df};
41 }
42  
43 26 ▶sub report_progress ( $self, @args )
Subroutine report_progress: called CC=2 SCAR=7.6
Pod undocumented
44 {
45 26 ▶ $self->{progress}->( @args ) if $self->{progress};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"progress"} 0 26 26
46 }
47  
48 0 ▶sub get_sv_from_inv ( $self, $inv )
Subroutine get_sv_from_inv: not called CC=9 SCAR=40.2
Pod undocumented
49 {
50 0 ▶ my $sv = Devel::MAT::UI->can( "current_sv" ) && Devel::MAT::UI->current_sv;
Condition0%0/3
'Devel::MAT::UI'->can('current_sv') && 'Devel::MAT::UI'->current_sv
!ll&&!rl&&r
000
MC/DC0%0/2
'Devel::MAT::UI'->can('current_sv') && 'Devel::MAT::UI'->current_sv
'Devel::MAT::UI'->can('current_sv') 'Devel::MAT::UI'->current_sv
Truth table0%0/3
A && B
A= 'Devel::MAT::UI'->can('current_sv')B= 'Devel::MAT::UI'->current_sv
ABresult
0X0
100
111
51  
52 0 ▶ if( defined( my $addr = $inv->pull_token ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $addr = $inv->pull_token)) 0 0 0
53 # Acccept any root name symbolically
54 0 ▶ if( any { $addr eq $_ } Devel::MAT::Dumpfile->ROOTS ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
if (&any(sub { $addr eq $_; } , 'Devel::MAT::Dumpfile'->ROOTS)) { } 0 0 0
elsif ($addr =~ /^[\$\@\%\&]/u) { } 0 0 0
55 0 $sv = $self->df->$addr;
56 }
57 # Accept named symbols
58 elsif( $addr =~ m/^[\$\@\%\&]/ ) {
59 0 $sv = $self->pmat->find_symbol( $addr );
60 }
61 else {
62 0 ▶ $addr = do {
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /^0x/u 0 0 0
63 10 ▶ no warnings 'portable';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 0 hex $addr;
65 } if $addr =~ m/^0x/;
66  
67 0 ▶ do { no warnings 'numeric'; $addr eq $addr+0 } or
Subroutine BEGIN: called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} $addr eq $addr + 0 } or die "Expected numerical SV address\n" 0 0 0
68 die "Expected numerical SV address\n";
69  
70 0 ▶ $sv = $self->df->sv_at( $addr ) or
Branch: 1 branch
BranchTrueFalseTotal
$sv = $self->df->sv_at($addr) or die sprintf("No such SV at address %x\n", $addr) 0 0 0
71 die sprintf "No such SV at address %x\n", $addr;
72 }
73 }
74  
75 0 ▶ $sv or die "Need an SV address\n";
Branch: 1 branch
BranchTrueFalseTotal
$sv or die "Need an SV address\n" 0 0 0
76  
77 0 return $sv;
78 }
79  
80 # Some empty defaults
81 10 ▶use constant CMD_OPTS => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
82 10 ▶use constant CMD_ARGS_SV => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 10 ▶use constant CMD_ARGS => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 0 ▶sub find_subcommand ( $self, $subname )
Subroutine find_subcommand: not called CC=1 SCAR=6.9
Pod undocumented
86 {
87 # TODO: sanity check
88  
89 return ( ref($self) . "::" . $subname )->new( $self->pmat,
90 progress => $self->{progress},
91 0 );
92 }
93  
94 0 ▶sub parse_cmd ( $self, $inv )
Subroutine parse_cmd: not called CC=4 SCAR=30.0
Pod undocumented
95 {
96 0 my @args;
97  
98 0 ▶ if( my %optspec = $self->CMD_OPTS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%optspec) = $self->CMD_OPTS) 0 0 0
99 0 push @args, $self->get_opts_from_inv( $inv, \%optspec );
100 }
101  
102 0 ▶ if( $self->CMD_ARGS_SV ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->CMD_ARGS_SV) 0 0 0
103 0 push @args, $self->get_sv_from_inv( $inv );
104 }
105  
106 0 ▶ if( my @argspec = $self->CMD_ARGS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@argspec) = $self->CMD_ARGS) 0 0 0
107 0 push @args, $self->get_args_from_inv( $inv, @argspec );
108 }
109  
110 0 return @args;
111 }
112  
113 0 ▶sub run_cmd ( $self, $inv )
Subroutine run_cmd: not called CC=1 SCAR=6.9
Pod undocumented
114 {
115 0 $self->run( $self->parse_cmd( $inv ) );
116 }
117  
118 0 ▶sub get_opts_from_inv ( $self, $inv, $optspec, %args )
Subroutine get_opts_from_inv: not called CC=23 SCAR=62.0
Pod undocumented
119 {
120 0 ▶ my $permute = $args{permute} // 1;
Condition0%0/2
$args{"permute"} // 1
l!l
00
MC/DC0%0/1
$args{"permute"} // 1
$args{"permute"}
Truth table0%0/2
A
A= $args{"permute"}
Aresult
11
00
121  
122 0 my %opts;
123 my %aliases;
124  
125 0 foreach my $name ( keys %$optspec ) {
126 0 my $spec = $optspec->{$name};
127  
128 0 $opts{$name} = $spec->{default};
129  
130 0 ▶ $aliases{ $spec->{alias} } = $name if defined $spec->{alias};
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"alias"} 0 0 0
131 }
132  
133 0 my @remaining;
134  
135 0 ▶ while( defined( my $opt = $inv->pull_token ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $opt = $inv->pull_token)) 0 0 0
136 0 ▶ last if $opt eq "--";
Branch: 1 branch
BranchTrueFalseTotal
if $opt eq "--" 0 0 0
137  
138 0 ▶ if( $opt =~ m/^--(.*)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt =~ /^--(.*)$/u) { } 0 0 0
elsif ($opt =~ /^-(.)$/u) { } 0 0 0
139 0 $opt = $1;
140 }
141 elsif( $opt =~ m/^-(.)$/ ) {
142 0 ▶ $opt = $aliases{$1} or die "No such option '-$1'\n";
Branch: 1 branch
BranchTrueFalseTotal
$opt = $aliases{$1} or die "No such option '-$1'\n" 0 0 0
143 }
144 else {
145 0 push @remaining, $opt;
146  
147 0 ▶ last if !$permute;
Branch: 1 branch
BranchTrueFalseTotal
unless $permute 0 0 0
148 0 next;
149 }
150  
151 0 ▶ my $spec = $optspec->{$opt} or die "No such option '--$opt'\n";
Branch: 1 branch
BranchTrueFalseTotal
my $spec = $optspec->{$opt} or die "No such option '--${opt}'\n" 0 0 0
152  
153 0 my $val;
154 match( $spec->{type} // "" : eq ) {
155 case( "" ) {
156 0 ▶ $val = 1;
Branch: 1 branch
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq 's' ? : 0 0 0
157 }
158 case( "s" ) {
159 0 ▶ defined( $val = $inv->pull_token ) or
Branch: 1 branch
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq 'i' ? : 0 0 0
Condition0%0/2
defined($val = $inv->pull_token) or die "Option --$opt requires a value\n"
l!l
00
MC/DC0%0/1
defined($val = $inv->pull_token) or die "Option --$opt requires a value\n"
defined($val = $inv->pull_token)
Truth table0%0/2
A
A= defined($val = $inv->pull_token)
Aresult
11
00
160 die "Option --$opt requires a value\n";
161 }
162 case( "i" ) {
163 0 ▶ defined( $val = $inv->pull_token ) or
Condition0%0/2
defined($val = $inv->pull_token) or die "Option --$opt requires a value\n"
l!l
00
MC/DC0%0/1
defined($val = $inv->pull_token) or die "Option --$opt requires a value\n"
defined($val = $inv->pull_token)
Truth table0%0/2
A
A= defined($val = $inv->pull_token)
Aresult
11
00
164 die "Option --$opt requires a value\n";
165 0 ▶ $val =~ m/^-?\d+$/ or
Branch: 1 branch
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq 'x' ? : 0 0 0
Condition0%0/2
$val =~ /^-?\d+$/u or die "Option --$opt value '${val}' is not a number\n"
l!l
00
MC/DC0%0/1
$val =~ /^-?\d+$/u or die "Option --$opt value '${val}' is not a number\n"
$val =~ /^-?\d+$/u
Truth table0%0/2
A
A= $val =~ /^-?\d+$/u
Aresult
11
00
166 die "Option --$opt value '$val' is not a number\n";
167 }
168 case( "x" ) {
169 0 ▶ defined( $val = $inv->pull_token ) or
Condition0%0/2
defined($val = $inv->pull_token) or die "Option --$opt requires a value\n"
l!l
00
MC/DC0%0/1
defined($val = $inv->pull_token) or die "Option --$opt requires a value\n"
defined($val = $inv->pull_token)
Truth table0%0/2
A
A= defined($val = $inv->pull_token)
Aresult
11
00
170 die "Option --$opt requires a value\n";
171 0 ▶ $val =~ m/^-?\d+$/ or $val =~ m/^0x[0-9a-f]+$/i or
Condition0%0/5
$val =~ /^-?\d+$/u or $val =~ /^0x[0-9a-f]+$/iu or die "Option --$opt value '${val}' is not a (hex)number\n"
l!l
00
$val =~ /^-?\d+$/u or $val =~ /^0x[0-9a-f]+$/iu
l!l&&r!l&&!r
000
MC/DC0%0/2
$val =~ /^-?\d+$/u or $val =~ /^0x[0-9a-f]+$/iu or die "Option --$opt value '${val}' is not a (hex)number\n"
$val =~ /^-?\d+$/u $val =~ /^0x[0-9a-f]+$/iu
Truth table0%0/3
A or B
A= $val =~ /^-?\d+$/uB= $val =~ /^0x[0-9a-f]+$/iu
ABresult
1X1
011
000
172 die "Option --$opt value '$val' is not a (hex)number\n";
173 10 ▶ no warnings 'portable';
Subroutine BEGIN: called CC=1 SCAR=0.0
174 0 ▶ $val = hex $val if $val =~ m/^0x/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^0x/u 0 0 0
175 }
176 0 ▶ default {
Branch: 1 branch
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq '' ? : 0 0 0
Condition0%0/2
$spec->{"type"} // ""
l!l
00
MC/DC0%0/1
$spec->{"type"} // ""
$spec->{"type"}
Truth table0%0/2
A
A= $spec->{"type"}
Aresult
11
00
177 0 die "TODO: unrecognised type $_\n";
178 }
179 }
180  
181 0 $opts{$opt} = $val;
182 }
183  
184 0 $inv->putback_tokens( @remaining );
185  
186 0 return \%opts;
187 }
188  
189 0 ▶sub get_args_from_inv ( $self, $inv, @argspec )
Subroutine get_args_from_inv: not called CC=8 SCAR=42.8
Pod undocumented
190 {
191 0 my @args;
192  
193 0 foreach my $argspec ( @argspec ) {
194 0 my $val = $inv->pull_token;
195 defined $val or !$argspec->{required} or
196 0 ▶ die "Expected a value for '$argspec->{name}' argument\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $val or not $argspec->{"required"} or die qq[Expected a value for '$argspec->{"name"}' argument\n] 0 0 0
Condition0%0/3
defined $val or not $argspec->{"required"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $val or not $argspec->{"required"}
defined $val not $argspec->{"required"}
Truth table0%0/3
A or not(B)
A= defined $valB= not $argspec->{"required"}
ABresult
1X1
011
000
197 0 ▶ defined $val or last;
Branch: 1 branch
BranchTrueFalseTotal
defined $val or last 0 0 0
198 0 push @args, $val;
199 0 ▶ if( $argspec->{slurpy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argspec->{"slurpy"}) 0 0 0
200 0 ▶ push @args, $inv->pull_token while length $inv->peek_remaining;
Branch: 1 branch
BranchTrueFalseTotal
length $inv->peek_remaining and do { push @args, $inv->pull_token } 0 0 0
201 }
202 0 ▶ redo if $argspec->{repeated};
Branch: 1 branch
BranchTrueFalseTotal
if $argspec->{"repeated"} 0 0 0
203 }
204  
205 0 return @args;
206 }
207  
208 10 0x55AA;
« blib/lib/Devel/MAT/Tool/Count.pm ↑ Summary blib/lib/Devel/MAT/Tool/Callers.pm »