Perlanet::Trait::FeedFile - save the aggregated feed to a file


Perlanet documentation Contained in the Perlanet distribution.

Index


Code Index:

NAME

Top

Perlanet::Trait::FeedFile - save the aggregated feed to a file

SYNOPSIS

Top

   my $perlanet = Perlanet->new_with_traits(
     traits => [ 'Perlanet::Trait::FeedFile' ]
   );

   $perlanet->run;

DESCRIPTION

Top

When the aggregation is complete and the feed is being rendered, it will be saved to disk in XML format.

ATTRIBUTES

Top

feed_file

The path to the file to save the feed to.

feed_format

The format of the XML to use - may be RSS or Atom

AUTHOR

Top

Oliver Charles, <oliver.g.charles@googlemail.com>

COPYRIGHT AND LICENSE

Top


Perlanet documentation Contained in the Perlanet distribution.
package Perlanet::Trait::FeedFile;
use Moose::Role;
use namespace::autoclean;

use Carp qw( croak );
use Template;

has 'feed' => (
  isa       => 'HashRef',
  is        => 'rw',
  default   => sub {
    { file => 'atom.xml', format => 'Atom' }
  },
);

after 'render' => sub {
  my ($self, $feed) = @_;
  return unless $self->feed->{file};

  open my $feedfile, '>', $self->feed->{file}
    or croak 'Cannot open ' . $self->feed->{file} . " for writing: $!";
  print $feedfile $feed->as_xml($self->feed->{format});
  close $feedfile;
};

1;