| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 {
eval { or eval {
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
}
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 { || parse_datetime($ts)
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)
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | 0 | $ts = _strip_spaces($ts); | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return eval { DateTime::Format::W3CDTF->parse_datetime($ts) } | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
eval { || parse_datetime($ts)
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)
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 67 | 16 | return $_; | |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 35 | 1; | |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | XML::Feed::Util - Utility functions | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | use XML::Feed::Util qw( | ||||||||||||||||||||||||||||||||||
| 81 | format_w3cdtf | ||||||||||||||||||||||||||||||||||
| 82 | parse_datetime | ||||||||||||||||||||||||||||||||||
| 83 | parse_mail_date | ||||||||||||||||||||||||||||||||||
| 84 | parse_w3cdtf_date | ||||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||||
| 86 | use DateTime; | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | print format_w3cdtf(DateTime->now); | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | my $dt; | ||||||||||||||||||||||||||||||||||
| 91 | $dt = parse_datetime('January 8, 1999'); | ||||||||||||||||||||||||||||||||||
| 92 | $dt = parse_mail_date('Fri, 23 Nov 2001 21:57:24 -0600'); | ||||||||||||||||||||||||||||||||||
| 93 | $dt = parse_w3cdtf_date('2003-02-15T13:50:05-05:00'); | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | Common utility or helper functions. | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | =head1 USAGE | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | =head2 format_w3cdtf($datetime) | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | Convert DateTime object to W3CDTF format string. | ||||||||||||||||||||||||||||||||||
| 104 | Uses default timezone "Z" for "floating" DateTime. | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | =head2 parse_datetime($date) | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | Parse any date string using L<DateTime::Format::ISO8601>, | ||||||||||||||||||||||||||||||||||
| 109 | L<DateTime::Format::Flexible> or L<DateTime::Format::Natural>. | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | Returns DateTime object or undef. | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | =head2 parse_mail_date($date) | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | Parse date in RFC2822/822 format using L<DateTime::Format::Mail>. | ||||||||||||||||||||||||||||||||||
| 116 | Fallback to C<parse_datetime()> for other formats. | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | Returns DateTime object or undef. | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | =head2 parse_w3cdtf_date($date) | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | Parse date W3CDTF format using L<DateTime::Format::W3CDTF>. | ||||||||||||||||||||||||||||||||||
| 123 | Fallback to C<parse_datetime()> for other formats. | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | Returns DateTime object or undef. | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | =head1 AUTHOR & COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | Please see the I<XML::Feed> manpage for author, copyright, and license | ||||||||||||||||||||||||||||||||||
| 130 | information. | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||