App-MaMGal

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

         "requires" : {
            "Carp" : "0",
            "Cwd" : "0",
            "Exception::Class" : "0",
            "Fcntl" : "0",
            "File::Basename" : "0",
            "File::Temp" : "0",
            "File::stat" : "0",
            "FileHandle" : "0",
            "HTML::Entities" : "0",
            "Image::EXIF::DateTime::Parser" : "0",
            "Image::ExifTool" : "0",
            "Image::Info" : "0",
            "Image::Magick" : "0",
            "Locale::gettext" : "0",
            "POSIX" : "0",
            "Scalar::Util" : "0",
            "Test::Class" : "0",
            "Test::Exception" : "0",
            "Test::Files" : "0",
            "Test::HTML::Content" : "0",

META.yml  view on Meta::CPAN

requires:
  Carp: 0
  Cwd: 0
  Exception::Class: 0
  Fcntl: 0
  File::Basename: 0
  File::Temp: 0
  File::stat: 0
  FileHandle: 0
  HTML::Entities: 0
  Image::EXIF::DateTime::Parser: 0
  Image::ExifTool: 0
  Image::Info: 0
  Image::Magick: 0
  Locale::gettext: 0
  POSIX: 0
  Scalar::Util: 0
  Test::Class: 0
  Test::Exception: 0
  Test::Files: 0
  Test::HTML::Content: 0

Makefile.PL  view on Meta::CPAN

# Required for runtime
		'Carp' => 0,
		'Cwd' => 0,
		'Exception::Class' => 0,
		'Fcntl' => 0,
		'File::Basename' => 0,
		'File::stat' => 0,
		'File::Temp' => 0,
		'FileHandle' => 0,
		'HTML::Entities' => 0,
		'Image::EXIF::DateTime::Parser' => 0,
		'Image::Magick' => 0,
		'Locale::gettext' => 0,
		'POSIX' => 0,
		'Scalar::Util' => 0,
		'URI::file' => 0,
# Only one of these is necessary at runtime, but both are required for tests.
		'Image::ExifTool' => 0,
		'Image::Info' => 0,
# Required for tests only
		'Test::Class' => 0,

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

# The wrapper-for-everything module
package App::MaMGal;
use strict;
use warnings;
use base 'App::MaMGal::Base';
# Remeber to change po/mamgal.pot as well
our $VERSION = '1.6';
our $AUTOLOAD;
use Carp;
use FileHandle;
use Image::EXIF::DateTime::Parser;
use Locale::gettext;

use App::MaMGal::CommandChecker;
use App::MaMGal::EntryFactory;
use App::MaMGal::Formatter;
use App::MaMGal::ImageInfoFactory;
use App::MaMGal::LocaleEnv;
use App::MaMGal::Maker;
use App::MaMGal::MplayerWrapper;

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

	if (@_) {
		$locale_env = App::MaMGal::LocaleEnv->new($logger);
		$locale_env->set_locale($_[0]);
		textdomain('mamgal');
	} else {
		$locale_env = App::MaMGal::LocaleEnv->new($logger);
	}
	my $formatter = App::MaMGal::Formatter->new($locale_env);
	my $command_checker = App::MaMGal::CommandChecker->new;
	my $mplayer_wrapper = App::MaMGal::MplayerWrapper->new($command_checker);
	my $datetime_parser = Image::EXIF::DateTime::Parser->new;
	my $image_info_factory = App::MaMGal::ImageInfoFactory->new($datetime_parser, $logger);
	my $entry_factory = App::MaMGal::EntryFactory->new($formatter, $mplayer_wrapper, $image_info_factory, $logger);
	my $maker = App::MaMGal::Maker->new($entry_factory);

	$self->{maker} = $maker;
	$self->{logger} = $logger;

}

sub DESTROY {} # avoid using AUTOLOAD

lib/App/MaMGal/ImageInfo/Base.pm  view on Meta::CPAN

		my $e = $@;
		return $value if $value;
		if ($e) {
			chomp $e;
			$self->{logger}->log_message(sprintf('EXIF tag %s: %s', $methods_to_tags{$method}, $e), $self->{file_name});
		}
	}
	return undef;
}

# EXIF v2.2 tag 0x9003 DateTimeOriginal
# "when the original image data was generated"
#
# aka. Date/Time Original (exiftool output)
# aka. DateTimeOriginal (Image::ExifTool::Exif)
# aka. DateTimeOriginal (Image::Info, Image::TIFF)
sub datetime_original_string { croak "Missing implementation" }

# EXIF v2.2 tag 0x9004 DateTimeDigitized
# "when the image was stored as digital data"
#
# aka. Create Date (exiftool output)
# aka. CreateDate (Image::ExifTool::Exif)
# aka. DateTimeDigitized (Image::Info, Image::TIFF)
sub datetime_digitized_string { croak "Missing implementation" }

# EXIF v2.2 tag 0x0132 DateTime
# "of image creation"
#
# aka. Modify Date (exiftool output)
# aka. ModifyDate (Image::ExifTool::Exif)
# aka. DateTime (Image::Info, Image::TIFF)
sub datetime_string { croak "Missing implementation" }

sub description { croak "Missing implementation" }

1;

lib/App/MaMGal/ImageInfo/ExifTool.pm  view on Meta::CPAN

use base 'App::MaMGal::ImageInfo::Base';
use Carp;

use Image::ExifTool 'ImageInfo';

sub get_info
{
	my $self = shift;
	my $file = shift;
	my $tool = Image::ExifTool->new;
	my $ret = $tool->ExtractInfo($file, [qw(Comment exif:CreateDate exif:ModifyDate exif:DateTimeOriginal)]);
	my $info = $tool->GetInfo;
	croak $info->{Error} unless $ret;
	return $info;
}

sub datetime_original_string
{
	my $self = shift;
	$self->{info}->{DateTimeOriginal};
}

sub datetime_digitized_string
{
	my $self = shift;
	$self->{info}->{CreateDate};
}

sub datetime_string
{

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

	my $self = shift;
	my $file = shift;
	my $info = Image::Info::image_info($file);
	croak $info->{error} if exists $info->{error};
	return $info;
}

sub datetime_original_string
{
	my $self = shift;
	$self->{info}->{DateTimeOriginal};
}

sub datetime_digitized_string
{
	my $self = shift;
	$self->{info}->{DateTimeDigitized};
}

sub datetime_string
{
	my $self = shift;
	$self->{info}->{DateTime};
}

sub description
{
	my $self = shift;
	$self->{info}->{Comment};
}

1;

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

	} elsif (eval "require App::MaMGal::ImageInfo::ImageInfo") {
		$implementation = 'App::MaMGal::ImageInfo::ImageInfo';
	} else {
		App::MaMGal::SystemException->throw(message => 'No usable image info library found (looked for "Image::ExifTool" and "Image::Info" in %s).', objects => [join(':', @INC)]);;
	}
}

sub init
{
	my $self = shift;
	my $parser = shift or croak "A Image::EXIF::DateTime::Parser argument is required";
	ref $parser and $parser->isa('Image::EXIF::DateTime::Parser') or croak "Arg is not an Image::EXIF::DateTime::Parser , but a [$parser]";
	my $logger = shift or croak "A App::MaMGal::Logger argument is required";
	ref $logger and $logger->isa('App::MaMGal::Logger') or croak "Arg is not an App::MaMGal::Logger, but a [$logger]";
	$self->{parser} = $parser;
	$self->{logger} = $logger;
}

sub read {
	my $self = shift;
	my $o = $implementation->new(@_);
	$o->{parser} = $self->{parser};

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

package App::MaMGal::Unit::Entry::Picture;
use strict;
use warnings;
use Carp qw(verbose confess);
use Test::More;
use Test::Exception;
use Test::Files;
use Test::HTML::Content;
use lib 'testlib';
use File::stat;
use Image::EXIF::DateTime::Parser;
use App::MaMGal::ImageInfoFactory;
use App::MaMGal::TestHelper;
BEGIN { our @ISA = 'App::MaMGal::Unit::Entry' }
BEGIN { do 't/050_unit_entry.t' }

sub pre_class_setting : Test(startup) {
	my $self = shift;
	$self->{tools} = {
		mplayer_wrapper => App::MaMGal::TestHelper->get_mock_mplayer_wrapper,
		formatter => App::MaMGal::TestHelper->get_mock_formatter('format_slide'),
		image_info_factory => App::MaMGal::ImageInfoFactory->new(Image::EXIF::DateTime::Parser->new, get_mock_logger),
	};
}

sub entry_tools_setup : Test(setup => 0) {
	my $self = shift;
	$self->{entry}->add_tools($self->{tools});
	$self->{entry_no_stat}->add_tools($self->{tools});
}

sub _touch

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

# See the README file for license information
use strict;
use warnings;
use Carp 'verbose';
use Test::More tests => 40;
use Test::Exception;
use Test::Files;
use lib 'testlib';
use App::MaMGal::TestHelper;
use File::stat;
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

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

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);

my @ret = $d->elements;
is(scalar(@ret), 5,						"dir contains 5 elements");

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

# See the README file for license information
use strict;
use warnings;
use Carp 'verbose';
use Test::More tests => 21;
use Test::Exception;
use Test::Files;
use lib 'testlib';
use App::MaMGal::TestHelper;
use File::stat;
use Image::EXIF::DateTime::Parser;
use App::MaMGal::ImageInfoFactory;
use App::MaMGal::EntryFactory;

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);

my @ret = $d->elements;
is(scalar(@ret), 1,						"dir contains one element");

t/500_integration_formatter_one_picture.t  view on Meta::CPAN

# Copyright 2007, 2008 Marcin Owsiany <marcin@owsiany.pl>
# See the README file for license information
use strict;
use warnings;
use Carp 'verbose';
use Test::More tests => 40;
use Test::HTML::Content;
use Test::Exception;
use lib 'testlib';
use App::MaMGal::TestHelper;
use Image::EXIF::DateTime::Parser;
use App::MaMGal::ImageInfoFactory;

prepare_test_data;

use App::MaMGal::Formatter;
use App::MaMGal::EntryFactory;
use App::MaMGal::LocaleEnv;
my $le = App::MaMGal::LocaleEnv->new(get_mock_logger);
$le->set_locale('C');
my $f = App::MaMGal::Formatter->new($le);
my $edtp = Image::EXIF::DateTime::Parser->new;
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $ef = App::MaMGal::EntryFactory->new($f, get_mock_mplayer_wrapper, $iif, get_mock_logger);

#
# a dir with a single pic _without_ description
#

my $time = 1228933448;
utime($time, $time, 'td/more/zzz another subdir/p.png') == 1 or die "Failed to touch file";
my $dir_nd = $ef->create_entry_for('td/more/zzz another subdir');

t/500_integration_formatter_slides_sequence.t  view on Meta::CPAN

# mamgal - a program for creating static image galleries
# Copyright 2007, 2008 Marcin Owsiany <marcin@owsiany.pl>
# See the README file for license information
use strict;
use warnings;
use Carp 'verbose';
use Test::More tests => 11;
use Test::HTML::Content;
use lib 'testlib';
use App::MaMGal::TestHelper;
use Image::EXIF::DateTime::Parser;
use App::MaMGal::ImageInfoFactory;

prepare_test_data;

use App::MaMGal::Formatter;
use App::MaMGal::EntryFactory;
use App::MaMGal::LocaleEnv;
my $le = App::MaMGal::LocaleEnv->new(get_mock_logger);
$le->set_locale('C');
my $edtp = Image::EXIF::DateTime::Parser->new,
my $f = App::MaMGal::Formatter->new($le);
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $ef = App::MaMGal::EntryFactory->new($f, get_mock_mplayer_wrapper, $iif, get_mock_logger);
my $d = $ef->create_entry_for('td/more');

my @elems = $d->elements;
my $p = $elems[1];
my $t = $f->format_slide($p);
tag_ok($t, "img", {src => '../.mamgal-medium/b.png'}, "b.png: there is a medium pic on the page");
tag_ok($t, "a", {href => '../index.html'},           "b.png: there is a link to the index on the page");

testlib/App/MaMGal/TestHelper.pm  view on Meta::CPAN

sub get_mock_logger {
	my $l = Test::MockObject->new
		->mock('log_message')
		->mock('log_exception');
	$l->set_isa('App::MaMGal::Logger');
	$l
}

sub get_mock_datetime_parser {
	my $p = Test::MockObject->new->mock('parse');
	$p->set_isa('Image::EXIF::DateTime::Parser');
	$p
}

sub get_mock_formatter {
	my @methods = @_;
	my $mf = Test::MockObject->new();
	$mf->set_isa('App::MaMGal::Formatter');
	$mf->mock($_, sub { "whatever" }) for @methods;
	return $mf;
}



( run in 0.446 second using v1.01-cache-2.11-cpan-496ff517765 )