App-MaMGal

 view release on metacpan or  search on metacpan

lib/App/MaMGal/Entry.pm  view on Meta::CPAN

{
	my $self = shift;
	return $self->App::MaMGal::Entry::creation_time(@_);
}

sub fresher_than_me
{
	my $self = shift;
	my $path = shift;
	my %opts = @_;
	my $stat = stat($path) or return 0;
	return 1 if $stat->mtime >= $self->content_modification_time(%opts);
	return 0;
}

# Whether this entry should be shown in a directory contents montage
sub is_interesting { }

# Some constants
our $slides_dir = '.mamgal-slides';
sub slides_dir     { $slides_dir }

lib/App/MaMGal/EntryFactory.pm  view on Meta::CPAN

}


sub create_entry_for
{
	my $self = shift;
	my $path_arg = shift or croak "Need path"; # absolute, or relative to CWD
	croak "Need 1 arg, got more: [$_[0]]" if @_;

	my ($path, $dirname, $basename) = canonicalize_path($path_arg);
	my $lstat = lstat($path) or App::MaMGal::SystemException->throw(message => '%s: getting status failed: %s', objects => [$path, $!]);
	my $stat = $lstat;
	if ($lstat->mode & S_IFLNK) {
		$stat = stat($path);
	}

	my $e;
	if (not $stat) {
		$e = App::MaMGal::Entry::BrokenSymlink->new($dirname, $basename, $lstat)

	} elsif ($stat->mode & S_IFDIR) {
		$e = App::MaMGal::Entry::Dir->new($dirname, $basename, $stat)

	} elsif (($stat->mode & S_IFREG) and sounds_like_picture($path)) {

t/050_unit_entry.t  view on Meta::CPAN


sub parameter_checks : Test(startup => 6) {
	my $self = shift;
	my $class_name = $self->{class_name};

	dies_ok(sub { $class_name->new },                             "$class_name dies on creation with no args");
	dies_ok(sub { $class_name->new('/') },                        "$class_name dies on creation with one arg");
	dies_ok(sub { $class_name->new($self->file_name, 1) },       "$class_name dies on creation with third argument not being a File::stat");
	dies_ok(sub { $class_name->new(qw(td/empty .)) },             "$class_name refuses to be created with '.' as the basename, when a name could have been provided");
	dies_ok(sub { $class_name->new(qw(. td/empty)) },             "$class_name refuses to be created with basename containing a slash");
	my $stat = stat('td/empty_file');
	dies_ok(sub { $class_name->new(qw(td empty_file), $stat, 3) },"$class_name dies on creation with more than 3 args");
}

sub _entry_creation : Test(setup => 4) {
	my $self = shift;
	my $class_name = $self->{class_name};

	my $fake_stat = Test::MockObject->new;
	$fake_stat->set_isa('File::stat');
	$fake_stat->mock('mtime', sub { '1229888888' });

t/080_unit_picture.t  view on Meta::CPAN

	$self->{mock_container}->clear;
}

sub miniature_not_rewriting : Test(3) {
	my $self = shift;
	my $file_mtime = $self->{entry}->{stat}->mtime;
	my $miniature_mtime = $file_mtime + 60;
	my $infix = 'rewriting_miniature-'.$self->{class_name};
	$self->_touch($infix, $miniature_mtime);
	my $path = $self->miniature_path($infix);
	my $stat_before = stat($path) or die "Cannot stat [$path]: $!";
	is($stat_before->mtime, $miniature_mtime);
	my @ret = $self->call_refresh_miniatures($infix);
	is($ret[0], $self->relative_miniature_path($infix), "refesh_miniatures call returns the not-refreshed path");
	my $stat_after = stat($path) or die "Cannot stat: $!";
	is($stat_after->mtime, $miniature_mtime);
}

sub slide_not_rewriting : Test(3) {
	my $self = shift;
	my $file_mtime = $self->{entry}->{stat}->mtime;
	my $slide_mtime = $file_mtime + 60;
	my $infix = 'rewriting_slide-'.$self->{class_name};
	$self->_touch($infix, $slide_mtime, '.html');
	my $path = $self->slide_path($infix);
	my $stat_before = stat($path) or die "Cannot stat [$path]: $!";
	is($stat_before->mtime, $slide_mtime);
	local $App::MaMGal::Entry::slides_dir = $infix;
	my @ret = $self->call_refresh_slide();
	is($ret[0], $self->relative_slide_path($infix), "refesh_slide call returns the not-refreshed path");
	my $stat_after = stat($path) or die "Cannot stat: $!";
	is($stat_after->mtime, $slide_mtime, 'timestamp did not change after refresh_slide()');
}

sub miniature_refreshing : Test(4) {
	my $self = shift;
	my $file_mtime = $self->{entry}->{stat}->mtime;
	# make the miniature older than the source file
	my $miniature_mtime = $file_mtime - 60;
	my $infix = 'refreshed_miniature-'.$self->{class_name};
	$self->_touch($infix, $miniature_mtime);
	my $path = $self->miniature_path($infix);
	my $stat_before = stat($path) or die "Cannot stat: $!";
	is($stat_before->mtime, $miniature_mtime);
	my @ret = $self->call_refresh_miniatures($infix);
	is($ret[0], $self->relative_miniature_path($infix), "refesh_miniatures call returns the refreshed path");
	my $stat_after = stat($path) or die "Cannot stat: $!";
	cmp_ok($stat_after->mtime, '>', $miniature_mtime, 'refreshed miniature mtime is newer than its previous mtime');
	cmp_ok($stat_after->mtime, '>', $file_mtime, 'refreshed miniature mtime is newer than its source file\'s mtime');
}

sub slide_refreshing : Test(6) {
	my $self = shift;
	my $file_mtime = $self->{entry}->{stat}->mtime;
	# make the slide older than the source file
	my $slide_mtime = $file_mtime - 60;
	my $infix = 'refreshed_slide-'.$self->{class_name};
	$self->_touch($infix, $slide_mtime, '.html');
	my $path = $self->slide_path($infix);
	my $stat_before = stat($path) or die "Cannot stat: $!";
	is($stat_before->mtime, $slide_mtime);
	local $App::MaMGal::Entry::slides_dir = $infix;
	my @ret = $self->call_refresh_slide();
	is($ret[0], $self->relative_slide_path($infix), "refesh_slide call returns the refreshed path");
	my ($m, $args) = $self->{mock_container}->next_call;
	is($m, 'ensure_subdir_exists', 'subdir existence was ensured');
	is($args->[1], $infix, 'correct subdir was requested');
	($m, $args) = $self->{mock_container}->next_call;
	is($m, '_write_contents_to', 'slide was written');
	is($args->[2], $infix.'/'.$self->{test_file_name}->[1].'.html', 'correct slide path was requested');

t/300_integration_dir_with_many.t  view on Meta::CPAN

utime $time_past, $time_past, 'td/more/subdir/p.png'  or die "Touching p.png failed";
utime $time_old,  $time_old,  'td/more/subdir/p2.png' or die "Touching p2.png failed";
utime $time_old,  $time_now,  'td/more/subdir'        or die "Touching directory failed";
utime $time_not_oldest, $time_not_oldest,  'td/more/subdir/interesting' or die "Touching interesting failed";
utime $time_not_oldest, $time_not_oldest,  'td/more/subdir/uninteresting' or die "Touching uninteresting failed";
utime $time_not_oldest, $time_not_oldest,  'td/more/subdir/interesting/b.png' or die "Touching b.png failed";
utime $time_not_oldest, $time_not_oldest,  'td/more/subdir/uninteresting/bar.txt' or die "Touching bar.txt failed";

use_ok('App::MaMGal::Entry::Dir');
my $d;
lives_ok(sub { $d = App::MaMGal::Entry::Dir->new(qw(td more), stat('td/more')) },	"creation ok");
isa_ok($d, 'App::MaMGal::Entry::Dir',                                 "a dir is a dir");
my $mf = get_mock_formatter(qw(format stylesheet));
my $edtp = Image::EXIF::DateTime::Parser->new;
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $tools = {
	formatter => $mf,
	entry_factory => App::MaMGal::EntryFactory->new($mf, get_mock_mplayer_wrapper, $iif, get_mock_logger),
	image_info_factory => $iif,
};
$d->add_tools($tools);

t/300_integration_dir_with_many.t  view on Meta::CPAN

# inherit the range of the subdir.
my $single_creation_time = $d->creation_time;
ok($single_creation_time, "There is some non-zero create time");
my @creation_time_range = $d->creation_time;
is(scalar @creation_time_range, 2, "Creation time range is not empty");
cmp_ok($creation_time_range[0], '<=', $single_creation_time, "Second time in range is greater equal than the first one");
is($creation_time_range[1], $single_creation_time, "Second time in the range is equal to the scalar one, although I no longer remember why I wanted it this way...");
is($creation_time_range[0], $time_old, "First time in the range is equal to the one of the oldest picture");
is($creation_time_range[1], $time_past, "Second time in the range is equal to the one of the newer picture");

my $subdir_interesting = App::MaMGal::Entry::Dir->new(qw(td/more/subdir interesting), stat('td/more/subdir/interesting'));
$subdir_interesting->add_tools($tools);
ok($subdir_interesting->is_interesting, 'interesting dir is interesting');
my $subdir_uninteresting = App::MaMGal::Entry::Dir->new(qw(td/more/subdir uninteresting), stat('td/more/subdir/uninteresting'));
$subdir_uninteresting->add_tools($tools);
ok(! $subdir_uninteresting->is_interesting, 'uninteresting dir is uninteresting');

#my ($one_pic_entry) = $d->elements();
#ok($one_pic_entry, "There is one picture");
#my $picture_creation_time = $one_pic_entry->creation_time;
#ok($picture_creation_time, "Picture has a creation time");
#is($single_creation_time, $picture_creation_time, "The creation times match");

t/300_integration_dir_with_one_file.t  view on Meta::CPAN

prepare_test_data;

my $time = time;
my $pic_time = $time - 120;
# touch up the directory and picture with different times
utime $time, $time, 'td/one_pic' or die "Touching directory failed";
utime $pic_time, $pic_time, 'td/one_pic/a1.png' or die "Touching picture failed";

use_ok('App::MaMGal::Entry::Dir');
my $d;
lives_ok(sub { $d = App::MaMGal::Entry::Dir->new(qw(td one_pic), stat('td/one_pic')) },   "dir can be created with an array: existant dir with one pic");
isa_ok($d, 'App::MaMGal::Entry::Dir');
my $mf = get_mock_formatter(qw(format stylesheet format_slide));
my $edtp = Image::EXIF::DateTime::Parser->new;
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $tools = {
	formatter => $mf,
	entry_factory => App::MaMGal::EntryFactory->new($mf, get_mock_mplayer_wrapper, $iif, get_mock_logger),
	image_info_factory => $iif,
};
$d->add_tools($tools);



( run in 1.336 second using v1.01-cache-2.11-cpan-49f99fa48dc )