| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$name ||= @items == 1 ? "$thing_name->$op('$items[0]')" : "$thing_name->$op(...)"
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(...)"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 118 | ▶ | unless (defined($thing) && (blessed($thing) || !ref($thing) && length($thing))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $thing and builtin::blessed($thing) || !ref($thing) && length $thing
builtin::blessed($thing) or not ref $thing and length $thing
not ref $thing and length $thing
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | my $thing = defined($thing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $thing or "'${thing}'"
MC/DC100%1/1
ref $thing or "'${thing}'"
ref $thing
Truth table100%2/2
A
A= ref $thing
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
"UNIVERSAL"->can($op) or $thing->can($op)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 375 | ▶ | next if $bool; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||