line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
21
|
|
|
21
|
|
69
|
use strict; |
|
21
|
|
|
|
|
24
|
|
|
21
|
|
|
|
|
435
|
|
2
|
21
|
|
|
21
|
|
59
|
use warnings; |
|
21
|
|
|
|
|
20
|
|
|
21
|
|
|
|
|
768
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package File::Util::Definitions; |
5
|
|
|
|
|
|
|
$File::Util::Definitions::VERSION = '4.161950'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Global symbols and constants used in most File::Util classes |
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
75
|
use Fcntl qw( :flock ); |
|
21
|
|
|
|
|
22
|
|
|
21
|
|
|
|
|
2618
|
|
9
|
|
|
|
|
|
|
|
10
|
21
|
|
|
|
|
3140
|
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
|
|
79
|
); |
|
21
|
|
|
|
|
27
|
|
18
|
|
|
|
|
|
|
|
19
|
21
|
|
|
21
|
|
76
|
use Exporter; |
|
21
|
|
|
|
|
23
|
|
|
21
|
|
|
|
|
1964
|
|
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
|
|
109
|
unless ( $OS = $^O ) |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
|
|
0
|
require Config; |
40
|
|
|
|
|
|
|
|
41
|
21
|
|
|
21
|
|
77
|
{ no warnings 'once'; $OS = $Config::Config{osname} } |
|
21
|
|
|
|
|
23
|
|
|
21
|
|
|
|
|
6728
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
21
|
|
|
|
|
24
|
{ local $@; $HAVE_UU = eval { require 5.008001 } } |
|
21
|
|
|
|
|
24
|
|
|
21
|
|
|
|
|
27
|
|
|
21
|
|
|
|
|
377
|
|
45
|
|
|
|
|
|
|
|
46
|
21
|
50
|
|
|
|
295
|
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
|
|
|
|
|
29
|
else { $OS = 'UNIX' } |
56
|
|
|
|
|
|
|
|
57
|
21
|
|
|
|
|
22
|
$EBCDIC = qq[\t] ne qq[\011] ? 1 : 0; |
58
|
21
|
50
|
|
|
|
75
|
$NEEDS_BINMODE = $OS =~ /WINDOWS|DOS|OS2|MSWin/ ? 1 : 0; |
59
|
21
|
50
|
33
|
|
|
163
|
$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
|
|
|
170
|
VMS => '/', CYGWIN => '/', }->{ $OS } || '/'; |
68
|
|
|
|
|
|
|
|
69
|
21
|
|
|
|
|
580
|
$_LOCKS = { }; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
} BEGIN { |
72
|
21
|
|
|
21
|
|
76
|
use constant NL => $NL; |
|
21
|
|
|
|
|
23
|
|
|
21
|
|
|
|
|
1476
|
|
73
|
21
|
|
|
21
|
|
70
|
use constant SL => $SL; |
|
21
|
|
|
|
|
23
|
|
|
21
|
|
|
|
|
882
|
|
74
|
21
|
|
|
21
|
|
70
|
use constant OS => $OS; |
|
21
|
|
|
0
|
|
21
|
|
|
21
|
|
|
|
|
11487
|
|
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__ |