File Coverage

blib/lib/Image/Delivery/Provider/Scalar.pm
Criterion Covered Total %
statement 32 34 94.1
branch 10 14 71.4
condition 6 9 66.6
subroutine 8 8 100.0
pod 0 2 0.0
total 56 67 83.5


line stmt bran cond sub pod time code
1             package Image::Delivery::Provider::Scalar;
2              
3 4     4   2354 use strict;
  4         6  
  4         129  
4 4     4   20 use UNIVERSAL 'isa';
  4         7  
  4         24  
5 4     4   1734 use base 'Image::Delivery::Provider';
  4         8  
  4         374  
6 4     4   30 use Digest::TransformPath ();
  4         8  
  4         118  
7              
8 4     4   21 use vars qw{$VERSION};
  4         6  
  4         197  
9             BEGIN {
10 4     4   1151 $VERSION = '0.14';
11             }
12              
13              
14              
15              
16              
17             #####################################################################
18             # Constructor
19              
20             sub new {
21 10     10 0 20 my $class = shift;
22 10 50       36 my $image = ref $_[0] eq 'SCALAR' ? shift : return undef;
23 10         23 my %params = @_;
24              
25             # Create the object
26 10         44 my $self = bless {
27             image => $image,
28             }, $class;
29              
30             # Handle arguments
31 10 50       63 if ( isa($params{TransformPath}, 'Digest::TransformPath') ) {
32 0         0 $self->{TransformPath} = $params{TransformPath};
33             }
34 10 100 66     50 if ( defined $params{id} and length $params{id} ) {
35 1         4 $self->{id} = $params{id};
36             }
37 10 100 66     39 if ( defined $params{content_type} and length $params{content_type} ) {
38 1         3 $self->{content_type} = $params{content_type};
39             }
40 10 100 66     40 if ( defined $params{extension} and length $params{extension} ) {
41 1         3 $self->{extension} = $params{extension};
42             }
43              
44             # Are we allowed to use the image type passed
45 10 50       48 my $extension = $self->extension or return undef;
46 10 50       50 unless ( grep { $extension eq $_ } $self->filetypes ) {
  30         81  
47             # Unsupported file type
48 0         0 return undef;
49             }
50              
51 10         64 $self;
52             }
53              
54 27     27 0 8419 sub image { $_[0]->{image} }
55              
56             1;