| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Followme::JpegData; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 598 | use 5.008005; | 
|  | 3 |  |  |  |  | 24 |  | 
| 4 | 3 |  |  | 3 |  | 18 | use strict; | 
|  | 3 |  |  |  |  | 14 |  | 
|  | 3 |  |  |  |  | 72 |  | 
| 5 | 3 |  |  | 3 |  | 14 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 106 |  | 
| 6 | 3 |  |  | 3 |  | 17 | use integer; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 19 |  | 
| 7 | 3 |  |  | 3 |  | 86 | use lib '../..'; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 17 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 3 |  |  | 3 |  | 444 | use base qw(App::Followme::FileData); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 632 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 3 |  |  | 3 |  | 987 | use Image::Size; | 
|  | 3 |  |  |  |  | 5123 |  | 
|  | 3 |  |  |  |  | 176 |  | 
| 12 | 3 |  |  | 3 |  | 21 | use File::Spec::Functions qw(catfile); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 141 |  | 
| 13 | 3 |  |  | 3 |  | 19 | use App::Followme::FIO; | 
|  | 3 |  |  |  |  | 11 |  | 
|  | 3 |  |  |  |  | 1381 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our $VERSION = "2.03"; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 18 |  |  |  |  |  |  | # Read the default parameter values | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub parameters { | 
| 21 | 16 |  |  | 16 | 1 | 33 | my ($self) = @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | return ( | 
| 24 | 16 |  |  |  |  | 52 | 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 | 1542 | my ($self, $filename) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 19 | 100 |  |  |  | 362 | return () unless -e $filename; | 
| 37 | 12 | 100 |  |  |  | 807 | return $self->SUPER::fetch_from_file($filename) if -T $filename; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 5 |  |  |  |  | 18 | my %dimensions; | 
| 40 | 5 |  |  |  |  | 22 | ($dimensions{width}, $dimensions{height}) = imgsize($filename); | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 5 |  |  |  |  | 1730 | return %dimensions; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 46 |  |  |  |  |  |  | # Get the name of the thumb photo file | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub get_thumb_file { | 
| 49 | 20 |  |  | 20 | 0 | 882 | my ($self, $filename) = @_; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 20 |  |  |  |  | 55 | my ($dir, $file) = fio_split_filename($filename); | 
| 52 | 20 |  |  |  |  | 62 | my ($root, $ext) = split(/\./, $file); | 
| 53 | 20 |  |  |  |  | 65 | $file = join('', $root, $self->{thumb_suffix}, '.', $ext); | 
| 54 | 20 |  |  |  |  | 71 | my $photoname = catfile($dir, $file); | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 20 |  |  |  |  | 76 | return [$photoname]; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 60 |  |  |  |  |  |  | # Get a url from a filename | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub get_url { | 
| 63 | 20 |  |  | 20 | 0 | 39 | my ($self, $filename) = @_; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | return $self->filename_to_url($self->{top_directory}, | 
| 66 | 20 |  |  |  |  | 67 | $filename); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 70 |  |  |  |  |  |  | # Set up exclude | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub setup { | 
| 73 | 4 |  |  | 4 | 1 | 19 | my ($self) = @_; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 4 |  |  |  |  | 8 | my $dir; | 
| 76 | 4 |  |  |  |  | 21 | my $thumb_files = $self->get_thumb_file("*.$self->{extension}"); | 
| 77 | 4 |  |  |  |  | 13 | ($dir, $self->{exclude}) = fio_split_filename($thumb_files->[0]); | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 4 |  |  |  |  | 15 | 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 |