| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Safe::Caller; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69167
|
use strict; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
55
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
60
|
|
|
5
|
2
|
|
|
2
|
|
904
|
use boolean qw(true false); |
|
|
2
|
|
|
|
|
6730
|
|
|
|
2
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
158
|
use Carp qw(croak); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
147
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
13
|
use constant FRAMES => 1; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1466
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
1
|
|
|
1
|
1
|
91
|
my $class = shift; |
|
16
|
1
|
|
|
|
|
3
|
my ($frames) = @_; |
|
17
|
1
|
|
50
|
|
|
14
|
$frames ||= FRAMES; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $caller = sub |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
14
|
|
|
14
|
|
22
|
my ($f, $elem) = @_; |
|
22
|
14
|
100
|
|
|
|
23
|
my $frames = defined $f ? $f : $frames; |
|
23
|
14
|
|
50
|
|
|
101
|
return (caller($frames + 2))[$elem] || ''; |
|
24
|
1
|
|
|
|
|
6
|
}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# All fields required because we need |
|
27
|
|
|
|
|
|
|
# to retain backwards compatibility. |
|
28
|
1
|
|
|
|
|
9
|
my @sets = ( |
|
29
|
|
|
|
|
|
|
[qw(package pkg)], |
|
30
|
|
|
|
|
|
|
[qw(filename file)], |
|
31
|
|
|
|
|
|
|
'line', |
|
32
|
|
|
|
|
|
|
[qw(subroutine sub)], |
|
33
|
|
|
|
|
|
|
'hasargs', |
|
34
|
|
|
|
|
|
|
'wantarray', |
|
35
|
|
|
|
|
|
|
'evaltext', |
|
36
|
|
|
|
|
|
|
'is_require', |
|
37
|
|
|
|
|
|
|
'hints', |
|
38
|
|
|
|
|
|
|
'bitmask' |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
my %fields; |
|
42
|
1
|
|
|
|
|
2
|
my $i = 0; |
|
43
|
1
|
|
|
|
|
4
|
foreach my $set (@sets) { |
|
44
|
10
|
100
|
|
|
|
18
|
foreach my $name (ref $set eq 'ARRAY' ? @$set : $set) { |
|
45
|
13
|
|
|
|
|
26
|
$fields{$name} = $i; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
10
|
|
|
|
|
12
|
$i++; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
2
|
my $accessors = {}; |
|
51
|
1
|
|
|
|
|
5
|
foreach my $name (keys %fields) { |
|
52
|
|
|
|
|
|
|
$accessors->{$name} = sub |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
14
|
|
|
14
|
|
54
|
my $frames = shift; |
|
55
|
14
|
|
|
|
|
50
|
return $caller->($frames, $fields{$name}); |
|
56
|
13
|
|
|
|
|
41
|
}; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
1
|
|
|
|
|
3
|
$accessors->{_frames} = $frames; |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
33
|
|
|
8
|
return bless $accessors, ref($class) || $class; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub called_from_package |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
2
|
|
|
2
|
1
|
3839
|
my $self = shift; |
|
66
|
2
|
|
|
|
|
5
|
my ($called_from_package) = @_; |
|
67
|
2
|
50
|
|
|
|
6
|
croak q(Usage: $caller->called_from_package('Package');) |
|
68
|
|
|
|
|
|
|
unless defined $called_from_package; |
|
69
|
|
|
|
|
|
|
|
|
70
|
2
|
50
|
|
|
|
4
|
return $self->{package}->() eq $called_from_package |
|
71
|
|
|
|
|
|
|
? true : false; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub called_from_filename |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
2
|
|
|
2
|
1
|
29
|
my $self = shift; |
|
77
|
2
|
|
|
|
|
4
|
my ($called_from_filename) = @_; |
|
78
|
2
|
50
|
|
|
|
5
|
croak q(Usage: $caller->called_from_filename('file');) |
|
79
|
|
|
|
|
|
|
unless defined $called_from_filename; |
|
80
|
|
|
|
|
|
|
|
|
81
|
2
|
50
|
|
|
|
6
|
return $self->{filename}->() eq $called_from_filename |
|
82
|
|
|
|
|
|
|
? true : false; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub called_from_line |
|
86
|
|
|
|
|
|
|
{ |
|
87
|
1
|
|
|
1
|
1
|
8
|
my $self = shift; |
|
88
|
1
|
|
|
|
|
2
|
my ($called_from_line) = @_; |
|
89
|
1
|
50
|
33
|
|
|
12
|
croak q(Usage: $caller->called_from_line(42);) |
|
90
|
|
|
|
|
|
|
unless defined $called_from_line && $called_from_line =~ /^\d+$/; |
|
91
|
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
3
|
return $self->{line}->() == $called_from_line |
|
93
|
|
|
|
|
|
|
? true : false; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub called_from_subroutine |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
2
|
|
|
2
|
1
|
9
|
my $self = shift; |
|
99
|
2
|
|
|
|
|
4
|
my ($called_from_subroutine) = @_; |
|
100
|
2
|
50
|
|
|
|
3
|
croak q(Usage: $caller->called_from_subroutine('Package::sub');) |
|
101
|
|
|
|
|
|
|
unless defined $called_from_subroutine; |
|
102
|
|
|
|
|
|
|
|
|
103
|
2
|
50
|
|
|
|
5
|
return $self->{subroutine}->($self->{_frames} + 1) eq $called_from_subroutine |
|
104
|
|
|
|
|
|
|
? true : false; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# backwards compatibility (deprecated) |
|
108
|
|
|
|
|
|
|
*called_from_pkg = \&called_from_package; |
|
109
|
|
|
|
|
|
|
*called_from_file = \&called_from_filename; |
|
110
|
|
|
|
|
|
|
*called_from_sub = \&called_from_subroutine; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
__END__ |