line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Modern::Open; |
2
|
|
|
|
|
|
|
###################################################################### |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Modern::Open - Autovivification, Autodie, and 3-args open support |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# https://metacpan.org/release/Modern-Open |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright (c) 2014, 2015, 2018, 2019, 2020, 2021 INABA Hitoshi |
9
|
|
|
|
|
|
|
###################################################################### |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.12'; |
12
|
|
|
|
|
|
|
$VERSION = $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
27842
|
use 5.00503; |
|
9
|
|
|
|
|
64
|
|
15
|
9
|
|
|
9
|
|
39
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
360
|
|
16
|
9
|
50
|
|
9
|
|
154
|
BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 }; use warnings; local $^W=1; |
|
9
|
|
|
9
|
|
49
|
|
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
341
|
|
17
|
|
|
|
|
|
|
|
18
|
9
|
|
|
9
|
|
43
|
use Fcntl; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
12225
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub Modern::Open::confess (@) { |
21
|
22
|
|
|
22
|
0
|
103
|
my $i = 0; |
22
|
22
|
|
|
|
|
34
|
my @confess = (); |
23
|
22
|
|
|
|
|
150
|
while (my($package,$filename,$line,$subroutine) = caller($i)) { |
24
|
66
|
|
|
|
|
178
|
push @confess, "[$i] $filename($line) $package"."::$subroutine\n"; |
25
|
66
|
|
|
|
|
204
|
$i++; |
26
|
|
|
|
|
|
|
} |
27
|
22
|
|
|
|
|
131
|
print STDERR CORE::reverse @confess; |
28
|
22
|
|
|
|
|
85
|
print STDERR "\n"; |
29
|
22
|
|
|
|
|
76
|
print STDERR @_; |
30
|
22
|
|
|
|
|
80
|
die "\n"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub Modern::Open::open (*$;$) { |
34
|
34
|
|
|
34
|
1
|
6496
|
my $handle; |
35
|
|
|
|
|
|
|
|
36
|
34
|
100
|
|
|
|
82
|
if (defined $_[0]) { |
37
|
17
|
|
|
|
|
25
|
Modern::Open::confess "Bare handle no longer supported"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
17
|
|
|
|
|
27
|
$handle = $_[0] = \do { local *_ }; |
|
17
|
|
|
|
|
95
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
17
|
50
|
|
|
|
49
|
if (@_ >= 4) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Too many arguments for open"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif (@_ == 3) { |
47
|
8
|
|
|
|
|
22
|
my($mode,$filename) = @_[1,2]; |
48
|
|
|
|
|
|
|
|
49
|
8
|
100
|
|
|
|
20
|
if ($mode eq '-|') { |
|
|
100
|
|
|
|
|
|
50
|
1
|
|
|
|
|
1192
|
my $return = CORE::open($handle,qq{$filename |}); |
51
|
1
|
50
|
33
|
|
|
69
|
if ($return or defined wantarray) { |
52
|
1
|
|
|
|
|
40
|
return $return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't open($_[0],$_[1],$_[2]): $!"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ($mode eq '|-') { |
59
|
1
|
|
|
|
|
1586
|
my $return = CORE::open($handle,qq{| $filename}); |
60
|
1
|
50
|
33
|
|
|
55
|
if ($return or defined wantarray) { |
61
|
1
|
|
|
|
|
39
|
return $return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't open($_[0],$_[1],$_[2]): $!"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
6
|
|
|
|
|
19
|
my %flags = ( |
69
|
|
|
|
|
|
|
'<' => O_RDONLY, |
70
|
|
|
|
|
|
|
'>' => O_WRONLY | O_TRUNC | O_CREAT, |
71
|
|
|
|
|
|
|
'>>' => O_WRONLY |O_APPEND | O_CREAT, |
72
|
|
|
|
|
|
|
'+<' => O_RDWR, |
73
|
|
|
|
|
|
|
'+>' => O_RDWR | O_TRUNC | O_CREAT, |
74
|
|
|
|
|
|
|
'+>>' => O_RDWR | O_APPEND | O_CREAT, |
75
|
|
|
|
|
|
|
); |
76
|
6
|
50
|
|
|
|
10
|
if (not exists $flags{$mode}) { |
77
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Unknown open() mode '$mode'"; |
78
|
|
|
|
|
|
|
} |
79
|
6
|
|
|
|
|
260
|
my $return = CORE::sysopen($handle,$filename,$flags{$mode}); |
80
|
6
|
50
|
33
|
|
|
31
|
if ($return or defined wantarray) { |
81
|
6
|
|
|
|
|
24
|
return $return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't open($_[0],$_[1],$_[2]): $!"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif (@_ == 2) { |
89
|
9
|
|
|
|
|
3015
|
my $return = CORE::open($handle,$_[1]); |
90
|
9
|
50
|
33
|
|
|
77
|
if ($return or defined wantarray) { |
91
|
9
|
|
|
|
|
85
|
return $return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't open($_[0],$_[1]): $!"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Not enough arguments for open"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub Modern::Open::opendir (*$) { |
103
|
2
|
|
|
2
|
0
|
74
|
my $handle; |
104
|
|
|
|
|
|
|
|
105
|
2
|
100
|
|
|
|
6
|
if (defined $_[0]) { |
106
|
1
|
|
|
|
|
3
|
Modern::Open::confess "Bare handle no longer supported"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
1
|
|
|
|
|
2
|
$handle = $_[0] = \do { local *_ }; |
|
1
|
|
|
|
|
5
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
2
|
my $return; |
113
|
1
|
50
|
0
|
|
|
36
|
if ($return = CORE::opendir($handle,$_[1])) { |
|
|
0
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
elsif (($^O =~ /MSWin32/) and (-d qq{$_[1].})) { |
116
|
0
|
|
|
|
|
0
|
$return = CORE::opendir($handle,qq{$_[1].}); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
1
|
50
|
33
|
|
|
6
|
if ($return or defined wantarray) { |
120
|
1
|
|
|
|
|
4
|
return $return; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't opendir($_[0],$_[1]): $!"; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub Modern::Open::sysopen (*$$;$) { |
128
|
2
|
|
|
2
|
0
|
66
|
my $handle; |
129
|
|
|
|
|
|
|
|
130
|
2
|
100
|
|
|
|
6
|
if (defined $_[0]) { |
131
|
1
|
|
|
|
|
4
|
Modern::Open::confess "Bare handle no longer supported"; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else { |
134
|
1
|
|
|
|
|
2
|
$handle = $_[0] = \do { local *_ }; |
|
1
|
|
|
|
|
5
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
1
|
50
|
|
|
|
6
|
if (@_ >= 5) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Too many arguments for sysopen"; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif (@_ == 4) { |
141
|
0
|
|
|
|
|
0
|
my $return = CORE::sysopen($handle,$_[1],$_[2],$_[3]); |
142
|
0
|
0
|
0
|
|
|
0
|
if ($return or defined wantarray) { |
143
|
0
|
|
|
|
|
0
|
return $return; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else { |
146
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't sysopen($_[0],$_[1],$_[2],$_[3]): $!"; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
elsif (@_ == 3) { |
150
|
1
|
|
|
|
|
46
|
my $return = CORE::sysopen($handle,$_[1],$_[2]); |
151
|
1
|
50
|
33
|
|
|
6
|
if ($return or defined wantarray) { |
152
|
1
|
|
|
|
|
4
|
return $return; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
else { |
155
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't sysopen($_[0],$_[1],$_[2]): $!"; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else { |
159
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Not enough arguments for sysopen"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub Modern::Open::pipe (**) { |
164
|
2
|
|
|
2
|
0
|
72
|
my($handle0,$handle1); |
165
|
|
|
|
|
|
|
|
166
|
2
|
100
|
|
|
|
7
|
if (defined $_[0]) { |
167
|
1
|
|
|
|
|
4
|
Modern::Open::confess "Bare handle no longer supported"; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else { |
170
|
1
|
|
|
|
|
3
|
$handle0 = $_[0] = \do { local *_ }; |
|
1
|
|
|
|
|
6
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
1
|
50
|
|
|
|
3
|
if (defined $_[1]) { |
174
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Bare handle no longer supported"; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
else { |
177
|
1
|
|
|
|
|
1
|
$handle1 = $_[1] = \do { local *_ }; |
|
1
|
|
|
|
|
3
|
|
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
1
|
|
|
|
|
30
|
my $return = CORE::pipe($handle0,$handle1); |
181
|
1
|
50
|
33
|
|
|
7
|
if ($return or defined wantarray) { |
182
|
1
|
|
|
|
|
4
|
return $return; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
else { |
185
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't pipe($_[0],$_[1]): $!"; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub Modern::Open::socket (*$$$) { |
190
|
3
|
|
|
3
|
0
|
1042
|
my $handle; |
191
|
|
|
|
|
|
|
|
192
|
3
|
100
|
|
|
|
11
|
if (defined $_[0]) { |
193
|
2
|
|
|
|
|
9
|
Modern::Open::confess "Bare handle no longer supported"; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
else { |
196
|
1
|
|
|
|
|
2
|
$handle = $_[0] = \do { local *_ }; |
|
1
|
|
|
|
|
6
|
|
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# socket doesn't autodie |
200
|
1
|
|
|
|
|
49
|
return CORE::socket($handle,$_[1],$_[2],$_[3]); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub Modern::Open::accept (**) { |
204
|
0
|
|
|
0
|
0
|
0
|
my($handle0,$handle1); |
205
|
|
|
|
|
|
|
|
206
|
0
|
0
|
|
|
|
0
|
if (defined $_[0]) { |
207
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Bare handle no longer supported"; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
else { |
210
|
0
|
|
|
|
|
0
|
$handle0 = $_[0] = \do { local *_ }; |
|
0
|
|
|
|
|
0
|
|
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
0
|
0
|
|
|
|
0
|
if (defined $_[1]) { |
214
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Bare handle no longer supported"; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
0
|
my $return = CORE::accept($handle0,$handle1); |
218
|
0
|
0
|
0
|
|
|
0
|
if ($return or defined wantarray) { |
219
|
0
|
|
|
|
|
0
|
return $return; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
else { |
222
|
0
|
|
|
|
|
0
|
Modern::Open::confess "Can't accept($_[0],$_[1]): $!"; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub import { |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# avoid: Can't use string ("main::open") as a symbol ref while "strict refs" in use |
229
|
9
|
|
|
9
|
|
86
|
no strict 'refs'; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
1429
|
|
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
# avoid: Prototype mismatch: sub main::open (*;$) vs (*$;$) |
232
|
9
|
|
|
0
|
|
62
|
local $SIG{__WARN__} = sub {}; |
|
9
|
|
|
9
|
|
50
|
|
233
|
9
|
|
|
|
|
19
|
*{caller() . '::open'} = \&Modern::Open::open; |
|
9
|
|
|
|
|
67
|
|
234
|
|
|
|
|
|
|
} |
235
|
9
|
|
|
|
|
17
|
*{caller() . '::opendir'} = \&Modern::Open::opendir; |
|
9
|
|
|
|
|
30
|
|
236
|
9
|
|
|
|
|
14
|
*{caller() . '::sysopen'} = \&Modern::Open::sysopen; |
|
9
|
|
|
|
|
31
|
|
237
|
9
|
|
|
|
|
15
|
*{caller() . '::pipe'} = \&Modern::Open::pipe; |
|
9
|
|
|
|
|
109
|
|
238
|
9
|
|
|
|
|
21
|
*{caller() . '::socket'} = \&Modern::Open::socket; |
|
9
|
|
|
|
|
42
|
|
239
|
9
|
|
|
|
|
14
|
*{caller() . '::accept'} = \&Modern::Open::accept; |
|
9
|
|
|
|
|
8249
|
|
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
1; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
__END__ |