line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
$VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
36200
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
12
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
111
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use base 'XML::Generator::RSS10::Module'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1504
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
1406
|
use Params::Validate qw( validate SCALAR HASHREF OBJECT ); |
|
1
|
|
|
|
|
13085
|
|
|
1
|
|
|
|
|
146
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
80
|
use constant CONTENTS_SPEC => { startdate => { type => SCALAR | HASHREF | OBJECT }, |
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
|
|
|
1
|
|
10
|
}; |
|
1
|
|
|
|
|
2
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
1725
|
use DateTime; |
|
1
|
|
|
|
|
195091
|
|
|
1
|
|
|
|
|
42
|
|
26
|
1
|
|
|
1
|
|
1112
|
use DateTime::Format::W3CDTF; |
|
1
|
|
|
|
|
923
|
|
|
1
|
|
|
|
|
455
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub NamespaceURI { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
'http://purl.org/rss/1.0/modules/event/' |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#### |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub contents { |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
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
|
0
|
0
|
|
|
|
if (($elt eq 'startdate') || ($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
|
|
|
|
|
|
|
sub _evdate { |
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
|
|
|
0
|
|
|
my ($self,$rss,$elt,$date) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $w3cdtf; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if (ref $date eq 'HASH') { # it's a date definition... |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $dt = DateTime->new($date); |
71
|
0
|
|
|
|
|
|
my $f = DateTime::Format::W3CDTF->new; |
72
|
0
|
0
|
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 |
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__ |