-
Notifications
You must be signed in to change notification settings - Fork 4
/
Feed.pm
86 lines (59 loc) · 1.75 KB
/
Feed.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package VegGuide::Feed;
use strict;
use warnings;
use parent 'XML::Feed';
use XML::Feed;
use XML::Feed::Format::Atom;
use XML::Feed::Format::RSS;
@XML::Feed::Format::RSS::ISA = @XML::Feed::Format::Atom::ISA
= 'VegGuide::Feed';
sub is_entries_only {
my $self = shift;
if (@_) {
$self->{is_entries_only} = shift;
}
return $self->{is_entries_only};
}
sub is_reviews_only {
my $self = shift;
if (@_) {
$self->{is_reviews_only} = shift;
}
return $self->{is_reviews_only};
}
sub convert {
my $self = shift;
my $new = $self->SUPER::convert(@_);
$new->is_entries_only( $self->is_entries_only() );
$new->is_reviews_only( $self->is_reviews_only() );
if ( $new->format() eq 'Atom' ) {
$new->_make_atom_valid();
}
return $new;
}
sub _make_atom_valid {
my $self = shift;
my $root_elem = $self->{atom}->elem();
my $link_node = $root_elem->ownerDocument()
->createElementNS( $self->{atom}->ns(), 'link' );
$link_node->setAttribute( rel => 'self' );
my $self_link = $self->link();
$self_link =~ s{/$}{};
$self_link .= '/site'
if $self_link =~ m{http://[^/]+$};
$self_link .= '/recent.atom';
if ( $self->is_entries_only() ) {
$self_link .= '?entries_only=1';
}
elsif ( $self->is_reviews_only() ) {
$self_link .= '?reviews_only=1';
}
$link_node->setAttribute( href => $self_link );
$root_elem->insertBefore( $link_node, $root_elem->firstChild() );
my $id_node = $root_elem->ownerDocument()
->createElementNS( $self->{atom}->ns(), 'id' );
$id_node->appendChild( XML::LibXML::Text->new( $self->link() ) );
$root_elem->insertBefore( $id_node, $root_elem->firstChild() );
return;
}
1;