line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::Sub; |
2
|
169
|
|
|
169
|
|
1165
|
use strict; |
|
169
|
|
|
|
|
429
|
|
|
169
|
|
|
|
|
4719
|
|
3
|
169
|
|
|
169
|
|
851
|
use warnings; |
|
169
|
|
|
|
|
349
|
|
|
169
|
|
|
|
|
6995
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000155'; |
6
|
|
|
|
|
|
|
|
7
|
169
|
|
|
169
|
|
1026
|
use Carp qw/croak carp/; |
|
169
|
|
|
|
|
371
|
|
|
169
|
|
|
|
|
8933
|
|
8
|
169
|
|
|
169
|
|
1311
|
use B(); |
|
169
|
|
|
|
|
461
|
|
|
169
|
|
|
|
|
8526
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
11
|
|
|
|
|
|
|
sub_info |
12
|
|
|
|
|
|
|
sub_name |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
gen_reader gen_writer gen_accessor |
15
|
|
|
|
|
|
|
}; |
16
|
169
|
|
|
169
|
|
1154
|
use base 'Exporter'; |
|
169
|
|
|
|
|
538
|
|
|
169
|
|
|
|
|
115348
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub gen_reader { |
19
|
6
|
|
|
6
|
0
|
21
|
my $field = shift; |
20
|
6
|
|
|
6
|
|
35
|
return sub { $_[0]->{$field} }; |
|
6
|
|
|
|
|
28
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub gen_writer { |
24
|
6
|
|
|
6
|
0
|
11
|
my $field = shift; |
25
|
6
|
|
|
6
|
|
31
|
return sub { $_[0]->{$field} = $_[1] }; |
|
6
|
|
|
|
|
28
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub gen_accessor { |
29
|
9
|
|
|
9
|
0
|
27
|
my $field = shift; |
30
|
|
|
|
|
|
|
return sub { |
31
|
12
|
|
|
12
|
|
16
|
my $self = shift; |
32
|
12
|
100
|
|
|
|
43
|
($self->{$field}) = @_ if @_; |
33
|
12
|
|
|
|
|
62
|
return $self->{$field}; |
34
|
9
|
|
|
|
|
67
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub sub_name { |
38
|
5
|
|
|
5
|
1
|
46
|
my ($sub) = @_; |
39
|
|
|
|
|
|
|
|
40
|
5
|
100
|
|
|
|
440
|
croak "sub_name requires a coderef as its only argument" |
41
|
|
|
|
|
|
|
unless ref($sub) eq 'CODE'; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
9
|
my $cobj = B::svref_2object($sub); |
44
|
2
|
|
|
|
|
13
|
my $name = $cobj->GV->NAME; |
45
|
2
|
|
|
|
|
16
|
return $name; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub sub_info { |
49
|
1471
|
|
|
1471
|
1
|
9545
|
my ($sub, @all_lines) = @_; |
50
|
1471
|
|
|
|
|
2821
|
my %in = map {$_ => 1} @all_lines; |
|
0
|
|
|
|
|
0
|
|
51
|
|
|
|
|
|
|
|
52
|
1471
|
50
|
|
|
|
5982
|
croak "sub_info requires a coderef as its first argument" |
53
|
|
|
|
|
|
|
unless ref($sub) eq 'CODE'; |
54
|
|
|
|
|
|
|
|
55
|
1471
|
|
|
|
|
5263
|
my $cobj = B::svref_2object($sub); |
56
|
1471
|
|
|
|
|
6739
|
my $name = $cobj->GV->NAME; |
57
|
1471
|
|
|
|
|
6861
|
my $file = $cobj->FILE; |
58
|
1471
|
|
|
|
|
5725
|
my $package = $cobj->GV->STASH->NAME; |
59
|
|
|
|
|
|
|
|
60
|
1471
|
|
|
|
|
5975
|
my $op = $cobj->START; |
61
|
1471
|
|
|
|
|
3738
|
while ($op) { |
62
|
27803
|
100
|
|
|
|
67867
|
push @all_lines => $op->line if $op->can('line'); |
63
|
27803
|
100
|
|
|
|
60309
|
last unless $op->can('next'); |
64
|
26332
|
|
|
|
|
78481
|
$op = $op->next; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1471
|
|
|
|
|
2475
|
my ($start, $end, @lines); |
68
|
1471
|
50
|
|
|
|
2998
|
if (@all_lines) { |
69
|
1471
|
|
|
|
|
3874
|
@all_lines = sort { $a <=> $b } @all_lines; |
|
4057
|
|
|
|
|
6014
|
|
70
|
1471
|
|
|
|
|
2988
|
($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
|
1471
|
100
|
|
|
|
3177
|
if ($start < $end) { |
75
|
430
|
50
|
33
|
|
|
2259
|
$start-- unless $start <= 1 || $in{$start}; |
76
|
430
|
50
|
|
|
|
1104
|
$end++ unless $in{$end}; |
77
|
|
|
|
|
|
|
} |
78
|
1471
|
|
|
|
|
3705
|
@lines = ($start, $end); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return { |
82
|
1471
|
|
|
|
|
16566
|
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
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |