File Coverage

blib/lib/Perlanet/Feed.pm
Criterion Covered Total %
statement 30 30 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 38 39 97.4


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