line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util; |
2
|
57
|
|
|
57
|
|
19502
|
use strict; |
|
57
|
|
|
|
|
58
|
|
|
57
|
|
|
|
|
1209
|
|
3
|
57
|
|
|
57
|
|
162
|
use warnings; |
|
57
|
|
|
|
|
54
|
|
|
57
|
|
|
|
|
2062
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000043'; |
6
|
|
|
|
|
|
|
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) |
7
|
|
|
|
|
|
|
|
8
|
57
|
|
|
57
|
|
162
|
use Config qw/%Config/; |
|
57
|
|
|
|
|
155
|
|
|
57
|
|
|
|
|
3017
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
11
|
|
|
|
|
|
|
try |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
pkg_to_file |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
get_tid USE_THREADS |
16
|
|
|
|
|
|
|
CAN_THREAD |
17
|
|
|
|
|
|
|
CAN_REALLY_FORK |
18
|
|
|
|
|
|
|
CAN_FORK |
19
|
|
|
|
|
|
|
}; |
20
|
57
|
|
|
57
|
|
241
|
use base 'Exporter'; |
|
57
|
|
|
|
|
67
|
|
|
57
|
|
|
|
|
13911
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _can_thread { |
23
|
57
|
50
|
|
57
|
|
209
|
return 0 unless $] >= 5.008001; |
24
|
57
|
50
|
|
|
|
418
|
return 0 unless $Config{'useithreads'}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Threads are broken on perl 5.10.0 built with gcc 4.8+ |
27
|
0
|
0
|
0
|
|
|
0
|
if ($] == 5.010000 && $Config{'ccname'} eq 'gcc' && $Config{'gccversion'}) { |
|
|
|
0
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my @parts = split /\./, $Config{'gccversion'}; |
29
|
0
|
0
|
0
|
|
|
0
|
return 0 if $parts[0] >= 4 && $parts[1] >= 8; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Change to a version check if this ever changes |
33
|
0
|
0
|
|
|
|
0
|
return 0 if $INC{'Devel/Cover.pm'}; |
34
|
0
|
|
|
|
|
0
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _can_fork { |
38
|
57
|
50
|
|
57
|
|
7055
|
return 1 if $Config{d_fork}; |
39
|
0
|
0
|
0
|
|
|
0
|
return 0 unless $^O eq 'MSWin32' || $^O eq 'NetWare'; |
40
|
0
|
0
|
|
|
|
0
|
return 0 unless $Config{useithreads}; |
41
|
0
|
0
|
|
|
|
0
|
return 0 unless $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
return _can_thread(); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
BEGIN { |
47
|
57
|
|
|
57
|
|
251
|
no warnings 'once'; |
|
57
|
|
|
|
|
64
|
|
|
57
|
|
|
|
|
6658
|
|
48
|
57
|
50
|
|
57
|
|
3343
|
*CAN_REALLY_FORK = $Config{d_fork} ? sub() { 1 } : sub() { 0 }; |
49
|
57
|
50
|
|
|
|
142
|
*CAN_THREAD = _can_thread() ? sub() { 1 } : sub() { 0 }; |
50
|
57
|
50
|
|
|
|
175
|
*CAN_FORK = _can_fork() ? sub() { 1 } : sub() { 0 }; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _manual_try(&;@) { |
54
|
2
|
|
|
2
|
|
10
|
my $code = shift; |
55
|
2
|
|
|
|
|
2
|
my $args = \@_; |
56
|
2
|
|
|
|
|
3
|
my $err; |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
5
|
my $die = delete $SIG{__DIE__}; |
59
|
|
|
|
|
|
|
|
60
|
2
|
100
|
50
|
|
|
3
|
eval { $code->(@$args); 1 } or $err = $@ || "Error was squashed!\n"; |
|
2
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
61
|
|
|
|
|
|
|
|
62
|
2
|
50
|
|
|
|
13
|
$die ? $SIG{__DIE__} = $die : delete $SIG{__DIE__}; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
6
|
return (!defined($err), $err); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _local_try(&;@) { |
68
|
194
|
|
|
194
|
|
1247
|
my $code = shift; |
69
|
194
|
|
|
|
|
289
|
my $args = \@_; |
70
|
194
|
|
|
|
|
207
|
my $err; |
71
|
|
|
|
|
|
|
|
72
|
57
|
|
|
57
|
|
226
|
no warnings; |
|
57
|
|
|
|
|
69
|
|
|
57
|
|
|
|
|
5871
|
|
73
|
194
|
|
|
|
|
641
|
local $SIG{__DIE__}; |
74
|
194
|
100
|
50
|
|
|
279
|
eval { $code->(@$args); 1 } or $err = $@ || "Error was squashed!\n"; |
|
194
|
|
|
|
|
427
|
|
|
179
|
|
|
|
|
606
|
|
75
|
|
|
|
|
|
|
|
76
|
194
|
|
|
|
|
1508
|
return (!defined($err), $err); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Older versions of perl have a nasty bug on win32 when localizing a variable |
80
|
|
|
|
|
|
|
# before forking or starting a new thread. So for those systems we use the |
81
|
|
|
|
|
|
|
# non-local form. When possible though we use the faster 'local' form. |
82
|
|
|
|
|
|
|
BEGIN { |
83
|
57
|
50
|
33
|
57
|
|
323
|
if ($^O eq 'MSWin32' && $] < 5.020002) { |
84
|
0
|
|
|
|
|
0
|
*try = \&_manual_try; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
57
|
|
|
|
|
7213
|
*try = \&_local_try; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
BEGIN { |
92
|
57
|
|
|
57
|
|
89
|
if(CAN_THREAD) { |
93
|
|
|
|
|
|
|
if ($INC{'threads.pm'}) { |
94
|
|
|
|
|
|
|
# Threads are already loaded, so we do not need to check if they |
95
|
|
|
|
|
|
|
# are loaded each time |
96
|
|
|
|
|
|
|
*USE_THREADS = sub() { 1 }; |
97
|
|
|
|
|
|
|
*get_tid = sub { threads->tid() }; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
|
|
|
|
|
|
# :-( Need to check each time to see if they have been loaded. |
101
|
|
|
|
|
|
|
*USE_THREADS = sub { $INC{'threads.pm'} ? 1 : 0 }; |
102
|
|
|
|
|
|
|
*get_tid = sub { $INC{'threads.pm'} ? threads->tid() : 0 }; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
|
|
|
|
|
|
# No threads, not now, not ever! |
107
|
57
|
|
|
|
|
232
|
*USE_THREADS = sub() { 0 }; |
108
|
57
|
|
|
|
|
4180
|
*get_tid = sub() { 0 }; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub pkg_to_file { |
113
|
436
|
|
|
436
|
1
|
359
|
my $pkg = shift; |
114
|
436
|
|
|
|
|
364
|
my $file = $pkg; |
115
|
436
|
|
|
|
|
1503
|
$file =~ s{(::|')}{/}g; |
116
|
436
|
|
|
|
|
402
|
$file .= '.pm'; |
117
|
436
|
|
|
|
|
669
|
return $file; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |