| 1 | package Test2::Util::Sub; | ||||||||||||||||||||||||||||
| 2 | 176 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 176 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 176 | our $VERSION = '1.302226'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 176 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 176 | ▶ | use B(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 176 | our @EXPORT_OK = qw{ | |||||||||||||||||||||||||||
| 11 | sub_info | ||||||||||||||||||||||||||||
| 12 | sub_name | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | gen_reader gen_writer gen_accessor | ||||||||||||||||||||||||||||
| 15 | }; | ||||||||||||||||||||||||||||
| 16 | 176 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | sub gen_reader { | ||||||||||||||||||||||||||
|
Subroutine
gen_reader: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 6 | my $field = shift; | |||||||||||||||||||||||||||
| 20 | 6 | ▶ | return sub { $_[0]->{$field} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | sub gen_writer { | ||||||||||||||||||||||||||
|
Subroutine
gen_writer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 6 | my $field = shift; | |||||||||||||||||||||||||||
| 25 | 6 | ▶ | return sub { $_[0]->{$field} = $_[1] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 9 | ▶ | sub gen_accessor { | ||||||||||||||||||||||||||
|
Subroutine
gen_accessor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 9 | my $field = shift; | |||||||||||||||||||||||||||
| 30 | 12 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 31 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 12 | ▶ | ($self->{$field}) = @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 12 | return $self->{$field}; | |||||||||||||||||||||||||||
| 34 | 9 | }; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub sub_name { | ||||||||||||||||||||||||||
|
Subroutine
sub_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 5 | my ($sub) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | croak "sub_name requires a coderef as its only argument" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | unless ref($sub) eq 'CODE'; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | my $cobj = B::svref_2object($sub); | |||||||||||||||||||||||||||
| 44 | 2 | my $name = $cobj->GV->NAME; | |||||||||||||||||||||||||||
| 45 | 2 | return $name; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 885 | ▶ | sub sub_info { | ||||||||||||||||||||||||||
|
Subroutine
sub_info: called CC=10 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 885 | my ($sub, @all_lines) = @_; | |||||||||||||||||||||||||||
| 50 | 0 | my %in = map {$_ => 1} @all_lines; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 885 | ▶ | croak "sub_info requires a coderef as its first argument" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | unless ref($sub) eq 'CODE'; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 885 | my $cobj = B::svref_2object($sub); | |||||||||||||||||||||||||||
| 56 | 885 | my $name = $cobj->GV->NAME; | |||||||||||||||||||||||||||
| 57 | 885 | my $file = $cobj->FILE; | |||||||||||||||||||||||||||
| 58 | 885 | my $package = $cobj->GV->STASH->NAME; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 885 | my $op = $cobj->START; | |||||||||||||||||||||||||||
| 61 | 885 | ▶ | while ($op) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 14242 | ▶ | push @all_lines => $op->line if $op->can('line'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 14242 | ▶ | last unless $op->can('next'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 13357 | $op = $op->next; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 885 | my ($start, $end, @lines); | |||||||||||||||||||||||||||
| 68 | 885 | ▶ | if (@all_lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 885 | @all_lines = sort { $a <=> $b } @all_lines; | |||||||||||||||||||||||||||
| 70 | 885 | ($start, $end) = ($all_lines[0], $all_lines[-1]); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Adjust start and end for the most common case of a multi-line block with | ||||||||||||||||||||||||||||
| 73 | # parens on the lines before and after. | ||||||||||||||||||||||||||||
| 74 | 885 | ▶ | if ($start < $end) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 220 | ▶ | $start-- unless $start <= 1 || $in{$start}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$start <= 1 or $in{$start}
MC/DC0%0/2
$start <= 1 or $in{$start}
$start <= 1
$in{$start}
Truth table33%1/3
A or B
A= $start <= 1B= $in{$start}
| |||||||||||||||||||||||||||||
| 76 | 220 | ▶ | $end++ unless $in{$end}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 885 | @lines = ($start, $end); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | return { | ||||||||||||||||||||||||||||
| 82 | 885 | ref => $sub, | |||||||||||||||||||||||||||
| 83 | cobj => $cobj, | ||||||||||||||||||||||||||||
| 84 | name => $name, | ||||||||||||||||||||||||||||
| 85 | file => $file, | ||||||||||||||||||||||||||||
| 86 | package => $package, | ||||||||||||||||||||||||||||
| 87 | start_line => $start, | ||||||||||||||||||||||||||||
| 88 | end_line => $end, | ||||||||||||||||||||||||||||
| 89 | all_lines => \@all_lines, | ||||||||||||||||||||||||||||
| 90 | lines => \@lines, | ||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 176 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||