File Coverage

lib/App/Followme/JpegData.pm
Criterion Covered Total %
statement 47 47 100.0
branch 4 4 100.0
condition n/a
subroutine 14 14 100.0
pod 2 5 40.0
total 67 70 95.7


line stmt bran cond sub pod time code
1             package App::Followme::JpegData;
2              
3 3     3   600 use 5.008005;
  3         20  
4 3     3   27 use strict;
  3         4  
  3         92  
5 3     3   17 use warnings;
  3         26  
  3         99  
6 3     3   17 use integer;
  3         6  
  3         18  
7 3     3   107 use lib '../..';
  3         6  
  3         17  
8              
9 3     3   439 use base qw(App::Followme::FileData);
  3         6  
  3         692  
10              
11 3     3   731 use Image::Size;
  3         4924  
  3         195  
12 3     3   22 use File::Spec::Functions qw(catfile);
  3         7  
  3         140  
13 3     3   17 use App::Followme::FIO;
  3         7  
  3         1486  
14              
15             our $VERSION = "2.02";
16              
17             #----------------------------------------------------------------------
18             # Read the default parameter values
19              
20             sub parameters {
21 16     16 1 26 my ($self) = @_;
22              
23             return (
24 16         59 extension => 'jpg',
25             target_prefix => 'img',
26             thumb_suffix => '-thumb',
27             );
28             }
29              
30             #----------------------------------------------------------------------
31             # Look in the file for the data
32              
33             sub fetch_from_file {
34 19     19 0 1402 my ($self, $filename) = @_;
35              
36 19 100       440 return () unless -e $filename;
37 12 100       950 return $self->SUPER::fetch_from_file($filename) if -T $filename;
38              
39 5         20 my %dimensions;
40 5         37 ($dimensions{width}, $dimensions{height}) = imgsize($filename);
41              
42 5         1880 return %dimensions;
43             }
44              
45             #----------------------------------------------------------------------
46             # Get the name of the thumb photo file
47              
48             sub get_thumb_file {
49 20     20 0 718 my ($self, $filename) = @_;
50              
51 20         72 my ($dir, $file) = fio_split_filename($filename);
52 20         72 my ($root, $ext) = split(/\./, $file);
53 20         66 $file = join('', $root, $self->{thumb_suffix}, '.', $ext);
54 20         80 my $photoname = catfile($dir, $file);
55              
56 20         73 return [$photoname];
57             }
58              
59             #----------------------------------------------------------------------
60             # Get a url from a filename
61              
62             sub get_url {
63 20     20 0 43 my ($self, $filename) = @_;
64              
65             return $self->filename_to_url($self->{top_directory},
66 20         73 $filename);
67             }
68              
69             #----------------------------------------------------------------------
70             # Set up exclude
71              
72             sub setup {
73 4     4 1 13 my ($self) = @_;
74              
75 4         8 my $dir;
76 4         18 my $thumb_files = $self->get_thumb_file("*.$self->{extension}");
77 4         34 ($dir, $self->{exclude}) = fio_split_filename($thumb_files->[0]);
78              
79 4         16 return;
80             }
81              
82             1;
83              
84             =pod
85              
86             =encoding utf-8
87              
88             =head1 NAME
89              
90             App::Followme::JpegData - Read datafrom a jpeg file
91              
92             =head1 SYNOPSIS
93              
94             use App::Followme::JpegData;
95             my $data = App::Followme::JpegData->new();
96             my $html = App::Followme::Template->new('example.htm', $data);
97              
98             =head1 DESCRIPTION
99              
100             This module extratcs metadata from a jpeg image and uses that metadata to
101             build variables used in a template.
102              
103             =head1 METHODS
104              
105             All data classes are first instantiated by calling new and the object
106             created is passed to a template object. It calls the build method with an
107             argument name to retrieve that data item, though for the sake of
108             efficiency, all the data are read from the file at once.
109              
110             =head1 VARIABLES
111              
112             =over 4
113              
114             =item @thumb_file
115              
116             The name of the thumb file for a photo. Even though this is a single file, it
117             is returned as a hash and thus must be used in a for statement.
118              
119             =item $height
120              
121             The height of the photo
122              
123             =item $width
124              
125             The width of the photo
126              
127             =back
128              
129             =head1 CONFIGURATION
130              
131             The following fields in the configuration file are used in this class and every
132             class based on it:
133              
134             =over 4
135              
136             =item extension
137              
138             The extension used by jpeg files.
139              
140             =item target_prefix
141              
142             The prefix used to build the target names. The default value is 'img'.
143              
144             =item thumb_suffix
145              
146             The suffix added to the root of the photo filename to build the thumb photo
147             filename. The default value is '-thumb'.
148              
149             =back
150              
151             =head1 LICENSE
152              
153             Copyright (C) Bernie Simon.
154              
155             This library is free software; you can redistribute it and/or modify
156             it under the same terms as Perl itself.
157              
158             =head1 AUTHOR
159              
160             Bernie Simon E<lt>bernie.simon@gmail.comE<gt>
161              
162             =cut