blib/lib/Test2/Util/Ref.pm

filter: Statementstmt 100% 36 / 36 Branchbran 94.4% 17 / 18 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 93.1% 68 / 73 CC 13 SCAR 17.4
CC
13
Cov
95%
rtype
7.1
render_ref
7.0
BEGIN
1.0
CRAP 5.7
« blib/lib/Test2/Tools/AsyncSubtest.pm ↑ Summary blib/lib/Test2/Event/V2.pm »
1 package Test2::Util::Ref;
2 177 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 177 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 177 our $VERSION = '1.302226';
6  
7 177 ▶use Scalar::Util qw/reftype blessed refaddr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 177 our @EXPORT_OK = qw/rtype render_ref/;
10 177 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 23161 ▶sub rtype {
Subroutine rtype: called CC=7 SCAR=19.7
Pod documented
13 23161 my ($thing) = @_;
14 23161 ▶ return '' unless defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 2 23159 23161
15  
16 23159 my $rf = ref $thing;
17 23159 my $rt = reftype $thing;
18  
19 23159 ▶ return '' unless $rf || $rt;
Branch: 1 branch
BranchTrueFalseTotal
unless $rf or $rt 17302 5857 23159
Condition66%2/3
$rf or $rt
l!l&&r!l&&!r
5857017302
MC/DC50%1/2
$rf or $rt
$rf $rt
Truth table66%2/3
A or B
A= $rfB= $rt
ABresult
1X1
011
000
20 5857 ▶ return 'REGEXP' if $rf =~ m/Regex/i;
Branch: 1 branch
BranchTrueFalseTotal
if $rf =~ /Regex/i 272 5585 5857
21 5585 ▶ return 'REGEXP' if $rt =~ m/Regex/i;
Branch: 1 branch
BranchTrueFalseTotal
if $rt =~ /Regex/i 0 5585 5585
22 5585 ▶ return $rt || '';
Condition50%1/2
$rt || ''
l!l
55850
MC/DC0%0/1
$rt || ''
$rt
Truth table50%1/2
A
A= $rt
Aresult
11
00
23 }
24  
25 14999 ▶sub render_ref {
Subroutine render_ref: called CC=7 SCAR=19.5
Pod documented
26 14999 my ($in) = @_;
27  
28 14999 ▶ return 'undef' unless defined($in);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 307 14692 14999
29  
30 14692 my $type = rtype($in);
31 14692 ▶ return "$in" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 10082 4610 14692
32  
33 # Look past overloading
34 4610 ▶ my $class = blessed($in) || '';
Condition100%2/2
builtin::blessed($in) || ''
l!l
24932117
MC/DC100%1/1
builtin::blessed($in) || ''
builtin::blessed($in)
Truth table100%2/2
A
A= builtin::blessed($in)
Aresult
11
00
35  
36 4610 my $it = sprintf('0x%x', refaddr($in));
37 4610 my $ref = "$type($it)";
38  
39 4610 ▶ return $ref unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 2117 2493 4610
40  
41 2493 my $out = "$class=$ref";
42 2493 ▶ if ($class =~ m/bool/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /bool/i) 8 2485 2493
43 8 ▶ my $bool = $in ? 'TRUE' : 'FALSE';
Branch: 1 branch
BranchTrueFalseTotal
$in ? : 4 4 8
44 8 return "<$bool: $out>";
45 }
46 2485 return $out;
47 }
48  
49 177 1;
50  
51 __END__
« blib/lib/Test2/Tools/AsyncSubtest.pm ↑ Summary blib/lib/Test2/Event/V2.pm »