blib/lib/Test2/Tools/Class.pm

filter: Statementstmt 100% 66 / 66 Branchbran 94.4% 17 / 18 Conditioncond 88.2% 15 / 17 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 94.9% 113 / 119 CC 18 SCAR 24.5
CC
18
Cov
97%
__ANON__
17.0
BEGIN
2.0
BEGIN
1.0
CRAP 11.6
« lib/Test/Tester.pm ↑ Summary blib/lib/Test2/IPC/Driver/Files.pm »
1 package Test2::Tools::Class;
2 166 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 166 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 166 our $VERSION = '1.302226';
6  
7 166 ▶use Test2::API qw/context/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 166 ▶use Test2::Util::Ref qw/render_ref/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 166 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 166 our @EXPORT = qw/can_ok isa_ok DOES_ok/;
13 166 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # For easier grepping
16 # sub isa_ok is defined here
17 # sub can_ok is defined here
18 # sub DOES_ok is defined here
19 166 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
20 166 for my $op (qw/isa can DOES/) {
21 118 ▶ my $sub = sub($;@) {
Subroutine __ANON__: called CC=17 SCAR=28.3
22 118 my ($thing, @args) = @_;
23 118 my $ctx = context();
24  
25 118 my (@items, $name);
26 118 ▶ if (ref($args[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq 'ARRAY') { } 21 97 118
27 21 $name = $args[1];
28 21 @items = @{$args[0]};
29 }
30 else {
31 97 @items = @args;
32 }
33  
34 118 ▶ my $thing_name = ref($thing) ? render_ref($thing) : defined($thing) ? "$thing" : "<undef>";
Branch: 2 branches
BranchTrueFalseTotal
ref $thing ? : 82 36 118
defined $thing ? : 35 1 36
35 118 $thing_name =~ s/\n/\\n/g;
36 118 $thing_name =~ s/#//g;
37 118 $thing_name =~ s/\(0x[a-f0-9]+\)//gi;
38  
39 118 ▶ $name ||= @items == 1 ? "$thing_name\->$op('$items[0]')" : "$thing_name\->$op(...)";
Branch: 1 branch
BranchTrueFalseTotal
@items == 1 ? : 60 37 97
Condition66%2/3
$name ||= @items == 1 ? "$thing_name->$op('$items[0]')" : "$thing_name->$op(...)"
l!l&&r!l&&!r
21970
MC/DC0%0/2
$name ||= @items == 1 ? "$thing_name->$op('$items[0]')" : "$thing_name->$op(...)"
$name @items == 1 ? "$thing_name->$op('$items[0]')" : "$thing_name->$op(...)"
Truth table66%2/3
A ||= B
A= $nameB= @items == 1 ? "$thing_name->$op('$items[0]')" : "$thing_name->$op(...)"
ABresult
1X1
011
000
40  
41 118 ▶ unless (defined($thing) && (blessed($thing) || !ref($thing) && length($thing))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $thing and builtin::blessed($thing) || !ref($thing) && length $thing) 3 115 118
Condition100%9/9
defined $thing and builtin::blessed($thing) || !ref($thing) && length $thing
!ll&&!rl&&r
12115
builtin::blessed($thing) or not ref $thing and length $thing
l!l&&r!l&&!r
81342
not ref $thing and length $thing
!ll&&!rl&&r
1134
MC/DC100%4/4
defined $thing and builtin::blessed($thing) || !ref($thing) && length $thing
defined $thing builtin::blessed($thing) not ref $thing length $thing
Truth table100%5/5
A and B or not(C) and D
A= defined $thingB= builtin::blessed($thing)C= not ref $thingD= length $thing
ABCDresult
0XXX0
100X0
10100
11XX1
10111
42 3 ▶ my $thing = defined($thing)
Branch: 1 branch
BranchTrueFalseTotal
defined $thing ? : 2 1 3
Condition100%2/2
ref $thing or "'${thing}'"
l!l
11
MC/DC100%1/1
ref $thing or "'${thing}'"
ref $thing
Truth table100%2/2
A
A= ref $thing
Aresult
11
00
43 ? ref($thing) || "'$thing'"
44 : '<undef>';
45  
46 3 $ctx->ok(0, $name, ["$thing is neither a blessed reference or a package name."]);
47  
48 3 $ctx->release;
49 3 return 0;
50 }
51  
52 115 ▶ unless(UNIVERSAL->can($op) || $thing->can($op)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("UNIVERSAL"->can($op) or $thing->can($op)) 1 114 115
Condition66%2/3
"UNIVERSAL"->can($op) or $thing->can($op)
l!l&&r!l&&!r
11401
MC/DC50%1/2
"UNIVERSAL"->can($op) or $thing->can($op)
"UNIVERSAL"->can($op) $thing->can($op)
Truth table66%2/3
A or B
A= "UNIVERSAL"->can($op)B= $thing->can($op)
ABresult
1X1
011
000
53 1 $ctx->skip($name, "'$op' is not supported on this platform");
54 1 $ctx->release;
55 1 return 1;
56 }
57  
58 114 my $file = $ctx->trace->file;
59 114 my $line = $ctx->trace->line;
60  
61 114 my @bad;
62 114 for my $item (@items) {
63 375 my ($bool, $ok, $err);
64  
65 {
66 375 local ($@, $!);
67 375 $ok = eval qq/#line $line "$file"\n\$bool = \$thing->$op(\$item); 1/;
68 375 $err = $@;
69 }
70  
71 375 ▶ die $err unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 375 375
72 375 ▶ next if $bool;
Branch: 1 branch
BranchTrueFalseTotal
if $bool 360 15 375
73  
74 15 push @bad => $item;
75 }
76  
77 114 $ctx->ok( !@bad, $name, [map { "Failed: $thing_name\->$op('$_')" } @bad]);
78  
79 114 $ctx->release;
80  
81 114 return !@bad;
82 498 };
83  
84 166 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 498 *{$op . "_ok"} = $sub;
86 }
87 }
88  
89 166 1;
90  
91 __END__
« lib/Test/Tester.pm ↑ Summary blib/lib/Test2/IPC/Driver/Files.pm »