blib/lib/Sub/Info.pm

filter: Statementstmt 100% 41 / 41 Branchbran 81.2% 13 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 92.7% 64 / 69 CC 10 SCAR 19.5
CC
10
Cov
93%
sub_info
10.1
BEGIN
1.0
BEGIN
1.0
CRAP 7.1
↑ Summary
1 package Sub::Info;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '0.002';
6  
7 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use B();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Importer Importer => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT_OK = qw{ sub_info };
12  
13 8 ▶sub sub_info {
Subroutine sub_info: called CC=10 SCAR=23.1
Pod documented
14 8 my ($sub, @all_lines) = @_;
15 8 my %in = map {$_ => 1} @all_lines;
16  
17 8 ▶ croak "sub_info requires a coderef as its first argument"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub eq "CODE" 0 8 8
18 unless ref($sub) eq 'CODE';
19  
20 8 my $cobj = B::svref_2object($sub);
21 8 my $name = $cobj->GV->NAME;
22 8 my $file = $cobj->FILE;
23 8 my $package = $cobj->GV->STASH->NAME;
24  
25 8 my $op = $cobj->START;
26 8 ▶ while ($op) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op) 54 0 54
27 54 ▶ push @all_lines => $op->line if $op->can('line');
Branch: 1 branch
BranchTrueFalseTotal
if $op->can("line") 16 38 54
28 54 ▶ last unless $op->can('next');
Branch: 1 branch
BranchTrueFalseTotal
unless $op->can("next") 8 46 54
29 46 $op = $op->next;
30 }
31  
32 8 my ($start, $end, @lines);
33 8 ▶ if (@all_lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@all_lines) 8 0 8
34 8 @all_lines = sort { $a <=> $b } @all_lines;
35 8 ($start, $end) = ($all_lines[0], $all_lines[-1]);
36  
37 # Adjust start and end for the most common case of a multi-line block with
38 # parens on the lines before and after.
39 8 ▶ if ($start < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start < $end) 4 4 8
40 4 ▶ $start-- unless $start <= 1 || $in{$start};
Branch: 1 branch
BranchTrueFalseTotal
unless $start <= 1 or $in{$start} 2 2 4
Condition66%2/3
$start <= 1 or $in{$start}
l!l&&r!l&&!r
202
MC/DC50%1/2
$start <= 1 or $in{$start}
$start <= 1 $in{$start}
Truth table66%2/3
A or B
A= $start <= 1B= $in{$start}
ABresult
1X1
011
000
41 4 ▶ $end++ unless $in{$end};
Branch: 1 branch
BranchTrueFalseTotal
unless $in{$end} 2 2 4
42 }
43 8 @lines = ($start, $end);
44 }
45  
46 return {
47 8 ref => $sub,
48 cobj => $cobj,
49 name => $name,
50 file => $file,
51 package => $package,
52 start_line => $start,
53 end_line => $end,
54 all_lines => \@all_lines,
55 lines => \@lines,
56 };
57 }
58  
59 1 1;
60  
61 __END__
↑ Summary