| 1 | # mamgal - a program for creating static image galleries | ||
| 2 | # Copyright 2007-2009 Marcin Owsiany <marcin@owsiany.pl> | ||
| 3 | # See the README file for license information | ||
| 4 | # The wrapper-for-everything module | ||
| 5 | package App::MaMGal; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use base 'App::MaMGal::Base'; | ||
| 9 | # Remeber to change po/mamgal.pot as well | ||
| 10 | our $VERSION = '1.6'; | ||
| 11 | our $AUTOLOAD; | ||
| 12 | use Carp; | ||
| 13 | use FileHandle; | ||
| 14 | use Image::EXIF::DateTime::Parser; | ||
| 15 | use Locale::gettext; | ||
| 16 | |||
| 17 | use App::MaMGal::CommandChecker; | ||
| 18 | use App::MaMGal::EntryFactory; | ||
| 19 | use App::MaMGal::Formatter; | ||
| 20 | use App::MaMGal::ImageInfoFactory; | ||
| 21 | use App::MaMGal::LocaleEnv; | ||
| 22 | use App::MaMGal::Maker; | ||
| 23 | use App::MaMGal::MplayerWrapper; | ||
| 24 | |||
| 25 | sub init | ||
| 26 | { | ||
| 27 | my $self = shift; | ||
| 28 | |||
| 29 | my $logger = App::MaMGal::Logger->new(FileHandle->new_from_fd('STDERR', 'w')); | ||
| 30 | my $locale_env; | ||
| 31 | if (@_) { | ||
| 32 | $locale_env = App::MaMGal::LocaleEnv->new($logger); | ||
| 33 | $locale_env->set_locale($_[0]); | ||
| 34 | textdomain('mamgal'); | ||
| 35 | } else { | ||
| 36 | $locale_env = App::MaMGal::LocaleEnv->new($logger); | ||
| 37 | } | ||
| 38 | my $formatter = App::MaMGal::Formatter->new($locale_env); | ||
| 39 | my $command_checker = App::MaMGal::CommandChecker->new; | ||
| 40 | my $mplayer_wrapper = App::MaMGal::MplayerWrapper->new($command_checker); | ||
| 41 | my $datetime_parser = Image::EXIF::DateTime::Parser->new; | ||
| 42 | my $image_info_factory = App::MaMGal::ImageInfoFactory->new($datetime_parser, $logger); | ||
| 43 | my $entry_factory = App::MaMGal::EntryFactory->new($formatter, $mplayer_wrapper, $image_info_factory, $logger); | ||
| 44 | my $maker = App::MaMGal::Maker->new($entry_factory); | ||
| 45 | |||
| 46 | $self->{maker} = $maker; | ||
| 47 | $self->{logger} = $logger; | ||
| 48 | |||
| 49 | } | ||
| 50 | |||
| 51 | sub DESTROY {} # avoid using AUTOLOAD | ||
| 52 | |||
| 53 | sub AUTOLOAD | ||
| 54 | { | ||
| 55 | my $self = shift; | ||
| 56 | my $method = $AUTOLOAD; | ||
| 57 | $method =~ s/.*://; | ||
| 58 | croak "Unknown method $method" unless $method =~ /^make_(without_)?roots$/; | ||
| 59 | eval { | ||
| 60 | $self->{maker}->$method(@_); | ||
| 61 | }; | ||
| 62 | my $e; | ||
| 63 | if ($e = Exception::Class->caught('App::MaMGal::SystemException')) { | ||
| 64 | $self->{logger}->log_exception($e); | ||
| 65 | } elsif ($e = Exception::Class->caught) { | ||
| 66 | ref $e ? $e->rethrow : die $e; | ||
| 67 | } | ||
| 68 | 1; | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 |