line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Scalar::IfDefined; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
1182300
|
use 5.006; |
|
5
|
|
|
|
|
20
|
|
4
|
5
|
|
|
5
|
|
28
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
105
|
|
5
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
204
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
25
|
use Scalar::Util qw/blessed reftype/; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
440
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
25
|
use Exporter 'import'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1630
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ifdef $ifdef lifdef/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub ifdef(&$) { |
17
|
9
|
|
|
9
|
1
|
620
|
scalar &lifdef; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub lifdef (&$) { |
22
|
13
|
|
|
13
|
1
|
1611
|
my ($block, $scalar) = @_; |
23
|
13
|
100
|
|
|
|
66
|
return if not defined $scalar; |
24
|
5
|
|
|
|
|
23
|
return $block->($scalar) for $scalar; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $ifdef = sub { |
29
|
|
|
|
|
|
|
my $obj = shift; |
30
|
|
|
|
|
|
|
my ($method, @args) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return undef if not defined $obj; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $obj->$method(@args) if blessed $obj or ifdef {$_ eq 'CODE'} reftype($method); |
35
|
|
|
|
|
|
|
return $obj->[$method] if reftype $obj eq 'ARRAY'; |
36
|
|
|
|
|
|
|
return $obj->{$method} if reftype $obj eq 'HASH'; |
37
|
|
|
|
|
|
|
return $obj->($method, @args) if reftype $obj eq 'CODE'; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
die "Can't getdef on " . reftype $obj; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; # End of Scalar::IfDefined |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |