FileCache.pm revision 7c478bd95313f5f23a4c958a745db2134aa03244
package FileCache;
=head1 NAME
FileCache - keep more files open than the system permits
=head1 SYNOPSIS
cacheout $path;
print $path @data;
=head1 DESCRIPTION
The C<cacheout> function will make sure that there's a filehandle open
for writing available as the pathname you give it. It automatically
closes and re-opens files if you exceed your system file descriptor
maximum.
=head1 BUGS
so you may have to set $FileCache::cacheout_maxopen yourself.
=cut
require 5.000;
use Carp;
use Exporter;
@EXPORT = qw(
);
# Open in their package.
sub cacheout_open {
my $pack = caller(1);
}
sub cacheout_close {
my $pack = caller(1);
}
# But only this sub name is visible to them.
$cacheout_seq = 0;
$cacheout_numopen = 0;
sub cacheout {
($file) = @_;
unless (defined $cacheout_maxopen) {
local ($_, $.);
while (<PARAM>) {
if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
}
close PARAM;
}
}
if (++$cacheout_numopen > $cacheout_maxopen) {
$cacheout_numopen -= @lru;
}
or croak("Can't create $file: $!");
}
}
1;