line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::Class; |
2
|
158
|
|
|
158
|
|
1401
|
use strict; |
|
158
|
|
|
|
|
348
|
|
|
158
|
|
|
|
|
4417
|
|
3
|
158
|
|
|
158
|
|
756
|
use warnings; |
|
158
|
|
|
|
|
344
|
|
|
158
|
|
|
|
|
6258
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
6
|
|
|
|
|
|
|
|
7
|
158
|
|
|
158
|
|
1430
|
use Test2::API qw/context/; |
|
158
|
|
|
|
|
72183
|
|
|
158
|
|
|
|
|
8326
|
|
8
|
158
|
|
|
158
|
|
1387
|
use Test2::Util::Ref qw/render_ref/; |
|
158
|
|
|
|
|
446
|
|
|
158
|
|
|
|
|
7289
|
|
9
|
|
|
|
|
|
|
|
10
|
158
|
|
|
158
|
|
978
|
use Scalar::Util qw/blessed/; |
|
158
|
|
|
|
|
522
|
|
|
158
|
|
|
|
|
10683
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw/can_ok isa_ok DOES_ok/; |
13
|
158
|
|
|
158
|
|
1176
|
use base 'Exporter'; |
|
158
|
|
|
|
|
334
|
|
|
158
|
|
|
|
|
92669
|
|
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
|
|
|
|
|
|
|
BEGIN { |
20
|
158
|
|
|
158
|
|
594
|
for my $op (qw/isa can DOES/) { |
21
|
|
|
|
|
|
|
my $sub = sub($;@) { |
22
|
106
|
|
|
106
|
|
3795
|
my ($thing, @args) = @_; |
23
|
106
|
|
|
|
|
436
|
my $ctx = context(); |
24
|
|
|
|
|
|
|
|
25
|
106
|
|
|
|
|
15414
|
my (@items, $name); |
26
|
106
|
100
|
|
|
|
384
|
if (ref($args[0]) eq 'ARRAY') { |
27
|
9
|
|
|
|
|
15
|
$name = $args[1]; |
28
|
9
|
|
|
|
|
18
|
@items = @{$args[0]}; |
|
9
|
|
|
|
|
22
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
97
|
|
|
|
|
256
|
@items = @args; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
106
|
100
|
|
|
|
493
|
my $thing_name = ref($thing) ? render_ref($thing) : defined($thing) ? "$thing" : ""; |
|
|
100
|
|
|
|
|
|
35
|
106
|
|
|
|
|
313
|
$thing_name =~ s/\n/\\n/g; |
36
|
106
|
|
|
|
|
208
|
$thing_name =~ s/#//g; |
37
|
106
|
|
|
|
|
521
|
$thing_name =~ s/\(0x[a-f0-9]+\)//gi; |
38
|
|
|
|
|
|
|
|
39
|
106
|
100
|
66
|
|
|
854
|
$name ||= @items == 1 ? "$thing_name\->$op('$items[0]')" : "$thing_name\->$op(...)"; |
40
|
|
|
|
|
|
|
|
41
|
106
|
100
|
100
|
|
|
687
|
unless (defined($thing) && (blessed($thing) || !ref($thing) && length($thing))) { |
|
|
|
100
|
|
|
|
|
42
|
3
|
100
|
66
|
|
|
11
|
my $thing = defined($thing) |
43
|
|
|
|
|
|
|
? ref($thing) || "'$thing'" |
44
|
|
|
|
|
|
|
: ''; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
13
|
$ctx->ok(0, $name, ["$thing is neither a blessed reference or a package name."]); |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
1358
|
$ctx->release; |
49
|
3
|
|
|
|
|
66
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
103
|
100
|
66
|
|
|
657
|
unless(UNIVERSAL->can($op) || $thing->can($op)) { |
53
|
1
|
|
|
|
|
18
|
$ctx->skip($name, "'$op' is not supported on this platform"); |
54
|
1
|
|
|
|
|
261
|
$ctx->release; |
55
|
1
|
|
|
|
|
24
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
102
|
|
|
|
|
419
|
my $file = $ctx->trace->file; |
59
|
102
|
|
|
|
|
1052
|
my $line = $ctx->trace->line; |
60
|
|
|
|
|
|
|
|
61
|
102
|
|
|
|
|
590
|
my @bad; |
62
|
102
|
|
|
|
|
245
|
for my $item (@items) { |
63
|
194
|
|
|
|
|
306
|
my ($bool, $ok, $err); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
194
|
|
|
|
|
299
|
local ($@, $!); |
|
194
|
|
|
|
|
523
|
|
67
|
194
|
|
|
|
|
6925
|
$ok = eval qq/#line $line "$file"\n\$bool = \$thing->$op(\$item); 1/; |
68
|
194
|
|
|
|
|
3310
|
$err = $@; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
194
|
50
|
|
|
|
570
|
die $err unless $ok; |
72
|
194
|
100
|
|
|
|
524
|
next if $bool; |
73
|
|
|
|
|
|
|
|
74
|
15
|
|
|
|
|
31
|
push @bad => $item; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
102
|
|
|
|
|
640
|
$ctx->ok( !@bad, $name, [map { "Failed: $thing_name\->$op('$_')" } @bad]); |
|
15
|
|
|
|
|
59
|
|
78
|
|
|
|
|
|
|
|
79
|
102
|
|
|
|
|
30145
|
$ctx->release; |
80
|
|
|
|
|
|
|
|
81
|
102
|
|
|
|
|
3091
|
return !@bad; |
82
|
474
|
|
|
|
|
5480
|
}; |
83
|
|
|
|
|
|
|
|
84
|
158
|
|
|
158
|
|
1307
|
no strict 'refs'; |
|
158
|
|
|
|
|
444
|
|
|
158
|
|
|
|
|
7230
|
|
85
|
474
|
|
|
|
|
1043
|
*{$op . "_ok"} = $sub; |
|
474
|
|
|
|
|
6928
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |