3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.6 2002/11/17 07:18:59 joko |
7 |
|
# + sub deep_copy |
8 |
|
# |
9 |
|
# Revision 1.5 2002/10/27 18:34:28 joko |
10 |
|
# + sub now |
11 |
|
# |
12 |
|
# Revision 1.4 2002/08/16 19:06:39 cvsjoko |
13 |
|
# + sub getDirList |
14 |
|
# |
15 |
# Revision 1.3 2002/07/19 18:13:50 cvsjoko |
# Revision 1.3 2002/07/19 18:13:50 cvsjoko |
16 |
# no message |
# no message |
17 |
# |
# |
36 |
stripHtml stripSpaces stripNewLines toReal trim |
stripHtml stripSpaces stripNewLines toReal trim |
37 |
croak |
croak |
38 |
array_getDifference |
array_getDifference |
39 |
|
getDirList |
40 |
|
now |
41 |
|
deep_copy |
42 |
); |
); |
43 |
|
|
44 |
use strict; |
use strict; |
59 |
|
|
60 |
use Carp; |
use Carp; |
61 |
|
|
62 |
|
use DirHandle; |
63 |
|
|
64 |
|
|
65 |
######################################## |
######################################## |
66 |
|
|
141 |
return $res->{diff}; |
return $res->{diff}; |
142 |
} |
} |
143 |
|
|
144 |
|
|
145 |
|
# ============================================= |
146 |
|
# "global" vars used in directory-recursive-parsing |
147 |
|
my $dirlist_buf; |
148 |
|
my @dirlist_path; |
149 |
|
my $dirlist_base; |
150 |
|
|
151 |
|
sub entry_callback { |
152 |
|
|
153 |
|
my $entry = shift; |
154 |
|
|
155 |
|
# CHECKS |
156 |
|
# dont't use this: |
157 |
|
if ($entry eq '.' || $entry eq '..') { return; } |
158 |
|
|
159 |
|
# PREPARE |
160 |
|
# prepare path to current entry |
161 |
|
my $cur_entry = join('/', @dirlist_path, $entry); |
162 |
|
# prepare path to current entry (absolute) |
163 |
|
my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry); |
164 |
|
|
165 |
|
# ENTRY |
166 |
|
# add current entry to buffer |
167 |
|
$dirlist_buf .= $cur_entry . "\n"; |
168 |
|
|
169 |
|
# (SUB-)DIRECTORY |
170 |
|
# check if current entry is a (sub-)directory ... |
171 |
|
if (-d $cur_entry_abs) { |
172 |
|
push @dirlist_path, $cur_entry; |
173 |
|
# ... and parse this (recursion here!!!) |
174 |
|
iterate_path($cur_entry_abs); |
175 |
|
pop @dirlist_path; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
sub iterate_path { |
180 |
|
|
181 |
|
my $path = shift; |
182 |
|
|
183 |
|
# create new "DirHandle"-object |
184 |
|
my $d = new DirHandle $path; |
185 |
|
if (defined $d) { |
186 |
|
|
187 |
|
# iterate through all entries in $path ($d->read) and call out entry-handler on each entry |
188 |
|
while (defined(my $line = $d->read)) { |
189 |
|
entry_callback($line); |
190 |
|
} |
191 |
|
|
192 |
|
undef $d; |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
|
sub getDirList { |
197 |
|
|
198 |
|
$dirlist_base = shift; |
199 |
|
|
200 |
|
# reset vars |
201 |
|
$dirlist_buf = ''; |
202 |
|
@dirlist_path = (); |
203 |
|
|
204 |
|
# start parsing file-structure |
205 |
|
iterate_path($dirlist_base); |
206 |
|
|
207 |
|
# return complete list of directory-content including files and subdirs |
208 |
|
# entries are newline (\n) - seperated |
209 |
|
return $dirlist_buf; |
210 |
|
|
211 |
|
} |
212 |
|
# ============================================= |
213 |
|
|
214 |
|
|
215 |
|
sub now { |
216 |
|
return strftime("%Y-%m-%d %H:%M:%S", localtime); |
217 |
|
} |
218 |
|
|
219 |
|
sub deep_copy { |
220 |
|
my $this = shift; |
221 |
|
if (not ref $this) { |
222 |
|
$this; |
223 |
|
} elsif (ref $this eq "ARRAY") { |
224 |
|
[map deep_copy($_), @$this]; |
225 |
|
} elsif (ref $this eq "HASH") { |
226 |
|
+{map { $_ => deep_copy($this->{$_}) } keys %$this}; |
227 |
|
} elsif (ref $this eq "CODE") { |
228 |
|
$this; |
229 |
|
} else { die "what type is $_?" } |
230 |
|
} |
231 |
|
|
232 |
1; |
1; |