line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
20
|
|
|
20
|
|
66
|
use strict; |
|
20
|
|
|
|
|
23
|
|
|
20
|
|
|
|
|
419
|
|
2
|
20
|
|
|
20
|
|
52
|
use warnings; |
|
20
|
|
|
|
|
22
|
|
|
20
|
|
|
|
|
769
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package File::Util::Definitions; |
5
|
|
|
|
|
|
|
$File::Util::Definitions::VERSION = '4.161200'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Global symbols and constants used in most File::Util classes |
7
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
62
|
use Fcntl qw( :flock ); |
|
20
|
|
|
|
|
18
|
|
|
20
|
|
|
|
|
2322
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
|
|
2907
|
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
|
20
|
|
|
20
|
|
76
|
); |
|
20
|
|
|
|
|
35
|
|
18
|
|
|
|
|
|
|
|
19
|
20
|
|
|
20
|
|
70
|
use Exporter; |
|
20
|
|
|
|
|
18
|
|
|
20
|
|
|
|
|
1750
|
|
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
|
20
|
50
|
|
20
|
|
97
|
unless ( $OS = $^O ) |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
|
|
0
|
require Config; |
40
|
|
|
|
|
|
|
|
41
|
20
|
|
|
20
|
|
66
|
{ no warnings 'once'; $OS = $Config::Config{osname} } |
|
20
|
|
|
|
|
20
|
|
|
20
|
|
|
|
|
5905
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
20
|
|
|
|
|
22
|
{ local $@; $HAVE_UU = eval { require 5.008001 } } |
|
20
|
|
|
|
|
21
|
|
|
20
|
|
|
|
|
23
|
|
|
20
|
|
|
|
|
323
|
|
45
|
|
|
|
|
|
|
|
46
|
20
|
50
|
|
|
|
263
|
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
|
20
|
|
|
|
|
27
|
else { $OS = 'UNIX' } |
56
|
|
|
|
|
|
|
|
57
|
20
|
|
|
|
|
16
|
$EBCDIC = qq[\t] ne qq[\011] ? 1 : 0; |
58
|
20
|
50
|
|
|
|
76
|
$NEEDS_BINMODE = $OS =~ /WINDOWS|DOS|OS2|MSWin/ ? 1 : 0; |
59
|
20
|
50
|
33
|
|
|
144
|
$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
|
20
|
|
50
|
|
|
155
|
VMS => '/', CYGWIN => '/', }->{ $OS } || '/'; |
68
|
|
|
|
|
|
|
|
69
|
20
|
|
|
|
|
530
|
$_LOCKS = { }; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
} BEGIN { |
72
|
20
|
|
|
20
|
|
68
|
use constant NL => $NL; |
|
20
|
|
|
|
|
16
|
|
|
20
|
|
|
|
|
1343
|
|
73
|
20
|
|
|
20
|
|
72
|
use constant SL => $SL; |
|
20
|
|
|
|
|
20
|
|
|
20
|
|
|
|
|
836
|
|
74
|
20
|
|
|
20
|
|
62
|
use constant OS => $OS; |
|
20
|
|
|
0
|
|
19
|
|
|
20
|
|
|
|
|
10478
|
|
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__ |