Apache-EnvDir
view release on metacpan or search on metacpan
local *DIR;
local *FILE;
local $/ = undef;
die "couldn't find directory called $dirname\n" unless (-d $dirname && -x _);
# First time through, this creates an anonymous hash.
# On subsequent runs, the hash is cleared if $dirname's
# mtime has changed. This is how you get Apache::EnvDir
# to notice that files have gone away.
$dircfg->{mtime} ||= 0;
%$dircfg = () if (stat(_))[9] > $dircfg->{mtime};
$prefix ||= "";
$dircfg->{prefix} = $prefix;
$dircfg->{mtime} = (stat(_))[9];
local *DIR;
opendir(DIR, $dirname) || die "couldn't open $dirname\n";
local *FILE;
foreach my $file (readdir DIR) {
my $path = join("/", $dirname, $file);
# Only do files.
next unless (-f $path && -r _);
# Skip files that havn't changed.
$dircfg->{file}{$file} ||= [0,""];
next unless (stat(_))[9] > $dircfg->{file}{$file}[0];
$changeflag++;
$dircfg->{file}{$file}[0] = (stat(_))[9];
if(open FILE, $path) {
$dircfg->{file}{$file}[1] = <FILE>;
$dircfg->{file}{$file}[1] =~ s/[\r\n]$//g;
close(FILE);
} else {
$r->log_error("couldn't open $path") if $r;
}
}
closedir(DIR);
( run in 1.145 second using v1.01-cache-2.11-cpan-49f99fa48dc )