Feed/Util.pm

filter: Statementstmt 76.0% 38 / 50 Branchbran 33.3% 4 / 12 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 84.6% 11 / 13 Podpod 100% 4 / 4 totaltotal 60.2% 59 / 98 CC 11 SCAR 17.7
CC
11
Cov
59%
parse_mail_date
12.0
parse_w3cdtf_date
12.0
parse_datetime
9.3
CRAP 5.8
« Feed.pm ↑ Summary Feed/Entry/Format/Atom.pm »
1 package XML::Feed::Util;
2 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 35 our $VERSION = '1.0.1';
6  
7 35 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use DateTime::Format::Flexible;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use DateTime::Format::Natural;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use DateTime::Format::W3CDTF;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use DateTime::Format::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 35 our @EXPORT_OK = qw(
15 format_w3cdtf
16 parse_datetime
17 parse_w3cdtf_date
18 parse_mail_date
19 );
20  
21 10 ▶sub format_w3cdtf {
Subroutine format_w3cdtf: called CC=2 SCAR=7.0
Pod documented
22 10 my $dt = shift;
23  
24 10 my $date = DateTime::Format::W3CDTF->format_datetime($dt);
25  
26 # Add timezone "Z" if "floating" DateTime.
27 10 ▶ $date .= 'Z' if $dt->time_zone->is_floating;
Branch: 1 branch
BranchTrueFalseTotal
if $dt->time_zone->is_floating 0 10 10
28  
29 10 return $date;
30 }
31  
32 19 ▶sub parse_datetime {
Subroutine parse_datetime: called CC=5 SCAR=22.3
Pod documented
33 19 ▶ my $ts = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ts = shift() or return undef 16 3 19
34  
35 16 $ts = _strip_spaces($ts);
36  
37 16 return eval { DateTime::Format::ISO8601->parse_datetime($ts) }
38 0 || eval { DateTime::Format::Flexible->parse_datetime($ts) }
39 16 ▶ || do {
Condition33%2/6
eval { do { 'DateTime::Format::ISO8601'->parse_datetime($ts) } } || eval { do { 'DateTime::Format::Flexible'->parse_datetime($ts) } } || do { my $p = 'DateTime::Format::Natural'->new; my $dt = $p->parse_datetime($ts); $p->success ? $dt : undef }
l!l&&r!l&&!r
1600
eval { do { "DateTime::Format::ISO8601"->parse_datetime($ts) } } or eval { do { "DateTime::Format::Flexible"->parse_datetime($ts) } }
l!l&&r!l&&!r
1600
MC/DC0%0/3
eval { do { 'DateTime::Format::ISO8601'->parse_datetime($ts) } } || eval { do { 'DateTime::Format::Flexible'->parse_datetime($ts) } } || do { my $p = 'DateTime::Format::Natural'->new; my $dt = $p->parse_datetime($ts); $p->success ? $dt : undef }
eval { do { "DateTime::Format::ISO8601"->parse_datetime($ts) } } eval { do { "DateTime::Format::Flexible"->parse_datetime($ts) } } do { my $p = 'DateTime::Format::Natural'->new; my $dt = $p->parse_datetime($ts); $p->success ? $dt : undef }
Truth table25%1/4
A or B || C
A= eval { do { "DateTime::Format::ISO8601"->parse_datetime($ts) } }B= eval { do { "DateTime::Format::Flexible"->parse_datetime($ts) } }C= do { my $p = 'DateTime::Format::Natural'->new; my $dt = $p->parse_datetime($ts); $p->success ? $dt : undef }
ABCresult
1XX1
01X1
0011
0000
40 0 my $p = DateTime::Format::Natural->new;
41 0 my $dt = $p->parse_datetime($ts);
42 0 ▶ $p->success ? $dt : undef;
Branch: 1 branch
BranchTrueFalseTotal
$p->success ? : 0 0 0
43 };
44 };
45  
46 0 ▶sub parse_mail_date {
Subroutine parse_mail_date: not called CC=3 SCAR=24.8
Pod documented
47 0 ▶ my $ts = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ts = shift() or return undef 0 0 0
48  
49 0 $ts = _strip_spaces($ts);
50  
51 0 ▶ return eval { DateTime::Format::Mail->new(loose => 1)->parse_datetime($ts) }
Condition0%0/3
eval { do { 'DateTime::Format::Mail'->new('loose', 1)->parse_datetime($ts) } } || parse_datetime($ts)
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { 'DateTime::Format::Mail'->new('loose', 1)->parse_datetime($ts) } } || parse_datetime($ts)
eval { do { 'DateTime::Format::Mail'->new('loose', 1)->parse_datetime($ts) } } parse_datetime($ts)
Truth table0%0/3
A || B
A= eval { do { 'DateTime::Format::Mail'->new('loose', 1)->parse_datetime($ts) } }B= parse_datetime($ts)
ABresult
1X1
011
000
52 || parse_datetime($ts);
53 };
54  
55 0 ▶sub parse_w3cdtf_date {
Subroutine parse_w3cdtf_date: not called CC=3 SCAR=24.8
Pod documented
56 0 ▶ my $ts = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ts = shift() or return undef 0 0 0
57  
58 0 $ts = _strip_spaces($ts);
59  
60 0 ▶ return eval { DateTime::Format::W3CDTF->parse_datetime($ts) }
Condition0%0/3
eval { do { 'DateTime::Format::W3CDTF'->parse_datetime($ts) } } || parse_datetime($ts)
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { 'DateTime::Format::W3CDTF'->parse_datetime($ts) } } || parse_datetime($ts)
eval { do { 'DateTime::Format::W3CDTF'->parse_datetime($ts) } } parse_datetime($ts)
Truth table0%0/3
A || B
A= eval { do { 'DateTime::Format::W3CDTF'->parse_datetime($ts) } }B= parse_datetime($ts)
ABresult
1X1
011
000
61 || parse_datetime($ts);
62 };
63  
64 16 ▶sub _strip_spaces {
Subroutine _strip_spaces: called CC=2 SCAR=7.1
65 16 local $_ = shift;
66 16 ▶ s/^\s+//, s/\s+$// if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 16 0 16
67 16 return $_;
68 }
69  
70 35 1;
71  
72 __END__
« Feed.pm ↑ Summary Feed/Entry/Format/Atom.pm »