App-MaMGal

 view release on metacpan or  search on metacpan

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


sub log_message
{
	my $self = shift;
	my $msg = shift;
	my $prefix = shift || '';
	$prefix .= ': ' if $prefix;
	$self->{fh}->printf("%s%s\n", $prefix, $msg);
}

our $not_available_warned_before = 0;
our $exe_failure_warned_before = 0;

sub log_exception
{
	my $self = shift;
	my $e = shift;
	my $prefix = shift;
	if ($e->isa('App::MaMGal::MplayerWrapper::NotAvailableException')) {
		# TODO this needs to be made thread-safe
		return if $not_available_warned_before;
		$not_available_warned_before = 1;
	} elsif ($e->isa('App::MaMGal::MplayerWrapper::ExecutionFailureException')) {
		# TODO this needs to be made thread-safe
		goto JUST_LOG if $exe_failure_warned_before or (! $e->stdout and ! $e->stderr);
		$exe_failure_warned_before = 1;
		$self->log_message($e->message, $prefix);
		$self->log_message('--------------------- standard output messages -------------------', $prefix);
		$self->log_message($_, $prefix) for $e->stdout ? @{$e->stdout} : ();
		$self->log_message('--------------------- standard error messages --------------------', $prefix);
		$self->log_message($_, $prefix) for $e->stderr ? @{$e->stderr} : ();
		$self->log_message('------------------------------------------------------------------', $prefix);

t/010_logger.t  view on Meta::CPAN

	printed_only_ok($self->{mock_fh}, qr{^foo bar$});# log_exception prints a message even second time
	$self->{mock_fh}->clear;

	warnings_are { $self->{l}->log_exception($e, 'prefix') } [], 'log_message with prefix causes no warnings';
	printed_only_ok($self->{mock_fh}, qr{^prefix: foo bar$});# log_message with prefix prints a message first time
	$self->{mock_fh}->clear;
	warnings_are { $self->{l}->log_exception($e, 'prefix') } [], 'log_message with prefix causes no warnings second time either';
	printed_only_ok($self->{mock_fh}, qr{^prefix: foo bar$});# log_message with prefix prints a message even second time
}

sub log_not_available_exception : Tests(7)
{
	my $self = shift;
	my $e = get_mock_exception 'App::MaMGal::MplayerWrapper::NotAvailableException';
	warnings_are { $self->{l}->log_exception($e, 'prefix') } [], 'log_exception with prefix causes no warnings';
	printed_only_ok($self->{mock_fh}, qr{^prefix: foo bar$});# log_exception with prefix prints a message first time
	$self->{mock_fh}->clear;
	warnings_are { $self->{l}->log_exception($e, 'prefix') } [], 'log_exception with prefix causes no warnings second time either';
	is($self->{mock_fh}->next_call, undef, 'reading image without an mplayer on the second time prints no message');
}

t/010_unit_command_checker.t  view on Meta::CPAN

	ok($self->{c}->is_available('true'), '/bin/true should always be there');
}

sub check_false : Test(1) {
	my $self = shift;
	ok($self->{c}->is_available('false'), '/bin/false should always be there');
}

sub check_inexistent : Test(1) {
	my $self = shift;
	ok(! $self->{c}->is_available('something_that_cannot_be_available'), 'an uninstalled command is not available');
}

App::MaMGal::Unit::CommandChecker->runtests unless defined caller;
1;

t/010_unit_imageinfo.t  view on Meta::CPAN

sub when_all_tags_present_and_parse_then_creation_time_returns_datetime_original: Test(4) {
	my $self = shift;
	my %parse_map = (
		'2008:11:27 20:43:51' => sub { 1234567891 },
		'2008:11:27 20:43:52' => sub { 1234567892 },
		'2008:11:27 20:43:53' => sub { 1234567893 },
	);
	$self->_test_creation_time('jpg', \%parse_map, 1234567893, 'datetime_original');
}

sub when_all_tags_present_and_just_datetime_original_does_not_parse_then_creation_time_returns_datetime_digitized : Test(4) {
	my $self = shift;
	my %parse_map = (
		'2008:11:27 20:43:51' => sub { 1234567891 },
		'2008:11:27 20:43:52' => sub { 1234567892 },
		'2008:11:27 20:43:53' => sub { undef },
	);
	$self->_test_creation_time('jpg', \%parse_map, 1234567891, 'datetime_digitized');
}

sub when_all_tags_present_and_just_datetime_parses_then_creation_time_returns_datetime : Test(4) {

t/010_unit_imageinfo.t  view on Meta::CPAN

sub when_all_tags_present_and_none_parses_then_creation_time_returns_undef : Test(4) {
	my $self = shift;
	my %parse_map = (
		'2008:11:27 20:43:51' => sub { undef },
		'2008:11:27 20:43:52' => sub { undef },
		'2008:11:27 20:43:53' => sub { undef },
	);
	$self->_test_creation_time('jpg', \%parse_map, undef, 'undef');
}

sub when_datetime_original_tag_not_present_and_rest_parse_then_creation_time_returns_datetime_digitized : Test(4) {
	my $self = shift;
	my %parse_map = (
		'2008:11:27 20:43:51' => sub { 1234567891 },
		'2008:11:27 20:43:52' => sub { 1234567892 },
	);
	$self->_test_creation_time('jpg_no_0x9003', \%parse_map, 1234567891, 'datetime_digitized');
}

sub when_datetime_original_tag_not_present_and_just_datetime_parses_then_creation_time_returns_datetime_digitized : Test(4) {
	my $self = shift;
	my %parse_map = (
		'2008:11:27 20:43:51' => sub { undef },
		'2008:11:27 20:43:52' => sub { 1234567892 },
	);
	$self->_test_creation_time('jpg_no_0x9003', \%parse_map, 1234567892, 'datetime');
}

sub when_datetime_original_tag_not_present_and_none_parses_then_creation_time_returns_undef : Test(4) {
	my $self = shift;
	my %parse_map = (
		'2008:11:27 20:43:51' => sub { undef },
		'2008:11:27 20:43:52' => sub { undef },
	);
	$self->_test_creation_time('jpg_no_0x9003', \%parse_map, undef, 'undef');
}


sub when_just_datetime_tag_present_and_parses_then_creation_time_returns_datetime : Test(4) {

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

	is($ret[0], $self->relative_slide_path($infix), "refesh_slide call returns the perhaps-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');
	$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();

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

use Image::EXIF::DateTime::Parser;
use App::MaMGal::EntryFactory;
use App::MaMGal::ImageInfoFactory;
use POSIX;

prepare_test_data;
my $time_now  = time;
my $time_past = POSIX::mktime(25,6,8,17,3,109,0,0,1);
cmp_ok($time_past + 3600, '<', $time_now, 'your clock is wrong');
my $time_old  = POSIX::mktime(0,0,0,18,11,104);# in 2004 - "very old"
my $time_not_oldest = $time_old + 3600;# whatever time between "past" and "old" to keep other entries from interfering
# touch up the directory and picture with different times
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,



( run in 1.290 second using v1.01-cache-2.11-cpan-0a987023a57 )