CGI-Application-PhotoGallery
view release on metacpan or search on metacpan
inc/Module/Install.pm view on Meta::CPAN
# we shouldn't really depend on it. See RT #24194 for detail.
# (Also, this module only supports Perl 5.6 and above).
eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006;
# If the script that is loading Module::Install is from the future,
# then make will detect this and cause it to re-run over and over
# again. This is bad. Rather than taking action to touch it (which
# is unreliable on some platforms and requires write permissions)
# for now we should catch this and refuse to run.
if ( -f $0 ) {
my $s = (stat($0))[9];
# If the modification time is only slightly in the future,
# sleep briefly to remove the problem.
my $a = $s - time;
if ( $a > 0 and $a < 5 ) { sleep 5 }
# Too far in the future, throw an error.
my $t = time;
if ( $s > $t ) { die <<"END_DIE" }
lib/CGI/Application/PhotoGallery.pm view on Meta::CPAN
my $parent = $user_dir;
$parent =~ s{^(.*?)/([^/]+?)/?$}{$1/};
my $directory = $photo_dir . $user_dir;
die "ERROR: File not found." unless -e $directory;
die "ERROR: '$directory' is not a directory" unless -d $directory;
my $output;
my $cache = $self->cache;
my $key = $directory;
my $lastmod = ( stat( $directory ) )[ 9 ];
my $cstamp = "$directory/.cachetime";
if ( $output = $cache->get( $key ) ) {
my $cachetime = $cache->get( $cstamp );
if ( $cachetime && $cachetime == $lastmod ) {
my $reqmod;
if ( my $header = $query->http( 'If-Modified-Since' ) ) {
$reqmod = HTTP::Date::str2time(
( split( /;/, $header, 2 ) )[ 0 ] );
lib/CGI/Application/PhotoGallery.pm view on Meta::CPAN
my $query = $self->query;
my $dir = $self->param( 'photos_dir' );
my $photo = $query->param( 'photo' );
my $size = $self->param( 'thumb_size' );
die 'ERROR: Missing photo query argument.' unless $photo;
my $path = "$dir$photo";
my $cache = $self->cache;
my $key = "$path$size";
my $lastmod = ( stat( $path ) )[ 9 ];
my $data;
if ( $data = $cache->get( $key ) ) {
my $reqmod;
if ( my $header = $query->http( 'If-Modified-Since' ) ) {
$reqmod
= HTTP::Date::str2time( ( split( /;/, $header, 2 ) )[ 0 ] );
}
if ( $reqmod && $reqmod == $lastmod ) {
lib/CGI/Application/PhotoGallery.pm view on Meta::CPAN
sub show_image {
my $self = shift;
my $query = $self->query;
my $dir = $self->param( 'photos_dir' );
my $photo = $query->param( 'photo' );
my $path = "$dir$photo";
die 'ERROR: Missing $photo query argument.' unless $photo;
my $lastmod = ( stat( $path ) )[ 9 ];
my $reqmod;
if ( my $header = $query->http( 'If-Modified-Since' ) ) {
$reqmod = HTTP::Date::str2time( ( split( /;/, $header, 2 ) )[ 0 ] );
}
if ( $reqmod && $reqmod == $lastmod ) {
$self->header_props( { -status => '304 Not Modified' } );
return;
}
lib/CGI/Application/PhotoGallery.pm view on Meta::CPAN
my $path = "$dir$photo";
die 'ERROR: Missing photo query argument.' unless $photo;
die 'ERROR: File not found' unless -e $path;
my $caption_path = "$dir/captions.txt";
my $output;
my $cache = $self->cache;
my $key = "$path.#frame";
my $lastmod = ( stat( $path ) )[ 9 ];
# Directory change means links may have changed
# Caption file change is a content change
my $lastdir = ( stat( $dir ) )[ 9 ];
$lastmod = $lastdir if ( $lastdir > $lastmod );
my $lastcap = 0;
$lastcap = ( stat( $caption_path ) )[ 9 ] if ( -r $caption_path );
$lastmod = $lastcap if ( $lastcap > $lastmod );
my $cstamp = "$key#cachetime";
if ( $output = $cache->get( $key ) ) {
my $cachetime = $cache->get( $cstamp );
if ( $cachetime && $cachetime == $lastmod ) {
my $reqmod;
if ( my $header = $query->http( 'If-Modified-Since' ) ) {
$reqmod = HTTP::Date::str2time(
( split( /;/, $header, 2 ) )[ 0 ] );
( run in 0.724 second using v1.01-cache-2.11-cpan-49f99fa48dc )