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