| 1 | # mamgal - a program for creating static image galleries | ||
| 2 | # Copyright 2007, 2008 Marcin Owsiany <marcin@owsiany.pl> | ||
| 3 | # See the README file for license information | ||
| 4 | # The runner module | ||
| 5 | package App::MaMGal::Maker; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use base 'App::MaMGal::Base'; | ||
| 9 | use Carp; | ||
| 10 | use App::MaMGal::Entry::Dir; | ||
| 11 | |||
| 12 | sub init | ||
| 13 | { | ||
| 14 | my $self = shift; | ||
| 15 | my $entry_factory = shift or croak "Need an entry factory arg"; | ||
| 16 | ref $entry_factory and $entry_factory->isa('App::MaMGal::EntryFactory') or croak "Arg is not an EntryFactory, but a [$entry_factory]"; | ||
| 17 | $self->{entry_factory} = $entry_factory; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub make_without_roots | ||
| 21 | { | ||
| 22 | my $self = shift; | ||
| 23 | return $self->_make_any(0, @_); | ||
| 24 | } | ||
| 25 | |||
| 26 | sub make_roots | ||
| 27 | { | ||
| 28 | my $self = shift; | ||
| 29 | return $self->_make_any(1, @_); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub _make_any | ||
| 33 | { | ||
| 34 | my $self = shift; | ||
| 35 | my $dirs_are_roots = shift; | ||
| 36 | # TODO: replace with croak after cmdline parsing is added | ||
| 37 | die "Argument required.\n" unless @_; | ||
| 38 | |||
| 39 | my @dirs = map { | ||
| 40 | my $d = $self->{entry_factory}->create_entry_for($_); | ||
| 41 | App::MaMGal::SystemException->throw(message => '%s: not a directory.', objects => [$_]) unless $d->isa('App::MaMGal::Entry::Dir'); | ||
| 42 | $d->set_root(1) if $dirs_are_roots; | ||
| 43 | $d | ||
| 44 | } @_; | ||
| 45 | $_->make foreach @dirs; | ||
| 46 | |||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; |