line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::Class; |
2
|
159
|
|
|
159
|
|
1554
|
use strict; |
|
159
|
|
|
|
|
349
|
|
|
159
|
|
|
|
|
5299
|
|
3
|
159
|
|
|
159
|
|
848
|
use warnings; |
|
159
|
|
|
|
|
308
|
|
|
159
|
|
|
|
|
7449
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000156'; |
6
|
|
|
|
|
|
|
|
7
|
159
|
|
|
159
|
|
1692
|
use Test2::API qw/context/; |
|
159
|
|
|
|
|
78522
|
|
|
159
|
|
|
|
|
8796
|
|
8
|
159
|
|
|
159
|
|
1425
|
use Test2::Util::Ref qw/render_ref/; |
|
159
|
|
|
|
|
455
|
|
|
159
|
|
|
|
|
8063
|
|
9
|
|
|
|
|
|
|
|
10
|
159
|
|
|
159
|
|
1044
|
use Scalar::Util qw/blessed/; |
|
159
|
|
|
|
|
627
|
|
|
159
|
|
|
|
|
12074
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw/can_ok isa_ok DOES_ok/; |
13
|
159
|
|
|
159
|
|
1114
|
use base 'Exporter'; |
|
159
|
|
|
|
|
515
|
|
|
159
|
|
|
|
|
102105
|
|
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
|
|
638
|
for my $op (qw/isa can DOES/) { |
21
|
|
|
|
|
|
|
my $sub = sub($;@) { |
22
|
106
|
|
|
106
|
|
4192
|
my ($thing, @args) = @_; |
23
|
106
|
|
|
|
|
388
|
my $ctx = context(); |
24
|
|
|
|
|
|
|
|
25
|
106
|
|
|
|
|
17235
|
my (@items, $name); |
26
|
106
|
100
|
|
|
|
403
|
if (ref($args[0]) eq 'ARRAY') { |
27
|
9
|
|
|
|
|
19
|
$name = $args[1]; |
28
|
9
|
|
|
|
|
14
|
@items = @{$args[0]}; |
|
9
|
|
|
|
|
25
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
97
|
|
|
|
|
280
|
@items = @args; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
106
|
100
|
|
|
|
539
|
my $thing_name = ref($thing) ? render_ref($thing) : defined($thing) ? "$thing" : ""; |
|
|
100
|
|
|
|
|
|
35
|
106
|
|
|
|
|
330
|
$thing_name =~ s/\n/\\n/g; |
36
|
106
|
|
|
|
|
258
|
$thing_name =~ s/#//g; |
37
|
106
|
|
|
|
|
535
|
$thing_name =~ s/\(0x[a-f0-9]+\)//gi; |
38
|
|
|
|
|
|
|
|
39
|
106
|
100
|
66
|
|
|
889
|
$name ||= @items == 1 ? "$thing_name\->$op('$items[0]')" : "$thing_name\->$op(...)"; |
40
|
|
|
|
|
|
|
|
41
|
106
|
100
|
100
|
|
|
772
|
unless (defined($thing) && (blessed($thing) || !ref($thing) && length($thing))) { |
|
|
|
100
|
|
|
|
|
42
|
3
|
100
|
66
|
|
|
28
|
my $thing = defined($thing) |
43
|
|
|
|
|
|
|
? ref($thing) || "'$thing'" |
44
|
|
|
|
|
|
|
: ''; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
16
|
$ctx->ok(0, $name, ["$thing is neither a blessed reference or a package name."]); |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
1730
|
$ctx->release; |
49
|
3
|
|
|
|
|
87
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
103
|
100
|
66
|
|
|
701
|
unless(UNIVERSAL->can($op) || $thing->can($op)) { |
53
|
1
|
|
|
|
|
23
|
$ctx->skip($name, "'$op' is not supported on this platform"); |
54
|
1
|
|
|
|
|
352
|
$ctx->release; |
55
|
1
|
|
|
|
|
29
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
102
|
|
|
|
|
462
|
my $file = $ctx->trace->file; |
59
|
102
|
|
|
|
|
1162
|
my $line = $ctx->trace->line; |
60
|
|
|
|
|
|
|
|
61
|
102
|
|
|
|
|
621
|
my @bad; |
62
|
102
|
|
|
|
|
263
|
for my $item (@items) { |
63
|
194
|
|
|
|
|
338
|
my ($bool, $ok, $err); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
194
|
|
|
|
|
292
|
local ($@, $!); |
|
194
|
|
|
|
|
595
|
|
67
|
194
|
|
|
|
|
7835
|
$ok = eval qq/#line $line "$file"\n\$bool = \$thing->$op(\$item); 1/; |
68
|
194
|
|
|
|
|
3912
|
$err = $@; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
194
|
50
|
|
|
|
537
|
die $err unless $ok; |
72
|
194
|
100
|
|
|
|
570
|
next if $bool; |
73
|
|
|
|
|
|
|
|
74
|
15
|
|
|
|
|
41
|
push @bad => $item; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
102
|
|
|
|
|
656
|
$ctx->ok( !@bad, $name, [map { "Failed: $thing_name\->$op('$_')" } @bad]); |
|
15
|
|
|
|
|
75
|
|
78
|
|
|
|
|
|
|
|
79
|
102
|
|
|
|
|
29084
|
$ctx->release; |
80
|
|
|
|
|
|
|
|
81
|
102
|
|
|
|
|
3314
|
return !@bad; |
82
|
477
|
|
|
|
|
5923
|
}; |
83
|
|
|
|
|
|
|
|
84
|
159
|
|
|
159
|
|
1291
|
no strict 'refs'; |
|
159
|
|
|
|
|
357
|
|
|
159
|
|
|
|
|
8003
|
|
85
|
477
|
|
|
|
|
1118
|
*{$op . "_ok"} = $sub; |
|
477
|
|
|
|
|
7585
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |