File: Feed.pm

package info (click to toggle)
libperlanet-perl 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: xml: 1,177; perl: 757; sh: 6; makefile: 5
file content (108 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package Perlanet::Feed;

use 5.10.0;
use strict;
use warnings;

use Moose;
use XML::Feed;

=head1 NAME

Perlanet::Feed - represents a feed

=cut

has 'title' => (
  isa => 'Str',
  is => 'rw',
);

has 'url' => (
  isa => 'Str',
  is => 'rw',
);

has 'web' => (
  isa => 'Str',
  is => 'rw',
);

has 'format' => (
  is => 'rw',
);

has 'description' => (
  is => 'rw',
);

has 'author' => (
  is => 'rw',
);

has 'email' => (
  is => 'rw',
);

has '_xml_feed' => (
  isa => 'XML::Feed',
  is => 'rw',
);

has 'id' => (
  is => 'rw',
);

has 'self_link' => (
  is => 'rw',
);

has 'modified' => (
  is => 'rw',
);

has 'max_entries' => (
  is => 'ro',
  isa => 'Int',
);

has 'entries' => (
  isa => 'ArrayRef',
  is => 'rw',
  default => sub { [] },
  traits => [ 'Array' ],
  handles => {
    add_entry => 'push',
  }
);

=head1 METHODS

=head2 as_xml

Returns a string containing the XML for this feed and all its entries

=cut

sub as_xml {
  my $self = shift;
  my ($format) = @_;

  my $feed = XML::Feed->new($format);
  $feed->title($self->title);
  $feed->link($self->url);
  $feed->description($self->description);
  $feed->author($self->author);
  if ($format eq 'Atom') {
    $feed->{atom}->author->email($self->email);
  }
  $feed->modified($self->modified);
  $feed->self_link($self->self_link);
  $feed->id($self->id);
  $feed->add_entry($_->_entry) for @{ $self->entries };
  return $feed->as_xml;
}

no Moose;
__PACKAGE__->meta->make_immutable;
1;