File Coverage

blib/lib/Safe/Isa.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Safe::Isa;
2              
3 2     2   121919 use strict;
  2         12  
  2         54  
4 2     2   8 use warnings FATAL => 'all';
  2         4  
  2         79  
5 2     2   11 use Scalar::Util ();
  2         3  
  2         50  
6 2     2   9 use Exporter 5.57 qw(import);
  2         33  
  2         638  
7              
8             our $VERSION = '1.000009';
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__