File Coverage

blib/lib/Perlanet/Trait/FeedFile.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Perlanet::Trait::FeedFile;
2              
3 6     6   2569 use strict;
  6         9  
  6         150  
4 6     6   19 use warnings;
  6         8  
  6         116  
5              
6 6     6   52 use 5.6.0;
  6         16  
7             our $VERSION = '0.58';
8              
9 6     6   21 use Moose::Role;
  6         10  
  6         40  
10 6     6   21015 use namespace::autoclean;
  6         9  
  6         38  
11              
12             =head1 NAME
13              
14             Perlanet::Trait::FeedFile - save the aggregated feed to a file
15              
16             =head1 SYNOPSIS
17              
18             my $perlanet = Perlanet->new_with_traits(
19             traits => [ 'Perlanet::Trait::FeedFile' ]
20             );
21              
22             $perlanet->run;
23              
24             =head1 DESCRIPTION
25              
26             When the aggregation is complete and the feed is being rendered, it will be
27             saved to disk in XML format.
28              
29             =head1 ATTRIBUTES
30              
31             =head2 feed_file
32              
33             The path to the file to save the feed to.
34              
35             =head2 feed_format
36              
37             The format of the XML to use - may be RSS or Atom
38              
39             =cut
40              
41 6     6   406 use Carp qw( croak );
  6         8  
  6         230  
42 6     6   23 use Template;
  6         9  
  6         867  
43              
44             has 'feed' => (
45             isa => 'HashRef',
46             is => 'rw',
47             default => sub {
48             { file => 'atom.xml', format => 'Atom' }
49             },
50             );
51              
52             after 'render' => sub {
53             my ($self, $feed) = @_;
54             return unless $self->feed->{file};
55              
56             open my $feedfile, '>', $self->feed->{file}
57             or croak 'Cannot open ' . $self->feed->{file} . " for writing: $!";
58             print $feedfile $feed->as_xml($self->feed->{format});
59             close $feedfile;
60             };
61              
62             =head1 AUTHOR
63              
64             Oliver Charles, <oliver.g.charles@googlemail.com>
65              
66             =head1 COPYRIGHT AND LICENSE
67              
68             Copyright (c) 2010 by Magnum Solutions Ltd.
69              
70             This library is free software; you can redistribute it and/or modify
71             it under the same terms as Perl itself, either Perl version 5.10.0 or,
72             at your option, any later version of Perl 5 you may have available.
73              
74             =cut
75              
76             1;