line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################################## |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# XML::RSS::FromAtom |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright 2005, Marcus Thiesen (marcus@thiesen.org) All rights reserved. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
8
|
|
|
|
|
|
|
# it under the terms of either: |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# a) the GNU General Public License as published by the Free Software |
11
|
|
|
|
|
|
|
# Foundation; either version 1, or (at your option) any later |
12
|
|
|
|
|
|
|
# version, or |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# b) the "Artistic License" which comes with Perl. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# On Debian GNU/Linux systems, the complete text of the GNU General |
17
|
|
|
|
|
|
|
# Public License can be found in `/usr/share/common-licenses/GPL' and |
18
|
|
|
|
|
|
|
# the Artistic Licence in `/usr/share/common-licenses/Artistic'. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
21
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
######################################################################## |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package XML::RSS::FromAtom; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
198991
|
use common::sense; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
12351
|
use DateTime; |
|
1
|
|
|
|
|
196997
|
|
|
1
|
|
|
|
|
34
|
|
31
|
1
|
|
|
1
|
|
927
|
use DateTime::Format::ISO8601; |
|
1
|
|
|
|
|
95132
|
|
|
1
|
|
|
|
|
88
|
|
32
|
1
|
|
|
1
|
|
1166
|
use DateTime::Format::Mail; |
|
1
|
|
|
|
|
2322
|
|
|
1
|
|
|
|
|
34
|
|
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
62608
|
use Moo; |
|
1
|
|
|
|
|
70025
|
|
|
1
|
|
|
|
|
8
|
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
2117
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
1029
|
use XML::Atom::Syndication::Feed; |
|
1
|
|
|
|
|
40947
|
|
|
1
|
|
|
|
|
32
|
|
39
|
1
|
|
|
1
|
|
2098
|
use XML::RSS; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Version set by dist.ini; do not change here. |
42
|
|
|
|
|
|
|
our $VERSION = '0.02_03'; # VERSION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has 'syndicator' => ( |
45
|
|
|
|
|
|
|
is => 'ro', |
46
|
|
|
|
|
|
|
lazy => 1, |
47
|
|
|
|
|
|
|
builder => 'build_syndicator' ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub build_syndicator { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
return XML::Atom::Syndication::Feed->new(\$self->content); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'rss_processor' => ( |
55
|
|
|
|
|
|
|
is => 'ro', |
56
|
|
|
|
|
|
|
lazy => 1, |
57
|
|
|
|
|
|
|
builder => 'build_rss_processor', |
58
|
|
|
|
|
|
|
handles => [qw(add_item channel)] ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub build_rss_processor { |
61
|
|
|
|
|
|
|
return XML::RSS->new(version => '2.0'); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has 'content' => ( |
65
|
|
|
|
|
|
|
is => 'rw' |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub parse { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my $text = shift; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$self->content( $text ); |
73
|
|
|
|
|
|
|
return $self->atom_to_rss(); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub atom_to_rss { |
77
|
|
|
|
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
my $doc = $self->syndicator(); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $feed_title = $doc->title->body(); |
81
|
|
|
|
|
|
|
my $feed_description = $doc->subtitle->body(); |
82
|
|
|
|
|
|
|
my $feed_link = $doc->link->href(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->channel(title => $feed_title) if ($feed_title); |
85
|
|
|
|
|
|
|
$self->channel(description => $feed_description) if ($feed_description); |
86
|
|
|
|
|
|
|
$self->channel(link => $feed_link) if ($feed_link); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my @entries = $doc->entries(); |
89
|
|
|
|
|
|
|
for my $e (@entries) { |
90
|
|
|
|
|
|
|
my $desc = ''; |
91
|
|
|
|
|
|
|
$desc = $e->summary->body(); |
92
|
|
|
|
|
|
|
my $content = |
93
|
|
|
|
|
|
|
try { $e->content->body() } |
94
|
|
|
|
|
|
|
catch { undef }; |
95
|
|
|
|
|
|
|
if (defined($content) && |
96
|
|
|
|
|
|
|
length($content) > length($desc)) { |
97
|
|
|
|
|
|
|
$desc = $$content; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $title = $e->title->body(); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $mod = $e->modified(); |
103
|
|
|
|
|
|
|
my $upd = $e->updated(); |
104
|
|
|
|
|
|
|
my $ts = defined($mod) ? $mod : $upd; |
105
|
|
|
|
|
|
|
my $dt = DateTime::Format::ISO8601->parse_datetime( $ts ); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $link = $e->link->href(); |
108
|
|
|
|
|
|
|
my $author = $e->author->name(); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$self->add_item( |
111
|
|
|
|
|
|
|
title => $title, |
112
|
|
|
|
|
|
|
link => $link, |
113
|
|
|
|
|
|
|
description => $desc, |
114
|
|
|
|
|
|
|
pubDate => DateTime::Format::Mail->format_datetime($dt), |
115
|
|
|
|
|
|
|
author => $author ? $author : undef, |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return $self->rss_processor; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# ABSTRACT: create a XML::RSS object out of an Atom feed |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |