IMDB/Date.pm

filter: Statementstmt 42.8% 18 / 42 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 20.7% 23 / 111 CC 23 SCAR 61.2
CC
23
Cov
19%
_new
552.0
BEGIN
1.0
BEGIN
1.0
CRAP 453.6
↑ Summary IMDB/UserComment.pm »
1 # $Id: Date.pm 7370 2012-04-09 01:17:33Z chris $
2  
3 =head1 NAME
4  
5 WebService::IMDB::Date
6  
7 =head1 DESCRIPTION
8  
9 Constructor always returns a L<DateTime::Incomplete>.
10  
11 =cut
12  
13 package WebService::IMDB::Date;
14  
15 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 our $VERSION = '0.05';
19  
20 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 our @CARP_NOT = qw(WebService::IMDB WebService::IMDB::Trivium);
22  
23 2 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use DateTime::Incomplete;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 0 ▶sub _new {
Subroutine _new: not called CC=23 SCAR=63.1
28 0 my $class = shift;
29 0 my $ws = shift;
30 0 ▶ my $data = shift or die;
Branch: 1 branch
BranchTrueFalseTotal
my $data = shift() or die 0 0 0
31  
32 0 ▶ if (ref $data eq "HASH" && exists $data->{'normal'} && defined $data->{'normal'}) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $data eq 'HASH' and exists $data->{'normal'} and defined $data->{'normal'}) { } 0 0 0
elsif (ref $data eq 'HASH' and exists $data->{'text'}) { } 0 0 0
elsif (ref $data eq '' and $data =~ /^\d{4}-\d{2}-\d{2}$/) { } 0 0 0
Condition0%0/6
ref $data eq "HASH" and exists $data->{"normal"} and defined $data->{"normal"}
!ll&&!rl&&r
000
ref $data eq "HASH" and exists $data->{"normal"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $data eq "HASH" and exists $data->{"normal"} and defined $data->{"normal"}
ref $data eq "HASH" exists $data->{"normal"} defined $data->{"normal"}
Truth table0%0/4
A and B and C
A= ref $data eq "HASH"B= exists $data->{"normal"}C= defined $data->{"normal"}
ABCresult
0XX0
10X0
1100
1111
33 # TODO: Check whehter locale affects this.
34 0 my $dt = $data->{'normal'};
35 0 ▶ my ($y, $m, $d) = $dt =~ m/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/ or die "Failed to parse '$dt'";
Branch: 1 branch
BranchTrueFalseTotal
() = $dt =~ /^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/ or die "Failed to parse '${dt}'" 0 0 0
36 0 ▶ if (defined $y && defined $m && defined $d) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $y and defined $m and defined $d) { } 0 0 0
elsif (defined $y and defined $m) { } 0 0 0
elsif (defined $y) { } 0 0 0
Condition0%0/6
defined $y and defined $m and defined $d
!ll&&!rl&&r
000
defined $y and defined $m
!ll&&!rl&&r
000
MC/DC0%0/3
defined $y and defined $m and defined $d
defined $y defined $m defined $d
Truth table0%0/4
A and B and C
A= defined $yB= defined $mC= defined $d
ABCresult
0XX0
10X0
1100
1111
37 0 return DateTime::Incomplete->new('year' => $y, 'month' => $m, 'day' => $d);
38 ▶ } elsif (defined $y && defined $m) {
Condition0%0/3
defined $y and defined $m
!ll&&!rl&&r
000
MC/DC0%0/2
defined $y and defined $m
defined $y defined $m
Truth table0%0/3
A and B
A= defined $yB= defined $m
ABresult
0X0
100
111
39 0 return DateTime::Incomplete->new('year' => $y, 'month' => $m);
40 } elsif (defined $y) {
41 0 return DateTime::Incomplete->new('year' => $y);
42 } else {
43 0 die "";
44 }
45  
46 ▶ } elsif (ref $data eq "HASH" && exists $data->{'text'}) {
Condition0%0/3
ref $data eq "HASH" and exists $data->{"text"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data eq "HASH" and exists $data->{"text"}
ref $data eq "HASH" exists $data->{"text"}
Truth table0%0/3
A and B
A= ref $data eq "HASH"B= exists $data->{"text"}
ABresult
0X0
100
111
47  
48 0 ▶ if (!defined $data->{'text'}) { # A bit hacky, but not sure how else to deal with this.
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{'text'}) { } 0 0 0
49 0 return undef;
50 } else {
51 # Some 'text' dates are actually parseable, e.g. those of the format "July 14, 2007". Attempt to detect them
52 # and parse to a DateTime::Incomplete
53 0 my $d = DateTime::Format::Strptime->new('pattern' => "%B %d, %Y", 'on_error' => "undef")->parse_datetime($data->{'text'});
54 0 ▶ if (defined $d) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $d) { } 0 0 0
elsif ($data->{'text'} =~ m[^\d{1,2}/\d{2}$]) { } 0 0 0
elsif ($data->{'text'} =~ m[^\d{1,2}/\d{1,2}/\d{2}$]) { } 0 0 0
55 0 return DateTime::Incomplete->new('year' => $d->year(), 'month' => $d->month(), 'day' => $d->day());
56  
57 } elsif ($data->{'text'} =~ m/^\d{1,2}\/\d{2}$/) {
58 0 ▶ my ($m, $y) = $data->{'text'} =~ m/^(\d{1,2})\/(\d{2})$/ or die "Failed to parse '$data->{'text'}'";
Branch: 1 branch
BranchTrueFalseTotal
() = $data->{"text"} =~ m[^(\d{1,2})/(\d{2})$] or die qq[Failed to parse '$data->{"text"}'] 0 0 0
59 0 return DateTime::Incomplete->new('year' => $y, 'month' => $m);
60  
61 } elsif ($data->{'text'} =~ m/^\d{1,2}\/\d{1,2}\/\d{2}$/) {
62 0 ▶ my ($m, $d, $y) = $data->{'text'} =~ m/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/ or die "Failed to parse '$data->{'text'}'";
Branch: 1 branch
BranchTrueFalseTotal
() = $data->{"text"} =~ m[^(\d{1,2})/(\d{1,2})/(\d{2})$] or die qq[Failed to parse '$data->{"text"}'] 0 0 0
63 0 return DateTime::Incomplete->new('year' => $y, 'month' => $m, 'day' => $d);
64  
65 } else {
66 0 return $data->{'text'};
67 }
68 }
69  
70 ▶ } elsif (ref $data eq "" && $data =~ m/^\d{4}-\d{2}-\d{2}$/) {
Condition0%0/3
ref $data eq "" and $data =~ /^\d{4}-\d{2}-\d{2}$/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data eq "" and $data =~ /^\d{4}-\d{2}-\d{2}$/
ref $data eq "" $data =~ /^\d{4}-\d{2}-\d{2}$/
Truth table0%0/3
A and B
A= ref $data eq ""B= $data =~ /^\d{4}-\d{2}-\d{2}$/
ABresult
0X0
100
111
71 0 ▶ my ($y, $m, $d) = $data =~ m/^(\d{4})-(\d{2})-(\d{2})$/ or die "Failed to parse '$data'";
Branch: 1 branch
BranchTrueFalseTotal
() = $data =~ /^(\d{4})-(\d{2})-(\d{2})$/ or die "Failed to parse '${data}'" 0 0 0
72 0 return DateTime::Incomplete->new('year' => $y, 'month' => $m, 'day' => $d);
73  
74 } else {
75 0 croak "Unable to parse date";
76 }
77 }
78  
79 2 1;
↑ Summary IMDB/UserComment.pm »