File Coverage

blib/lib/Util/Underscore/References.pm
Criterion Covered Total %
statement 24 28 85.7
branch 27 30 90.0
condition 15 22 68.1
subroutine 16 16 100.0
pod n/a
total 82 96 85.4


line stmt bran cond sub pod time code
1             package Util::Underscore::References;
2              
3             #ABSTRACT: Functions for introspecting and manipulating references
4              
5 12     12   36 use strict;
  12         10  
  12         260  
6 12     12   35 use warnings;
  12         13  
  12         802  
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     8   1517 goto &Scalar::Util::refaddr;
17             }
18              
19             sub ref_type(_) {
20 141     141   3275 goto &Scalar::Util::reftype;
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 50   12   4552 if ($^V < 5.011) {
27 12     12   36 no warnings 'redefine';
  12         13  
  12         857  
28             *ref_type = sub (_) {
29 0         0 my $type = &Scalar::Util::reftype;
30 0 0 0     0 return 'REGEXP'
      0        
31             if defined $type
32             and $type eq 'SCALAR'
33             and ref $_[0] eq 'Regexp';
34 0         0 return $type;
35 0         0 };
36             }
37             }
38              
39             sub ref_weaken(_) {
40 3     3   1607 goto &Scalar::Util::weaken;
41             }
42              
43             sub ref_unweaken(_) {
44 2     2   6 goto &Scalar::Util::unweaken;
45             }
46              
47             sub ref_is_weak(_) {
48 9     9   3279 goto &Scalar::Util::isweak;
49             }
50              
51             sub is_ref(_) {
52 18 100 100 18   2830 defined($_[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 100   13   3542 : do {
    100          
63 9   100     12 my $type = ref_type $_[0] // q[];
64 9 100       46 $type eq 'SCALAR' || $type eq 'REF';
65             }
66             );
67             }
68              
69             sub is_array_ref(_) {
70 16 100 100 16   2106 defined($_[0])
    100          
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 100 100 12   2064 defined($_[0])
    100          
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 100 100 12   2116 defined($_[0])
    100          
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 100 100 12   2062 defined($_[0])
    100          
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 100 66 12   1995 defined(blessed $_[0])
107             && ('REGEXP' eq ref_type $_[0]
108             || overload::Method($_[0], q[qr]));
109             }
110              
111             1;
112              
113             __END__