Album
view release on metacpan or search on metacpan
script/album view on Meta::CPAN
my ($self) = @_;
sprintf("img%04d.html", $self->seq);
}
package FileList;
use Class::Struct "FileList" =>
[ _tally => '$',
_data => '$',
_hash => '$',
];
sub add {
my ($self, $el, $name) = @_;
my $data = $self->_data;
my $hash = $self->_hash;
$self->_hash($hash = {}) unless $hash;
$self->_data($data = []) unless $data;
push(@$data, $el);
$hash->{$name || $el->dest_name || ""} = $el;
$self->_tally(($self->_tally||0)+1);
$el->seq($self->_tally);
$self;
}
sub byname {
my ($self, $file) = @_;
$self->_hash ? $self->_hash->{$file} : undef;
}
sub entries {
my ($self) = @_;
$self->_data([]) unless $self->_data;
wantarray ? @{$self->_data} : $self->_data;
}
sub tally {
my ($self) = @_;
$self->_tally || 0;
}
sub byseq {
my ($self, $seq) = @_;
$self->_data ? $self->_data->[$seq-1] : undef;
}
#### Cache maintenance.
package ImageInfoCache;
use constant CACHE_VERSION => 3;
sub new {
my ($pkg, $file) = @_;
$pkg = ref($pkg) || $pkg;
my $self = bless({}, $pkg);
if ( defined($file) ) {
$self->load($file);
if ( ($self->{_version} || 1) != CACHE_VERSION ) {
warn("Incompatible cache version " . $self->version .
" -- invalidated\n") if $verbose;
$self = bless({}, $pkg);
}
}
$self->{_version} = CACHE_VERSION;
$self;
}
sub load {
my ($self, $file) = @_;
our $info;
$info = undef;
eval {
require $file;
};
if ( $@ ) {
warn("Illegal cache -- invalidated\n") if $verbose;
return;
}
@{$self}{keys(%$info)} = values(%$info);
}
sub store {
my ($self, $file) = @_;
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Sortkeys = 1; # avoid warnings
$Data::Dumper::Purity = 1;
my $cache = do { local *C; *C };
open($cache, ">$file")
and print $cache (Data::Dumper->Dump([$self],[qw(info)]), "\n1;\n")
and close($cache);
}
sub entry {
my ($self, $file, $entry) = @_;
$file =~ s;^\./;;;
if ( defined $entry ) {
$self->{$file} = $entry;
}
else {
$entry = $self->{$file};
}
$entry;
}
sub entries {
my ($self) = @_;
[ sort(keys(%{$self})) ];
}
sub version {
my ($self) = @_;
$self->{_version};
}
package main;
=head1 NAME
Album - create and maintain HTML based photo albums
=head1 SYNOPSIS
A photo album consists of a number of (large) pictures, small thumbnail
images, and index pages. Optionally, medium sized images can be
generated as well. The album will be organised as follows:
index.html first or only index page
indexN.html subsequent index pages (N = 1, 2, ...)
icons/ directory with navigation icons
large/ original (large) images, with HTML pages
medium/ optional medium sized images, with HTML pages
thumbnail/ thumbnail images
Each image can be labeled with a description, a tag (applies to a
group of images, e.g. a date), the image name, and some
( run in 0.596 second using v1.01-cache-2.11-cpan-13bb782fe5a )