File Coverage

blib/lib/Perlanet/Feed.pm
Criterion Covered Total %
statement 19 31 61.2
branch 0 2 0.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 27 41 65.8


line stmt bran cond sub pod time code
1             package Perlanet::Feed;
2              
3 6     6   23 use strict;
  6         8  
  6         171  
4 6     6   35 use warnings;
  6         7  
  6         185  
5              
6 6     6   67 use 5.6.0;
  6         15  
7             our $VERSION = '0.58';
8              
9 6     6   28 use Moose;
  6         7  
  6         39  
10 6     6   19099 use XML::Feed;
  6         675694  
  6         1279  
11              
12             =head1 NAME
13              
14             Perlanet::Feed - represents a feed
15              
16             =cut
17              
18             has 'title' => (
19             isa => 'Str',
20             is => 'rw',
21             );
22              
23             has 'url' => (
24             isa => 'Str',
25             is => 'rw',
26             );
27              
28             has 'web' => (
29             isa => 'Str',
30             is => 'rw',
31             );
32              
33             has 'format' => (
34             is => 'rw',
35             );
36              
37             has 'description' => (
38             is => 'rw',
39             );
40              
41             has 'author' => (
42             is => 'rw',
43             );
44              
45             has 'email' => (
46             is => 'rw',
47             );
48              
49             has '_xml_feed' => (
50             isa => 'XML::Feed',
51             is => 'rw',
52             );
53              
54             has 'id' => (
55             is => 'rw',
56             );
57              
58             has 'self_link' => (
59             is => 'rw',
60             );
61              
62             has 'modified' => (
63             is => 'rw',
64             );
65              
66             has 'entries' => (
67             isa => 'ArrayRef',
68             is => 'rw',
69             default => sub { [] },
70             traits => [ 'Array' ],
71             handles => {
72             add_entry => 'push',
73             }
74             );
75              
76             =head1 METHODS
77              
78             =head2 as_xml
79              
80             Returns a string containing the XML for this feed and all its entries
81              
82             =cut
83              
84             sub as_xml {
85 1     1 1 3 my ($self, $format) = @_;
86              
87 1         10 my $feed = XML::Feed->new($format);
88 0           $feed->title($self->title);
89 0           $feed->link($self->url);
90 0           $feed->description($self->description);
91 0           $feed->author($self->author);
92 0 0         if ($format eq 'Atom') {
93 0           $feed->{atom}->author->email($self->email);
94             }
95 0           $feed->modified($self->modified);
96 0           $feed->self_link($self->self_link);
97 0           $feed->id($self->id);
98 0           $feed->add_entry($_->_entry) for @{ $self->entries };
  0            
99 0           return $feed->as_xml;
100             }
101              
102 6     6   45 no Moose;
  6         11  
  6         55  
103             __PACKAGE__->meta->make_immutable;
104             1;