| 1 | package Scalar::IfDefined; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Scalar::Util qw/blessed reftype/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | our @EXPORT_OK = qw/ifdef $ifdef/; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub ifdef(&$) { | ||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my ($block, $scalar) = @_; | ||||||||||||||||||||||||||
|
Subroutine
ifdef: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | return $scalar if not defined $scalar; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | return $block->($scalar) for $scalar; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | our $ifdef = sub { | ||||||||||||||||||||||||||||
| 25 | 12 | ▶ | my $obj = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.8
| |||||||||||||||||||||||||||||
| 26 | 12 | my ($method, @args) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 12 | ▶ | return undef if not defined $obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | return $obj->$method(@args) if blessed $obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 7 | my $methtype = reftype($method); | |||||||||||||||||||||||||||
| 33 | 7 | ▶ | return $obj->$method(@args) if defined($methtype) and $methtype eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $methtype and $methtype eq "CODE"
MC/DC50%1/2
defined $methtype and $methtype eq "CODE"
defined $methtype
$methtype eq "CODE"
Truth table66%2/3
A and B
A= defined $methtypeB= $methtype eq "CODE"
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | ▶ | return $obj->[$method] if reftype $obj eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 4 | ▶ | return $obj->{$method} if reftype $obj eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return $obj->($method, @args) if reftype $obj eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | die "Can't getdef on " . reftype $obj; | |||||||||||||||||||||||||||
| 40 | 5 | }; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | 1; # End of Scalar::IfDefined | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | __END__ | ||||||||||||||||||||||||||||