blib/lib/DateTime/Format/EXIF.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 35 / 35 CC 4 SCAR 9.2
CC
4
Cov
100%
_postprocess
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
↑ Summary
1 package DateTime::Format::EXIF;
2 1 $DateTime::Format::EXIF::VERSION = '0.002';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: DateTime parser for EXIF timestamps
7  
8  
9  
10 1 ▶sub _make_regex {
Subroutine _make_regex: called CC=1 SCAR=0.0
11 1 my $date_re = '(\d{4}) : (\d{2}) : (\d{2})';
12 1 my $time_re = '(\d{2}) : (\d{2}) : (\d{2} (?: \. \d{1,9})?)';
13 1 my $tz_re = '(Z | [\+\-] \d{2} : \d{2})';
14 1 return qr/^ $date_re \s $time_re $tz_re? $/xms;
15 }
16  
17  
18 1 ▶use DateTime::Format::Builder (
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 parsers => {
20 parse_datetime => [
21 {
22 params => [ qw( year month day hour minute second time_zone ) ],
23 regex => _make_regex(),
24 postprocess => \&_postprocess,
25 },
26 ],
27 },
28 1 );
29  
30  
31 7 ▶sub _postprocess {
Subroutine _postprocess: called CC=4 SCAR=13.9
32 7 my %args = @_;
33 7 my ($date, $p) = @args{qw( input parsed )};
34  
35 # timezone
36 7 ▶ if (!$p->{time_zone}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $p->{'time_zone'}) { } 3 4 7
elsif ($p->{'time_zone'} eq 'Z') { } 2 2 4
37 3 $p->{time_zone} = 'floating';
38 }
39 elsif ($p->{time_zone} eq 'Z') {
40 2 $p->{time_zone} = 'UTC';
41 }
42  
43 # nanoseconds
44 7 my ($s, $fs) = split /(?=\.)/x => $p->{second};
45 7 $p->{second} = $s;
46 7 ▶ $p->{nanosecond} = int($fs * 1e9) if $fs;
Branch: 1 branch
BranchTrueFalseTotal
if $fs 3 4 7
47  
48 7 return $date;
49 }
50  
51  
52 1 1;
53  
54 __END__
↑ Summary