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