File Coverage

blib/lib/Perlanet/Feed.pm
Criterion Covered Total %
statement 17 29 58.6
branch 0 2 0.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 24 38 63.1


line stmt bran cond sub pod time code
1             package Perlanet::Feed;
2              
3 6     6   39 use strict;
  6         15  
  6         180  
4 6     6   34 use warnings;
  6         33  
  6         211  
5              
6 6     6   48 use Moose;
  6         16  
  6         51  
7 6     6   35977 use XML::Feed;
  6         890541  
  6         1579  
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 3 my ($self, $format) = @_;
83              
84 1         13 my $feed = XML::Feed->new($format);
85 0           $feed->title($self->title);
86 0           $feed->link($self->url);
87 0           $feed->description($self->description);
88 0           $feed->author($self->author);
89 0 0         if ($format eq 'Atom') {
90 0           $feed->{atom}->author->email($self->email);
91             }
92 0           $feed->modified($self->modified);
93 0           $feed->self_link($self->self_link);
94 0           $feed->id($self->id);
95 0           $feed->add_entry($_->_entry) for @{ $self->entries };
  0            
96 0           return $feed->as_xml;
97             }
98              
99 6     6   65 no Moose;
  6         28  
  6         65  
100             __PACKAGE__->meta->make_immutable;
101             1;