line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
21
|
|
|
21
|
|
122
|
use strict; |
|
21
|
|
|
|
|
30
|
|
|
21
|
|
|
|
|
552
|
|
2
|
21
|
|
|
21
|
|
88
|
use warnings; |
|
21
|
|
|
|
|
28
|
|
|
21
|
|
|
|
|
958
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package File::Util::Definitions; |
5
|
|
|
|
|
|
|
$File::Util::Definitions::VERSION = '4.201720'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Global symbols and constants used in most File::Util classes |
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
122
|
use Fcntl qw( :flock ); |
|
21
|
|
|
|
|
38
|
|
|
21
|
|
|
|
|
3131
|
|
9
|
|
|
|
|
|
|
|
10
|
21
|
|
|
|
|
3830
|
use vars qw( |
11
|
|
|
|
|
|
|
@ISA @EXPORT_OK %EXPORT_TAGS |
12
|
|
|
|
|
|
|
$OS $MODES $READ_LIMIT $ABORT_DEPTH |
13
|
|
|
|
|
|
|
$USE_FLOCK @ONLOCKFAIL $ILLEGAL_CHR $CAN_FLOCK |
14
|
|
|
|
|
|
|
$EBCDIC $DIRSPLIT $_LOCKS $NEEDS_BINMODE |
15
|
|
|
|
|
|
|
$WINROOT $ATOMIZER $SL $NL $EMPTY_WRITES_OK |
16
|
|
|
|
|
|
|
$FSDOTS $AUTHORITY $EBL $EBR $HAVE_UU |
17
|
21
|
|
|
21
|
|
155
|
); |
|
21
|
|
|
|
|
43
|
|
18
|
|
|
|
|
|
|
|
19
|
21
|
|
|
21
|
|
126
|
use Exporter; |
|
21
|
|
|
|
|
33
|
|
|
21
|
|
|
|
|
2220
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$AUTHORITY = 'cpan:TOMMY'; |
22
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
23
|
|
|
|
|
|
|
@EXPORT_OK = qw( |
24
|
|
|
|
|
|
|
$OS OS $MODES $READ_LIMIT $ABORT_DEPTH |
25
|
|
|
|
|
|
|
$USE_FLOCK @ONLOCKFAIL $ILLEGAL_CHR $CAN_FLOCK |
26
|
|
|
|
|
|
|
$EBCDIC $DIRSPLIT $_LOCKS $NEEDS_BINMODE |
27
|
|
|
|
|
|
|
$WINROOT $ATOMIZER $SL $NL $EMPTY_WRITES_OK |
28
|
|
|
|
|
|
|
$FSDOTS $AUTHORITY SL NL $EBL $EBR |
29
|
|
|
|
|
|
|
$HAVE_UU |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
BEGIN { |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Some OS logic. |
37
|
21
|
50
|
|
21
|
|
155
|
unless ( $OS = $^O ) |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
|
|
0
|
require Config; |
40
|
|
|
|
|
|
|
|
41
|
21
|
|
|
21
|
|
138
|
{ no warnings 'once'; $OS = $Config::Config{osname} } |
|
21
|
|
|
|
|
37
|
|
|
21
|
|
|
|
|
8283
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
21
|
|
|
|
|
36
|
{ local $@; $HAVE_UU = eval { require 5.008001 } } |
|
21
|
|
|
|
|
42
|
|
|
21
|
|
|
|
|
30
|
|
|
21
|
|
|
|
|
357
|
|
45
|
|
|
|
|
|
|
|
46
|
21
|
50
|
|
|
|
351
|
if ( $OS =~ /^darwin/i ) { $OS = 'UNIX' } |
|
0
|
50
|
|
|
|
0
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^cygwin/i ) { $OS = 'CYGWIN' } |
48
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^MSWin/i ) { $OS = 'WINDOWS' } |
49
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^vms/i ) { $OS = 'VMS' } |
50
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^bsdos/i ) { $OS = 'UNIX' } |
51
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^dos/i ) { $OS = 'DOS' } |
52
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^MacOS/i ) { $OS = 'MACINTOSH' } |
53
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^epoc/ ) { $OS = 'EPOC' } |
54
|
0
|
|
|
|
|
0
|
elsif ( $OS =~ /^os2/i ) { $OS = 'OS2' } |
55
|
21
|
|
|
|
|
43
|
else { $OS = 'UNIX' } |
56
|
|
|
|
|
|
|
|
57
|
21
|
|
|
|
|
44
|
$EBCDIC = qq[\t] ne qq[\011] ? 1 : 0; |
58
|
21
|
50
|
|
|
|
140
|
$NEEDS_BINMODE = $OS =~ /WINDOWS|DOS|OS2|MSWin/ ? 1 : 0; |
59
|
21
|
50
|
33
|
|
|
226
|
$NL = |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$NEEDS_BINMODE ? qq[\015\012] |
61
|
|
|
|
|
|
|
: $EBCDIC || $OS eq 'VMS' ? qq[\n] |
62
|
|
|
|
|
|
|
: $OS eq 'MACINTOSH' ? qq[\015] |
63
|
|
|
|
|
|
|
: qq[\012]; |
64
|
|
|
|
|
|
|
$SL = |
65
|
|
|
|
|
|
|
{ DOS => '\\', EPOC => '/', MACINTOSH => ':', |
66
|
|
|
|
|
|
|
OS2 => '\\', UNIX => '/', WINDOWS => chr(92), |
67
|
21
|
|
50
|
|
|
220
|
VMS => '/', CYGWIN => '/', }->{ $OS } || '/'; |
68
|
|
|
|
|
|
|
|
69
|
21
|
|
|
|
|
794
|
$_LOCKS = { }; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
} BEGIN { |
72
|
21
|
|
|
21
|
|
140
|
use constant NL => $NL; |
|
21
|
|
|
|
|
43
|
|
|
21
|
|
|
|
|
2041
|
|
73
|
21
|
|
|
21
|
|
118
|
use constant SL => $SL; |
|
21
|
|
|
|
|
33
|
|
|
21
|
|
|
|
|
1217
|
|
74
|
21
|
|
|
21
|
|
141
|
use constant OS => $OS; |
|
21
|
|
|
0
|
|
30
|
|
|
21
|
|
|
|
|
15408
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$WINROOT = qr/^(?: [[:alpha:]]{1} ) : (?: \\{1,2} )/x; |
78
|
|
|
|
|
|
|
$DIRSPLIT = qr/$WINROOT | [\\:\/]/x; |
79
|
|
|
|
|
|
|
$ATOMIZER = qr/ |
80
|
|
|
|
|
|
|
(^ $DIRSPLIT ){0,1} |
81
|
|
|
|
|
|
|
(?: (.*) $DIRSPLIT ){0,1} |
82
|
|
|
|
|
|
|
(.*) /x; |
83
|
|
|
|
|
|
|
$ILLEGAL_CHR = qr/[\/\|\\$NL\r\n\t\013\*\"\?\<\:\>]/; |
84
|
|
|
|
|
|
|
$FSDOTS = qr/^\.{1,2}$/; |
85
|
|
|
|
|
|
|
$READ_LIMIT = 52428800; # set read_limit to a default of 50 megabytes |
86
|
|
|
|
|
|
|
$ABORT_DEPTH = 1000; # maximum depth for recursive list_dir calls |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
local $@; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
eval { |
92
|
|
|
|
|
|
|
flock( STDOUT, &Fcntl::LOCK_SH ); |
93
|
|
|
|
|
|
|
flock( STDOUT, &Fcntl::LOCK_UN ); |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$CAN_FLOCK = $@ ? 0 : 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# try to use file locking, define flock race conditions policy |
100
|
|
|
|
|
|
|
$USE_FLOCK = 1; |
101
|
|
|
|
|
|
|
@ONLOCKFAIL = qw( NOBLOCKEX FAIL ); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$MODES->{popen} = { |
104
|
|
|
|
|
|
|
write => '>', trunc => '>', rwupdate => '+<', |
105
|
|
|
|
|
|
|
append => '>>', read => '<', rwclobber => '+>', |
106
|
|
|
|
|
|
|
rwcreate => '+>', rwappend => '+>>', |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$MODES->{sysopen} = { |
110
|
|
|
|
|
|
|
read => &Fcntl::O_RDONLY, |
111
|
|
|
|
|
|
|
write => &Fcntl::O_WRONLY | &Fcntl::O_CREAT, |
112
|
|
|
|
|
|
|
append => &Fcntl::O_WRONLY | &Fcntl::O_APPEND | &Fcntl::O_CREAT, |
113
|
|
|
|
|
|
|
trunc => &Fcntl::O_WRONLY | &Fcntl::O_CREAT | &Fcntl::O_TRUNC, |
114
|
|
|
|
|
|
|
rwcreate => &Fcntl::O_RDWR | &Fcntl::O_CREAT, |
115
|
|
|
|
|
|
|
rwclobber => &Fcntl::O_RDWR | &Fcntl::O_TRUNC | &Fcntl::O_CREAT, |
116
|
|
|
|
|
|
|
rwappend => &Fcntl::O_RDWR | &Fcntl::O_APPEND | &Fcntl::O_CREAT, |
117
|
|
|
|
|
|
|
rwupdate => &Fcntl::O_RDWR, |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# -------------------------------------------------------- |
121
|
|
|
|
|
|
|
# %$File::Util::Definitions::LOCKS |
122
|
|
|
|
|
|
|
# -------------------------------------------------------- |
123
|
|
|
|
|
|
|
$_LOCKS->{IGNORE} = sub { $_[2] }; |
124
|
|
|
|
|
|
|
$_LOCKS->{ZERO} = sub { 0 }; |
125
|
|
|
|
|
|
|
$_LOCKS->{UNDEF} = sub { }; |
126
|
|
|
|
|
|
|
$_LOCKS->{NOBLOCKEX} = sub { |
127
|
|
|
|
|
|
|
return $_[2] if flock( $_[2], &Fcntl::LOCK_EX | &Fcntl::LOCK_NB ); return |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
$_LOCKS->{NOBLOCKSH} = sub { |
130
|
|
|
|
|
|
|
return $_[2] if flock( $_[2], &Fcntl::LOCK_SH | &Fcntl::LOCK_NB ); return |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
$_LOCKS->{BLOCKEX} = sub { |
133
|
|
|
|
|
|
|
return $_[2] if flock( $_[2], &Fcntl::LOCK_EX ); return |
134
|
|
|
|
|
|
|
}; |
135
|
|
|
|
|
|
|
$_LOCKS->{BLOCKSH} = sub { |
136
|
|
|
|
|
|
|
return $_[2] if flock( $_[2], &Fcntl::LOCK_SH ); return |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
$_LOCKS->{WARN} = sub { |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $this = shift; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
return $this->_throw( |
143
|
|
|
|
|
|
|
'bad flock' => |
144
|
|
|
|
|
|
|
{ |
145
|
|
|
|
|
|
|
filename => shift, |
146
|
|
|
|
|
|
|
exception => $!, |
147
|
|
|
|
|
|
|
onfail => 'warn', |
148
|
|
|
|
|
|
|
opts => $this->_remove_opts( \@_ ), |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
}; |
152
|
|
|
|
|
|
|
$_LOCKS->{FAIL} = sub { |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $this = shift; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return $this->_throw( |
157
|
|
|
|
|
|
|
'bad flock' => |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
filename => shift, |
160
|
|
|
|
|
|
|
exception => $!, |
161
|
|
|
|
|
|
|
opts => $this->_remove_opts( \@_ ), |
162
|
|
|
|
|
|
|
}, |
163
|
|
|
|
|
|
|
); |
164
|
|
|
|
|
|
|
}; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# (for use in error messages) |
167
|
|
|
|
|
|
|
( $EBL, $EBR ) = ('( ', ' )'); # error bracket left, error bracket right |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# -------------------------------------------------------- |
170
|
|
|
|
|
|
|
# File::Util::Definitions::DESTROY() |
171
|
|
|
|
|
|
|
# -------------------------------------------------------- |
172
|
|
|
|
1
|
|
|
sub DESTROY { } |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |