line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::Class; |
2
|
159
|
|
|
159
|
|
1593
|
use strict; |
|
159
|
|
|
|
|
352
|
|
|
159
|
|
|
|
|
4868
|
|
3
|
159
|
|
|
159
|
|
806
|
use warnings; |
|
159
|
|
|
|
|
339
|
|
|
159
|
|
|
|
|
6668
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000155'; |
6
|
|
|
|
|
|
|
|
7
|
159
|
|
|
159
|
|
1522
|
use Test2::API qw/context/; |
|
159
|
|
|
|
|
72205
|
|
|
159
|
|
|
|
|
9555
|
|
8
|
159
|
|
|
159
|
|
1608
|
use Test2::Util::Ref qw/render_ref/; |
|
159
|
|
|
|
|
365
|
|
|
159
|
|
|
|
|
8242
|
|
9
|
|
|
|
|
|
|
|
10
|
159
|
|
|
159
|
|
1043
|
use Scalar::Util qw/blessed/; |
|
159
|
|
|
|
|
352
|
|
|
159
|
|
|
|
|
11509
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw/can_ok isa_ok DOES_ok/; |
13
|
159
|
|
|
159
|
|
1156
|
use base 'Exporter'; |
|
159
|
|
|
|
|
607
|
|
|
159
|
|
|
|
|
100475
|
|
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
|
159
|
|
|
159
|
|
756
|
for my $op (qw/isa can DOES/) { |
21
|
|
|
|
|
|
|
my $sub = sub($;@) { |
22
|
106
|
|
|
106
|
|
4678
|
my ($thing, @args) = @_; |
23
|
106
|
|
|
|
|
499
|
my $ctx = context(); |
24
|
|
|
|
|
|
|
|
25
|
106
|
|
|
|
|
16578
|
my (@items, $name); |
26
|
106
|
100
|
|
|
|
436
|
if (ref($args[0]) eq 'ARRAY') { |
27
|
9
|
|
|
|
|
14
|
$name = $args[1]; |
28
|
9
|
|
|
|
|
16
|
@items = @{$args[0]}; |
|
9
|
|
|
|
|
23
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
97
|
|
|
|
|
275
|
@items = @args; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
106
|
100
|
|
|
|
527
|
my $thing_name = ref($thing) ? render_ref($thing) : defined($thing) ? "$thing" : ""; |
|
|
100
|
|
|
|
|
|
35
|
106
|
|
|
|
|
342
|
$thing_name =~ s/\n/\\n/g; |
36
|
106
|
|
|
|
|
242
|
$thing_name =~ s/#//g; |
37
|
106
|
|
|
|
|
556
|
$thing_name =~ s/\(0x[a-f0-9]+\)//gi; |
38
|
|
|
|
|
|
|
|
39
|
106
|
100
|
66
|
|
|
949
|
$name ||= @items == 1 ? "$thing_name\->$op('$items[0]')" : "$thing_name\->$op(...)"; |
40
|
|
|
|
|
|
|
|
41
|
106
|
100
|
100
|
|
|
739
|
unless (defined($thing) && (blessed($thing) || !ref($thing) && length($thing))) { |
|
|
|
100
|
|
|
|
|
42
|
3
|
100
|
66
|
|
|
22
|
my $thing = defined($thing) |
43
|
|
|
|
|
|
|
? ref($thing) || "'$thing'" |
44
|
|
|
|
|
|
|
: ''; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
15
|
$ctx->ok(0, $name, ["$thing is neither a blessed reference or a package name."]); |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
1685
|
$ctx->release; |
49
|
3
|
|
|
|
|
83
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
103
|
100
|
66
|
|
|
669
|
unless(UNIVERSAL->can($op) || $thing->can($op)) { |
53
|
1
|
|
|
|
|
26
|
$ctx->skip($name, "'$op' is not supported on this platform"); |
54
|
1
|
|
|
|
|
308
|
$ctx->release; |
55
|
1
|
|
|
|
|
26
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
102
|
|
|
|
|
523
|
my $file = $ctx->trace->file; |
59
|
102
|
|
|
|
|
1169
|
my $line = $ctx->trace->line; |
60
|
|
|
|
|
|
|
|
61
|
102
|
|
|
|
|
681
|
my @bad; |
62
|
102
|
|
|
|
|
272
|
for my $item (@items) { |
63
|
194
|
|
|
|
|
350
|
my ($bool, $ok, $err); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
194
|
|
|
|
|
320
|
local ($@, $!); |
|
194
|
|
|
|
|
577
|
|
67
|
194
|
|
|
|
|
7700
|
$ok = eval qq/#line $line "$file"\n\$bool = \$thing->$op(\$item); 1/; |
68
|
194
|
|
|
|
|
3882
|
$err = $@; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
194
|
50
|
|
|
|
583
|
die $err unless $ok; |
72
|
194
|
100
|
|
|
|
565
|
next if $bool; |
73
|
|
|
|
|
|
|
|
74
|
15
|
|
|
|
|
38
|
push @bad => $item; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
102
|
|
|
|
|
657
|
$ctx->ok( !@bad, $name, [map { "Failed: $thing_name\->$op('$_')" } @bad]); |
|
15
|
|
|
|
|
74
|
|
78
|
|
|
|
|
|
|
|
79
|
102
|
|
|
|
|
29442
|
$ctx->release; |
80
|
|
|
|
|
|
|
|
81
|
102
|
|
|
|
|
3424
|
return !@bad; |
82
|
477
|
|
|
|
|
6236
|
}; |
83
|
|
|
|
|
|
|
|
84
|
159
|
|
|
159
|
|
1303
|
no strict 'refs'; |
|
159
|
|
|
|
|
371
|
|
|
159
|
|
|
|
|
8166
|
|
85
|
477
|
|
|
|
|
1074
|
*{$op . "_ok"} = $sub; |
|
477
|
|
|
|
|
7374
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |