| 1 | package Media::DateTime::JPEG; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A plugin for the C<Media::DateTime> module to support JPEG files | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.49'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Image::ExifTool; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | my $exifTool; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub datetime { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my ( $self, $f ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $exifTool = Image::ExifTool->new() unless $exifTool; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $exifTool->ExtractInfo($f) or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | warn "Exiftool unable to read: $f\nFallback to file timestamp.\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | my $datetime = $exifTool->GetValue('DateTimeOriginal') | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | warn "JPEG does not contain DateTimeOriginal exif entry ($f),\n" | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | . "Fallback to file timestamp.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # DateTime format = yyyy:mm:dd hh:mm:ss | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my ( $y, $m, $d, $h, $min, $s ) = $datetime =~ m/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | (\d{4}) : # year | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | (\d{2}) : # month | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | (\d{2}) # day | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | \s # space | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | (\d{2}) : # hour | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | (\d{2}) : # min | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | (\d{2}) # sec | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | /x | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | warn "failed DateTime pattern match in $f\n" | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | . "Fallback to file timestamp"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $date = try { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | DateTime->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | year => $y, | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | month => $m, | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | day => $d, | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | hour => $h, | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | minute => $min, | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | second => $s, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ((blessed $_ && $_->isa('Specio::Exception')) || /to DateTime::new did not pass/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($_) and $_->isa("Specio::Exception") or /to DateTime::new did not pass/
builtin::blessed($_) and $_->isa("Specio::Exception")
MC/DC0%0/3
builtin::blessed($_) and $_->isa("Specio::Exception") or /to DateTime::new did not pass/
builtin::blessed($_)
$_->isa("Specio::Exception")
/to DateTime::new did not pass/
Truth table0%0/5
A and B or C
A= builtin::blessed($_)B= $_->isa("Specio::Exception")C= /to DateTime::new did not pass/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | warn | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | "JPEG's DateTimeOriginal exif entry ($f) not a valid datetime.\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | . "Fallback to file timestamp.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $date; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub match { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my ( $self, $f ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $f =~ /\.jpe?g$/i; ## no critic | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | # TODO: should we use something more complicated here? maybe mime type? | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||