| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 27 | 54 | ▶ | push @all_lines => $op->line if $op->can('line'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 54 | ▶ | last unless $op->can('next'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 46 | $op = $op->next; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 8 | my ($start, $end, @lines); | |||||||||||||||||||||||||||
| 33 | 8 | ▶ | if (@all_lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 40 | 4 | ▶ | $start-- unless $start <= 1 || $in{$start}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$start <= 1 or $in{$start}
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}
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | $end++ unless $in{$end}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||