line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Safe::Caller; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13261
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
49
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
5
|
2
|
|
|
2
|
|
755
|
use boolean qw(true false); |
|
2
|
|
|
|
|
4735
|
|
|
2
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
121
|
use Carp qw(croak); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
107
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.08_03'; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
8
|
use constant FRAMES => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
985
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
1
|
|
|
1
|
1
|
10
|
my $class = shift; |
16
|
1
|
|
|
|
|
2
|
my ($frames) = @_; |
17
|
1
|
|
50
|
|
|
5
|
$frames ||= FRAMES; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $caller = sub |
20
|
|
|
|
|
|
|
{ |
21
|
14
|
|
|
14
|
|
14
|
my ($f, $elem) = @_; |
22
|
14
|
100
|
|
|
|
14
|
my $frames = defined $f ? $f : $frames; |
23
|
14
|
|
50
|
|
|
102
|
return (caller($frames + 2))[$elem] || ''; |
24
|
1
|
|
|
|
|
5
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# All fields required because we need |
27
|
|
|
|
|
|
|
# to retain backwards compatibility. |
28
|
1
|
|
|
|
|
6
|
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
|
|
|
|
|
1
|
my $i = 0; |
43
|
1
|
|
|
|
|
3
|
foreach my $set (@sets) { |
44
|
10
|
100
|
|
|
|
14
|
foreach my $name (ref $set eq 'ARRAY' ? @$set : $set) { |
45
|
13
|
|
|
|
|
17
|
$fields{$name} = $i; |
46
|
|
|
|
|
|
|
} |
47
|
10
|
|
|
|
|
8
|
$i++; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
1
|
my $accessors = {}; |
51
|
1
|
|
|
|
|
5
|
foreach my $name (keys %fields) { |
52
|
|
|
|
|
|
|
$accessors->{$name} = sub |
53
|
|
|
|
|
|
|
{ |
54
|
14
|
|
|
14
|
|
40
|
my $frames = shift; |
55
|
14
|
|
|
|
|
16
|
return $caller->($frames, $fields{$name}); |
56
|
13
|
|
|
|
|
31
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
2
|
$accessors->{_frames} = $frames; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
33
|
|
|
7
|
return bless $accessors, ref($class) || $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub called_from_package |
64
|
|
|
|
|
|
|
{ |
65
|
2
|
|
|
2
|
1
|
2808
|
my $self = shift; |
66
|
2
|
|
|
|
|
3
|
my ($called_from_package) = @_; |
67
|
2
|
50
|
|
|
|
4
|
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
|
26
|
my $self = shift; |
77
|
2
|
|
|
|
|
3
|
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
|
|
|
|
3
|
return $self->{filename}->() eq $called_from_filename |
82
|
|
|
|
|
|
|
? true : false; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub called_from_line |
86
|
|
|
|
|
|
|
{ |
87
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
88
|
1
|
|
|
|
|
1
|
my ($called_from_line) = @_; |
89
|
1
|
50
|
33
|
|
|
9
|
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
|
7
|
my $self = shift; |
99
|
2
|
|
|
|
|
2
|
my ($called_from_subroutine) = @_; |
100
|
2
|
50
|
|
|
|
5
|
croak q(Usage: $caller->called_from_subroutine('Package::sub');) |
101
|
|
|
|
|
|
|
unless defined $called_from_subroutine; |
102
|
|
|
|
|
|
|
|
103
|
2
|
50
|
|
|
|
38
|
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__ |