DateTime/JPEG.pm

filter: Statementstmt 54.5% 24 / 44 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 63.6% 7 / 11 Podpod 100% 2 / 2 totaltotal 43.4% 33 / 76 CC 8 SCAR 25.9
CC
8
Cov
40%
datetime
30.0
__ANON__
20.0
__ANON__
2.0
CRAP 13.4
↑ Summary DateTime.pm »
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
BranchTrueFalseTotal
unless $exifTool 0 0 0
22 0 ▶ $exifTool->ExtractInfo($f) or do {
Branch: 1 branch
BranchTrueFalseTotal
$exifTool->ExtractInfo($f) or do { warn "Exiftool unable to read: $f\nFallback to file timestamp.\n"; return } 0 0 0
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
BranchTrueFalseTotal
my $datetime = $exifTool->GetValue("DateTimeOriginal") or do { warn "JPEG does not contain DateTimeOriginal exif entry ($f),\n" . "Fallback to file timestamp.\n"; return } 0 0 0
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
BranchTrueFalseTotal
() = $datetime =~ / (\d{4}) : # year (\d{2}) : # month (\d{2}) # day \s # space (\d{2}) : # hour (\d{2}) : # min (\d{2}) # sec /x or do { warn "failed DateTime pattern match in $f\n" . 'Fallback to file timestamp'; return } 0 0 0
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
BranchTrueFalseTotal
if (builtin::blessed($_) and $_->isa('Specio::Exception') or /to DateTime::new did not pass/) { } 0 0 0
Condition0%0/6
builtin::blessed($_) and $_->isa("Specio::Exception") or /to DateTime::new did not pass/
l!l&&r!l&&!r
000
builtin::blessed($_) and $_->isa("Specio::Exception")
!ll&&!rl&&r
000
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/
ABCresult
11X1
0X11
1011
0X00
1000
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__
↑ Summary DateTime.pm »