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   88941 use strict;
  3         5  
  3         76  
8 3     3   13 use warnings;
  3         6  
  3         97  
9 3     3   17 use base 'App::MaMGal::Base';
  3         5  
  3         1490  
10 3     3   15 use Carp;
  3         5  
  3         138  
11 3     3   13 use App::MaMGal::Exceptions;
  3         5  
  3         310  
12              
13             my $implementation;
14              
15             BEGIN {
16 3 100   3   72 if (exists $ENV{MAMGAL_FORCE_IMAGEINFO}) {
    50          
    0          
17 2         6 $implementation = $ENV{MAMGAL_FORCE_IMAGEINFO};
18 2 50       130 eval "require $implementation" or die;
19             } elsif (eval "require App::MaMGal::ImageInfo::ExifTool") {
20 1         202 $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 87 my $self = shift;
31 46 100       384 my $parser = shift or croak "A Image::EXIF::DateTime::Parser argument is required";
32 44 100 66     312 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       980 my $logger = shift or croak "A App::MaMGal::Logger argument is required";
34 40 100 66     529 ref $logger and $logger->isa('App::MaMGal::Logger') or croak "Arg is not an App::MaMGal::Logger, but a [$logger]";
35 38         625 $self->{parser} = $parser;
36 38         122 $self->{logger} = $logger;
37             }
38              
39             sub read {
40 220     220 0 38418 my $self = shift;
41 220         1761 my $o = $implementation->new(@_);
42 216         580 $o->{parser} = $self->{parser};
43 216         494 $o->{logger} = $self->{logger};
44 216         1086 $o
45             }
46              
47             1;