| 1 | package Util::Underscore::References; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: Functions for introspecting and manipulating references | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | ## no critic (ProhibitMultiplePackages) | ||||||||||||||||||||||||||||||||||||||||||
| 10 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||
| 11 | _; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | ## no critic (RequireArgUnpacking, RequireFinalReturn, ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | sub ref_addr(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | goto &Scalar::Util::refaddr; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref_addr: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub ref_type(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 141 | ▶ | goto &Scalar::Util::reftype; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # perl 5.10 thinks reftype qr// eq 'SCALAR'. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # This is bogus, we'll have to correct that. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | if ($^V < 5.011) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=12.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 12 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | *ref_type = sub (_) { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $type = &Scalar::Util::reftype; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | return 'REGEXP' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $type and $type eq "SCALAR" and ref $_[0] eq "Regexp"
defined $type and $type eq "SCALAR"
MC/DC0%0/3
defined $type and $type eq "SCALAR" and ref $_[0] eq "Regexp"
defined $type
$type eq "SCALAR"
ref $_[0] eq "Regexp"
Truth table0%0/4
A and B and C
A= defined $typeB= $type eq "SCALAR"C= ref $_[0] eq "Regexp"
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | if defined $type | ||||||||||||||||||||||||||||||||||||||||||
| 32 | and $type eq 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | and ref $_[0] eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $type; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | sub ref_weaken(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | goto &Scalar::Util::weaken; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref_weaken: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | sub ref_unweaken(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | goto &Scalar::Util::unweaken; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref_unweaken: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | sub ref_is_weak(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | goto &Scalar::Util::isweak; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref_is_weak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | sub is_ref(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | ▶ | defined($_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ref: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%3/3
defined $_[0] and defined &ref_type($_[0])
MC/DC100%2/2
defined $_[0] and defined &ref_type($_[0])
defined $_[0]
defined &ref_type($_[0])
Truth table100%3/3
A and B
A= defined $_[0]B= defined &ref_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | && defined ref_type $_[0] | ||||||||||||||||||||||||||||||||||||||||||
| 54 | && !defined blessed $_[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | sub is_scalar_ref(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | defined($_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 60 | (defined blessed $_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ? overload::Method($_[0], q[${}]) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_scalar_ref: called CC=5 SCAR=16.1
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | ▶ | my $type = ref_type $_[0] // q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
&ref_type($_[0]) // ""
MC/DC100%1/1
&ref_type($_[0]) // ""
&ref_type($_[0])
Truth table100%2/2
A
A= &ref_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 9 | ▶ | $type eq 'SCALAR' || $type eq 'REF'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | sub is_array_ref(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | ▶ | defined($_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_array_ref: called CC=4 SCAR=13.9
Branch: 2 branches
Condition100%2/2
&ref_type($_[0]) // ""
MC/DC100%1/1
&ref_type($_[0]) // ""
&ref_type($_[0])
Truth table100%2/2
A
A= &ref_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 72 | (defined blessed $_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ? overload::Method($_[0], q[@{}]) | ||||||||||||||||||||||||||||||||||||||||||
| 74 | : (ref_type $_[0] // q[]) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub is_hash_ref(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 12 | ▶ | defined($_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_hash_ref: called CC=4 SCAR=13.9
Branch: 2 branches
Condition100%2/2
&ref_type($_[0]) // ""
MC/DC100%1/1
&ref_type($_[0]) // ""
&ref_type($_[0])
Truth table100%2/2
A
A= &ref_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 81 | (defined blessed $_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ? overload::Method($_[0], q[%{}]) | ||||||||||||||||||||||||||||||||||||||||||
| 83 | : (ref_type $_[0] // q[]) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | sub is_code_ref(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | ▶ | defined($_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_code_ref: called CC=4 SCAR=13.9
Branch: 2 branches
Condition100%2/2
&ref_type($_[0]) // ""
MC/DC100%1/1
&ref_type($_[0]) // ""
&ref_type($_[0])
Truth table100%2/2
A
A= &ref_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 90 | (defined blessed $_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ? overload::Method($_[0], q[&{}]) | ||||||||||||||||||||||||||||||||||||||||||
| 92 | : (ref_type $_[0] // q[]) eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | sub is_glob_ref(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | ▶ | defined($_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_glob_ref: called CC=4 SCAR=13.9
Branch: 2 branches
Condition100%2/2
&ref_type($_[0]) // ""
MC/DC100%1/1
&ref_type($_[0]) // ""
&ref_type($_[0])
Truth table100%2/2
A
A= &ref_type($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 99 | (defined blessed $_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ? overload::Method($_[0], q[*{}]) | ||||||||||||||||||||||||||||||||||||||||||
| 101 | : (ref_type $_[0] // q[]) eq 'GLOB' | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub is_regex(_) { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | ▶ | defined(blessed $_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_regex: called CC=3 SCAR=11.3
Branch: 1 branch
Condition66%4/6
defined &blessed($_[0]) && ('REGEXP' eq &ref_type($_[0]) || overload::Method($_[0], 'qr'))
"REGEXP" eq &ref_type($_[0]) or overload::Method($_[0], "qr")
MC/DC33%1/3
defined &blessed($_[0]) && ('REGEXP' eq &ref_type($_[0]) || overload::Method($_[0], 'qr'))
defined &blessed($_[0])
"REGEXP" eq &ref_type($_[0])
overload::Method($_[0], "qr")
Truth table75%3/4
A && B or C
A= defined &blessed($_[0])B= "REGEXP" eq &ref_type($_[0])C= overload::Method($_[0], "qr")
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | && ('REGEXP' eq ref_type $_[0] | ||||||||||||||||||||||||||||||||||||||||||
| 108 | || overload::Method($_[0], q[qr])); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||||||||||||