Cache-Cache
view release on metacpan or search on metacpan
lib/Cache/FileBackend.pm view on Meta::CPAN
Assert_Defined( $p_directory );
-d $p_directory or
return ( );
local *Dir;
opendir( Dir, _Untaint_Path( $p_directory ) ) or
throw Error::Simple( "Couldn't open directory $p_directory: $!" );
my @dirents = readdir( Dir );
closedir( Dir ) or
throw Error::Simple( "Couldn't close directory $p_directory: $!" );
return @dirents;
}
# read in a file. returns a reference to the data read
sub _Read_File
{
my ( $p_path ) = @_;
Assert_Defined( $p_path );
local *File;
open( File, _Untaint_Path( $p_path ) ) or
return undef;
binmode( File );
local $/ = undef;
my $data_ref;
$$data_ref = <File>;
close( File );
return $data_ref;
}
# read in a file. returns a reference to the data read, without
# modifying the last accessed time
sub _Read_File_Without_Time_Modification
{
my ( $p_path ) = @_;
Assert_Defined( $p_path );
-e $p_path or
return undef;
my ( $file_access_time, $file_modified_time ) =
( stat( _Untaint_Path( $p_path ) ) )[8,9];
my $data_ref = _Read_File( $p_path );
utime( $file_access_time, $file_modified_time, _Untaint_Path( $p_path ) );
return $data_ref;
}
# remove a file
sub _Remove_File
{
my ( $p_path ) = @_;
Assert_Defined( $p_path );
if ( -f _Untaint_Path( $p_path ) )
{
# We don't catch the error, because this may fail if two
# processes are in a race and try to remove the object
unlink( _Untaint_Path( $p_path ) );
}
}
# remove a directory
sub _Remove_Directory
{
my ( $p_directory ) = @_;
Assert_Defined( $p_directory );
if ( -d _Untaint_Path( $p_directory ) )
{
# We don't catch the error, because this may fail if two
# processes are in a race and try to remove the object
rmdir( _Untaint_Path( $p_directory ) );
}
}
# recursively list the files of the subdirectories, without the full paths
sub _Recursively_List_Files
{
my ( $p_directory, $p_files_ref ) = @_;
return unless -d $p_directory;
foreach my $dirent ( _Read_Dirents( $p_directory ) )
{
next if $dirent eq '.' or $dirent eq '..';
my $path = Build_Path( $p_directory, $dirent );
if ( -d $path )
( run in 3.168 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )