File Coverage

blib/lib/App/MaMGal/ImageInfoFactory.pm
Criterion Covered Total %
statement 31 33 93.9
branch 12 16 75.0
condition 4 6 66.6
subroutine 8 8 100.0
pod 0 2 0.0
total 55 65 84.6


line stmt bran cond sub pod time code
1             # mamgal - a program for creating static image galleries
2             # Copyright 2009 Marcin Owsiany
3             # See the README file for license information
4             # A factory class for the image info library wrappers, makes it possible to
5             # decouple the rest of the program from particular implementation.
6             package App::MaMGal::ImageInfoFactory;
7 3     3   92029 use strict;
  3         7  
  3         101  
8 3     3   15 use warnings;
  3         4  
  3         123  
9 3     3   16 use base 'App::MaMGal::Base';
  3         4  
  3         1496  
10 3     3   16 use Carp;
  3         5  
  3         158  
11 3     3   13 use App::MaMGal::Exceptions;
  3         7  
  3         352  
12              
13             my $implementation;
14              
15             BEGIN {
16 3 100   3   90 if (exists $ENV{MAMGAL_FORCE_IMAGEINFO}) {
    50          
    0          
17 2         8 $implementation = $ENV{MAMGAL_FORCE_IMAGEINFO};
18 2 50       151 eval "require $implementation" or die;
19             } elsif (eval "require App::MaMGal::ImageInfo::ExifTool") {
20 1         207 $implementation = 'App::MaMGal::ImageInfo::ExifTool';
21             } elsif (eval "require App::MaMGal::ImageInfo::ImageInfo") {
22 0         0 $implementation = 'App::MaMGal::ImageInfo::ImageInfo';
23             } else {
24 0         0 App::MaMGal::SystemException->throw(message => 'No usable image info library found (looked for "Image::ExifTool" and "Image::Info" in %s).', objects => [join(':', @INC)]);;
25             }
26             }
27              
28             sub init
29             {
30 46     46 0 122 my $self = shift;
31 46 100       434 my $parser = shift or croak "A Image::EXIF::DateTime::Parser argument is required";
32 44 100 66     395 ref $parser and $parser->isa('Image::EXIF::DateTime::Parser') or croak "Arg is not an Image::EXIF::DateTime::Parser , but a [$parser]";
33 42 100       1306 my $logger = shift or croak "A App::MaMGal::Logger argument is required";
34 40 100 66     286 ref $logger and $logger->isa('App::MaMGal::Logger') or croak "Arg is not an App::MaMGal::Logger, but a [$logger]";
35 38         694 $self->{parser} = $parser;
36 38         119 $self->{logger} = $logger;
37             }
38              
39             sub read {
40 220     220 0 54289 my $self = shift;
41 220         1803 my $o = $implementation->new(@_);
42 216         851 $o->{parser} = $self->{parser};
43 216         496 $o->{logger} = $self->{logger};
44 216         1841 $o
45             }
46              
47             1;