App-MaMGal

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "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",
            "Test::MockObject" : "0",
            "Test::More" : "0",
            "Test::Warn" : "0",

META.yml  view on Meta::CPAN

  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
  Test::MockObject: 0
  Test::More: 0
  Test::Warn: 0

Makefile.PL  view on Meta::CPAN

		'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,
		'Test::Exception' => 0,

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

# Copyright 2007-2012 Marcin Owsiany <marcin@owsiany.pl>
# See the README file for license information
# The directory encapsulating class
package App::MaMGal::Entry::Dir;
use strict;
use warnings;
use base 'App::MaMGal::Entry';
use Carp;
use App::MaMGal::Entry::Picture;
use App::MaMGal::DirIcon;
use Image::Magick;
use App::MaMGal::Exceptions;

sub child            { $_[0]->{path_name}.'/'.$_[1]     }
sub page_path        { $_[0]->{base_name}.'/index.html' }
sub thumbnail_path   { $_[0]->{base_name}.'/.mamgal-index.png'  }

sub init
{
	my $self = shift;
	$self->SUPER::init(@_);

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

		return;
	}

	my $montage_path = $self->child('.mamgal-index.png');
	# Return early if the montage is fresh
	return if $self->fresher_than_me($montage_path, consider_interesting_only => 1) and $pruned_files == 0;

	# Get just a bunch of images, not all of them.
	my $montage_count = scalar @images > 36 ? 36 : scalar @images;
	# Stack them all together
	my $stack = Image::Magick->new;
	push @$stack, map {
		my $img = Image::Magick->new;
		my $rr;
		$rr = $img->Read($_->tile_path) and App::MaMGal::SystemException->throw(message => '%s: %s', objects => [$_->tile_path, $rr]);
		$img->[0] or $img } @images[0..($montage_count-1)];

	my $side = $self->_side_length($montage_count);

	my ($m_x, $m_y) = (200, 150);

	my ($montage, $r);
	# Do the magick, scale and write.

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

sub page_path { $_[0]->slides_dir.'/'.$_[0]->{base_name}.'.html' }
sub thumbnail_path { $_[0]->thumbnails_dir.'/'.$_[0]->{base_name} }
sub tile_path { $_[0]->{dir_name}.'/'.$_[0]->thumbnail_path }

# This method does not operate on App::MaMGal::Entry::Picture, but this was the most
# appropriate place to put it into.  At least until we grow a "utils" class.
sub scale_into
{
	my $that = shift;
	my $img = shift;
	ref($img) and $img->isa('Image::Magick') or croak "Need arg: an image";
	my ($x, $y) = @_;

	my $r;
	my ($x_pic, $y_pic) = $img->Get('width', 'height');
	my ($x_ratio, $y_ratio) = ($x_pic / $x, $y_pic / $y);
	if ($x_ratio <= 1 and $y_ratio <= 1) {
		return; # no need to scale
	} elsif ($x_ratio > $y_ratio) {
		return $img->Scale(width => $x, height => $y_pic / $x_ratio);
	} else {

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


sub refresh_scaled_pictures
{
	my $self = shift;
	return $self->refresh_miniatures([$self->thumbnails_dir, 200, 150, $thumbnail_extension]);
}

sub _new_video_icon
{
	my $self = shift;
	my $s = Image::Magick->new(magick => 'png');
	$s->BlobToImage(App::MaMGal::VideoIcon->img);
	$s;
}

sub read_image
{
	my $self = shift;
	my $tools = $self->tools or croak "Tools were not injected.";
	my $w = $tools->{mplayer_wrapper} or croak "MplayerWrapper required.";
	my $s;

lib/App/MaMGal/Entry/Picture/Static.pm  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
# The picture encapsulating class
package App::MaMGal::Entry::Picture::Static;
use strict;
use warnings;
use base 'App::MaMGal::Entry::Picture';
use Carp;
use Image::Magick;
use POSIX;

sub init
{
	my $self = shift;
	$self->SUPER::init(@_);
}

sub refresh_scaled_pictures
{

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

sub description
{
	my $self = shift;
	my $i = $self->image_info or return;
	return $i->description;
}

sub read_image
{
	my $self = shift;
	my $i = Image::Magick->new;
	my $r;
	$r = $i->Read($self->{path_name}) and App::MaMGal::SystemException->throw(message => '%s: reading failed: %s', objects => [$self->{path_name}, $r]);
	return $i;
}

sub creation_time
{
	my $self = shift;
	my $info = $self->image_info or return $self->SUPER::creation_time(@_);
	return $info->creation_time || $self->SUPER::creation_time(@_);

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


sub snapshot
{
	my $self = shift;
	$self->{available} = $self->{cc}->is_available('mplayer') unless exists $self->{available};
	App::MaMGal::MplayerWrapper::NotAvailableException->throw unless $self->{available};
	my $film_path = shift or croak "snapshot needs an arg: path to the film";
	-r $film_path or App::MaMGal::SystemException->throw(message => '%s: not readable', objects => [$film_path]);
	my $dir = $self->{tempdir};
	$self->run_mplayer($film_path);
	my $img = Image::Magick->new;
	if (my $r = $img->Read("${dir}/00000001.jpg")) {
		App::MaMGal::MplayerWrapper::ExecutionFailureException->throw(message => "Could not read the snapshot produced by mplayer: $r", $self->_read_messages);
	}
	$self->cleanup;
	return $img;
}

sub cleanup
{
	my $self = shift;

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

		my $ex = Test::MockObject->new;
		$ex->set_isa('App::MaMGal::MplayerWrapper::NotAvailableException');
		$e->{tools}->{mplayer_wrapper} = App::MaMGal::TestHelper->get_mock_mplayer_wrapper;
		$e->{tools}->{mplayer_wrapper}->mock('snapshot', sub { die $ex; } );
		my $i;

		$e->logger->clear;
		$i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');

		$e->logger->clear;
		$i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');

	}
	{
		my $e = $self->{entry_no_stat};
		my $ex = Test::MockObject->new;
		$ex->set_isa('App::MaMGal::MplayerWrapper::NotAvailableException');
		$e->{tools}->{mplayer_wrapper} = App::MaMGal::TestHelper->get_mock_mplayer_wrapper;
		$e->{tools}->{mplayer_wrapper}->mock('snapshot', sub { die $ex; } );
		my $i;

		$e->logger->clear;
		$i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');

		$e->logger->clear;
		$i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');
	}
}

sub read_image_method_error : Test(12)
{
	my $self = shift;
	my $class_name = $self->{class_name};
	{
		my $e = $self->{entry};
		my $ex = Test::MockObject->new;
		$ex->set_isa('App::MaMGal::MplayerWrapper::ExecutionFailureException');
		$ex->mock('message', sub { 'la di da' });
		$e->{tools}->{mplayer_wrapper} = App::MaMGal::TestHelper->get_mock_mplayer_wrapper;
		$e->{tools}->{mplayer_wrapper}->mock('snapshot', sub { die $ex } );
		$e->logger->clear;
		my $i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');
	}
	{
		my $e = $self->{entry_no_stat};
		my $ex = Test::MockObject->new;
		$ex->set_isa('App::MaMGal::MplayerWrapper::ExecutionFailureException');
		$ex->mock('message', sub { 'la di da' });
		$e->{tools}->{mplayer_wrapper} = App::MaMGal::TestHelper->get_mock_mplayer_wrapper;
		$e->{tools}->{mplayer_wrapper}->mock('snapshot', sub { die $ex } );
		$e->logger->clear;
		my $i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');
	}
}

package main;
use Test::More;
unless (defined caller) {
	plan tests => App::MaMGal::Unit::Entry::Picture::Static->expected_tests + App::MaMGal::Unit::Entry::Picture::Film->expected_tests;
	App::MaMGal::Unit::Entry::Picture::Static->runtests;
	App::MaMGal::Unit::Entry::Picture::Film->runtests;
}

t/100_unit_mplayer_wrapper.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 => 69;
use Test::Exception;
use Test::HTML::Content;
use lib 'testlib';
use App::MaMGal::TestHelper;
use Image::Magick;

prepare_test_data;

use_ok('App::MaMGal::MplayerWrapper');

dies_ok(sub { App::MaMGal::MplayerWrapper::ExecutionFailureException->new }, 'exception creation dies without arguments');
dies_ok(sub { App::MaMGal::MplayerWrapper::ExecutionFailureException->new(message => 'foo bar', stderr => 'just one') }, 'exception creation dies with just one argument');
dies_ok(sub { App::MaMGal::MplayerWrapper::ExecutionFailureException->new(message => 'foo bar', stdout => 'just one') }, 'exception creation dies with just another arg');

sub exception_instantiation_ok

t/100_unit_mplayer_wrapper.t  view on Meta::CPAN

ok($err->stdout, "invalid file produces some messages");
cmp_ok(scalar @{$err->stdout}, '>', 0, "there are lines in the stdout file");
is(scalar(grep(/\n$/, @{$err->stdout})), 0, "no newlines in the stdout file");
ok($err->stderr, "invalid file produces some error messages");
cmp_ok(scalar @{$err->stderr}, '>', 0, "there are lines in the stderr file");
is(scalar(grep(/\n$/, @{$err->stderr})), 0, "no newlines in the stderr file");

lives_ok(sub { $snap = $w->snapshot('td/one_film/m.mov') },	"wrapper can get a snapshot of a film file");
is($mccy->next_call, undef, 'checker not interrogated more than once');
$mccy->clear;
isa_ok($snap, 'Image::Magick',					"snapshot");
}

{
my $mccn = get_mock_cc(0);
my $w;
lives_ok(sub { $w = App::MaMGal::MplayerWrapper->new($mccn) },        "wrapper can be created with command checker");

is($mccn->next_call, undef, 'checker not interrogated until fist wrapper use');
$mccn->clear;

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

	$ml->mock('set_locale');
	$ml->mock('format_time', sub { "12:12:12" });
	$ml->mock('format_date', sub { "18 dec 2004" });
	return $ml;
}

sub get_mock_mplayer_wrapper {
	my $mmw = Test::MockObject->new;
	$mmw->set_isa('App::MaMGal::MplayerWrapper');
	my $mock_image = Test::MockObject->new;
	$mock_image->set_isa('Image::Magick');
	$mock_image->mock('Get', sub { '100', '100' });
	$mock_image->mock('Scale', sub { undef });
	$mock_image->mock('Write', sub { system('touch', $_[1] ) });
	$mmw->mock('snapshot', sub { $mock_image });
	return $mmw;
}

sub get_mock_cc($) {
	my $ret = shift;
	my $mcc = Test::MockObject->new;



( run in 0.435 second using v1.01-cache-2.11-cpan-beeb90c9504 )