line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
|
|
|
|
|
|
# IO::Dir.pm |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (c) 1997-8 Graham Barr . All rights reserved. |
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
6
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package IO::Dir; |
9
|
1
|
|
|
1
|
|
29
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
10
|
|
|
|
|
|
|
use 5.006; |
11
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
12
|
1
|
|
|
1
|
|
14
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
122
|
|
13
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
14
|
1
|
|
|
1
|
|
6
|
use Symbol; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
36
|
|
15
|
1
|
|
|
1
|
|
1541
|
use Exporter; |
|
1
|
|
|
|
|
1201
|
|
|
1
|
|
|
|
|
162
|
|
16
|
|
|
|
|
|
|
use IO::File; |
17
|
1
|
|
|
1
|
|
1348
|
our(@ISA, $VERSION, @EXPORT_OK); |
|
1
|
|
|
|
|
1269
|
|
|
1
|
|
|
|
|
32
|
|
18
|
1
|
|
|
1
|
|
8
|
use Tie::Hash; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
19
|
1
|
|
|
1
|
|
68
|
use File::stat; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
224
|
|
20
|
|
|
|
|
|
|
use File::Spec; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
@ISA = qw(Tie::Hash Exporter); |
23
|
|
|
|
|
|
|
$VERSION = "1.07"; |
24
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
25
|
|
|
|
|
|
|
@EXPORT_OK = qw(DIR_UNLINK); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub DIR_UNLINK () { 1 } |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
0
|
0
|
1
|
|
sub new { |
30
|
0
|
|
|
|
|
|
@_ >= 1 && @_ <= 2 or croak 'usage: new IO::Dir [DIRNAME]'; |
31
|
0
|
|
|
|
|
|
my $class = shift; |
32
|
0
|
0
|
|
|
|
|
my $dh = gensym; |
33
|
0
|
0
|
|
|
|
|
if (@_) { |
34
|
|
|
|
|
|
|
IO::Dir::open($dh, $_[0]) |
35
|
|
|
|
|
|
|
or return undef; |
36
|
0
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
bless $dh, $class; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
|
|
sub DESTROY { |
41
|
0
|
|
|
|
|
|
my ($dh) = @_; |
42
|
1
|
|
|
1
|
|
9
|
local($., $@, $!, $^E, $?); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
795
|
|
43
|
0
|
|
|
|
|
|
no warnings 'io'; |
44
|
|
|
|
|
|
|
closedir($dh); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
0
|
1
|
|
sub open { |
48
|
0
|
|
|
|
|
|
@_ == 2 or croak 'usage: $dh->open(DIRNAME)'; |
49
|
|
|
|
|
|
|
my ($dh, $dirname) = @_; |
50
|
0
|
0
|
|
|
|
|
return undef |
51
|
|
|
|
|
|
|
unless opendir($dh, $dirname); |
52
|
|
|
|
|
|
|
# a dir name should always have a ":" in it; assume dirname is |
53
|
0
|
0
|
0
|
|
|
|
# in current directory |
54
|
0
|
|
|
|
|
|
$dirname = ':' . $dirname if ( ($^O eq 'MacOS') && ($dirname !~ /:/) ); |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
${*$dh}{io_dir_path} = $dirname; |
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
0
|
1
|
|
sub close { |
60
|
0
|
|
|
|
|
|
@_ == 1 or croak 'usage: $dh->close()'; |
61
|
0
|
|
|
|
|
|
my ($dh) = @_; |
62
|
|
|
|
|
|
|
closedir($dh); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
0
|
1
|
|
sub read { |
66
|
0
|
|
|
|
|
|
@_ == 1 or croak 'usage: $dh->read()'; |
67
|
0
|
|
|
|
|
|
my ($dh) = @_; |
68
|
|
|
|
|
|
|
readdir($dh); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
0
|
1
|
|
sub seek { |
72
|
0
|
|
|
|
|
|
@_ == 2 or croak 'usage: $dh->seek(POS)'; |
73
|
0
|
|
|
|
|
|
my ($dh,$pos) = @_; |
74
|
|
|
|
|
|
|
seekdir($dh,$pos); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
0
|
1
|
|
sub tell { |
78
|
0
|
|
|
|
|
|
@_ == 1 or croak 'usage: $dh->tell()'; |
79
|
0
|
|
|
|
|
|
my ($dh) = @_; |
80
|
|
|
|
|
|
|
telldir($dh); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
0
|
1
|
|
sub rewind { |
84
|
0
|
|
|
|
|
|
@_ == 1 or croak 'usage: $dh->rewind()'; |
85
|
0
|
|
|
|
|
|
my ($dh) = @_; |
86
|
|
|
|
|
|
|
rewinddir($dh); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
|
|
sub TIEHASH { |
90
|
|
|
|
|
|
|
my($class,$dir,$options) = @_; |
91
|
0
|
0
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $dh = $class->new($dir) |
93
|
|
|
|
|
|
|
or return undef; |
94
|
0
|
|
0
|
|
|
|
|
95
|
|
|
|
|
|
|
$options ||= 0; |
96
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
${*$dh}{io_dir_unlink} = $options & DIR_UNLINK; |
98
|
|
|
|
|
|
|
$dh; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
|
|
sub FIRSTKEY { |
102
|
0
|
|
|
|
|
|
my($dh) = @_; |
103
|
0
|
|
|
|
|
|
$dh->rewind; |
104
|
|
|
|
|
|
|
scalar $dh->read; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
0
|
|
|
sub NEXTKEY { |
108
|
0
|
|
|
|
|
|
my($dh) = @_; |
109
|
|
|
|
|
|
|
scalar $dh->read; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
|
|
sub EXISTS { |
113
|
0
|
|
|
|
|
|
my($dh,$key) = @_; |
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
-e File::Spec->catfile(${*$dh}{io_dir_path}, $key); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
0
|
|
|
sub FETCH { |
118
|
0
|
|
|
|
|
|
my($dh,$key) = @_; |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
&lstat(File::Spec->catfile(${*$dh}{io_dir_path}, $key)); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
|
|
sub STORE { |
123
|
0
|
0
|
|
|
|
|
my($dh,$key,$data) = @_; |
124
|
0
|
|
|
|
|
|
my($atime,$mtime) = ref($data) ? @$data : ($data,$data); |
|
0
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
my $file = File::Spec->catfile(${*$dh}{io_dir_path}, $key); |
126
|
0
|
|
|
|
|
|
unless(-e $file) { |
127
|
0
|
0
|
|
|
|
|
my $io = IO::File->new($file,O_CREAT | O_RDWR); |
128
|
|
|
|
|
|
|
$io->close if $io; |
129
|
0
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
utime($atime,$mtime, $file); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
0
|
|
|
sub DELETE { |
134
|
|
|
|
|
|
|
my($dh,$key) = @_; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
# Only unlink if unlink-ing is enabled |
137
|
0
|
0
|
|
|
|
|
return 0 |
138
|
|
|
|
|
|
|
unless ${*$dh}{io_dir_unlink}; |
139
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $file = File::Spec->catfile(${*$dh}{io_dir_path}, $key); |
141
|
0
|
0
|
|
|
|
|
|
142
|
|
|
|
|
|
|
-d $file |
143
|
|
|
|
|
|
|
? rmdir($file) |
144
|
|
|
|
|
|
|
: unlink($file); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |