| 1 | ## XML::Generator::RSS10::ev | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## An extension to Dave Rolsky's XML::Generator::RSS10 to handle event metadata | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Written by Andrew Green, Article Seven, http://www.article7.co.uk/ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Sponsored by Woking Borough Council, http://www.woking.gov.uk/ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Last updated: Friday, 10 March 2006 | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | package XML::Generator::RSS10::ev; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use base 'XML::Generator::RSS10::Module'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Params::Validate qw( validate SCALAR HASHREF OBJECT ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant CONTENTS_SPEC => { startdate => { type => SCALAR | HASHREF | OBJECT }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | enddate => { type => SCALAR | HASHREF | OBJECT }, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | location => { type => SCALAR, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | organizer => { type => SCALAR, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | type => { type => SCALAR, optional => 1 } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use DateTime::Format::W3CDTF; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub NamespaceURI { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
NamespaceURI: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | 'http://purl.org/rss/1.0/modules/event/' | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub contents { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contents: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $rss = shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my %p = validate( @_, CONTENTS_SPEC ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | foreach my $elt ( sort keys %p ) { | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (($elt eq 'startdate') || ($elt eq 'enddate')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt eq "startdate" or $elt eq "enddate"
MC/DC0%0/2
$elt eq "startdate" or $elt eq "enddate"
$elt eq "startdate"
$elt eq "enddate"
Truth table0%0/3
A or B
A= $elt eq "startdate"B= $elt eq "enddate"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->_evdate($rss,$elt,$p{$elt}); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $rss->_element_with_data('ev',$elt,$p{$elt}); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $rss->_newline_if_pretty; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub _evdate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_evdate: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # if we're handed a hashref, convert it to a DateTime object and output it as W3CDTF | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # if we're handed a DateTime object, output it as W3CDTF; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # if we're handed an integer, treat it as an epoch, make it a DateTime object, and output it as W3CDTF; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # if we're handed any other scalar, assume it's already W3CDTF and output it verbatim | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my ($self,$rss,$elt,$date) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $w3cdtf; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (ref $date eq 'HASH') { # it's a date definition... | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $dt = DateTime->new($date); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $f = DateTime::Format::W3CDTF->new; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $w3cdtf = (exists $date->{'hour'} || exists $date->{'minute'} || exists $date->{'second'}) ? $f->format_datetime($dt) : $f->format_date($dt); # use the date alone if the hashref has no time values | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists $date->{"hour"} or exists $date->{"minute"} or exists $date->{"second"}
exists $date->{"hour"} or exists $date->{"minute"}
MC/DC0%0/3
exists $date->{"hour"} or exists $date->{"minute"} or exists $date->{"second"}
exists $date->{"hour"}
exists $date->{"minute"}
exists $date->{"second"}
Truth table0%0/4
A or B or C
A= exists $date->{"hour"}B= exists $date->{"minute"}C= exists $date->{"second"}
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } elsif (ref $date eq 'DateTime') { # it's an object... | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $f = DateTime::Format::W3CDTF->new; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $w3cdtf = $f->format_datetime($date); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } elsif ($date =~ /^[0-9]+$/) { # it's an epoch... | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $dt = DateTime->from_epoch( epoch => $date ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $f = DateTime::Format::W3CDTF->new; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $w3cdtf = $f->format_datetime($dt); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $w3cdtf = $date; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $rss->_element_with_data('ev',$elt,$w3cdtf); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||||||||||||