line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Safe::Isa; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
196664
|
use strict; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
87
|
|
4
|
2
|
|
|
2
|
|
15
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
132
|
|
5
|
2
|
|
|
2
|
|
17
|
use Scalar::Util (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
90
|
|
6
|
2
|
|
|
2
|
|
16
|
use Exporter 5.57 qw(import); |
|
2
|
|
|
|
|
57
|
|
|
2
|
|
|
|
|
1016
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.000010'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw($_call_if_object $_isa $_can $_does $_DOES $_call_if_can); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $_call_if_object = sub { |
13
|
|
|
|
|
|
|
my ($obj, $method) = (shift, shift); |
14
|
|
|
|
|
|
|
# This is intentionally a truth test, not a defined test, otherwise |
15
|
|
|
|
|
|
|
# we gratuitously break modules like Scalar::Defer, which would be |
16
|
|
|
|
|
|
|
# un-perlish. |
17
|
|
|
|
|
|
|
return unless Scalar::Util::blessed($obj); |
18
|
|
|
|
|
|
|
return $obj->$method(@_); |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our ($_isa, $_can) = map { |
22
|
|
|
|
|
|
|
my $method = $_; |
23
|
|
|
|
|
|
|
sub { my $obj = shift; $obj->$_call_if_object($method => @_) } |
24
|
|
|
|
|
|
|
} qw(isa can); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $_call_if_can = sub { |
27
|
|
|
|
|
|
|
my ($obj, $method) = (shift, shift); |
28
|
|
|
|
|
|
|
return unless $obj->$_call_if_object(can => $method); |
29
|
|
|
|
|
|
|
return $obj->$method(@_); |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $_does = sub { |
33
|
|
|
|
|
|
|
my $obj = shift; |
34
|
|
|
|
|
|
|
$obj->$_call_if_can(does => @_); |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $_DOES = sub { |
38
|
|
|
|
|
|
|
my $obj = shift; |
39
|
|
|
|
|
|
|
return unless Scalar::Util::blessed($obj); |
40
|
|
|
|
|
|
|
return $obj->DOES(@_) |
41
|
|
|
|
|
|
|
if $obj->can('DOES'); |
42
|
|
|
|
|
|
|
return $obj->isa(@_); |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
__END__ |