App-Chronicle

 view release on metacpan or  search on metacpan

lib/Chronicle/Plugin/Generate/RSS.pm  view on Meta::CPAN

=head1 DESCRIPTION

This module will be invoked automatically when your site is built
via the C<on_generate> hook which Chronicle provides.

It is responsible for creating the top-level RSS-feed for your blog,
which will be located at C</rss.tmpl>.

If there is a file named C<rss.tmpl> in the currently-selected
theme it will be used as the template for the generation of the
feed, otherwise a default RSS-template will be used, which will
come from this module.

=cut

=head1 METHODS

Now follows documentation on the available methods.

=cut


package Chronicle::Plugin::Generate::RSS;


use strict;
use warnings;


our $VERSION = "5.1.7";


=head2 on_generate

The C<on_generate> method is automatically invoked to generate output
pages.  This particular plugin method is invoked I<after> any
C<on_initiate> methods which might be present.

This method is responsible for generating the RSS-feed of your
blog site, via the theme-provided template C<rss.tmpl>.

If there is no C<rss.tmpl> template present in the theme then a default
will be used.

=cut

sub on_generate
{
    my ( $self, %args ) = (@_);

    my $dbh    = $args{ 'dbh' };
    my $config = $args{ 'config' };

    my $recent = $dbh->prepare(
        "SELECT id FROM blog ORDER BY date DESC LIMIT 0,$config->{'rss-count'}")
      or
      die "Failed to find recent posts";

    $recent->execute() or die "Failed to execute:" . $dbh->errstr();
    my $id;
    $recent->bind_columns( undef, \$id );


    my $entries;

    while ( $recent->fetch() )
    {
        my $post =
          Chronicle::getBlog( dbh    => $dbh,
                              id     => $id,
                              config => $config
                            );
        if ( $config->{ 'lower-case' } )
        {
            $post->{ 'link' } = lc( $post->{ 'link' } );
        }

        push( @$entries, $post );
    }
    $recent->finish();


    $config->{ 'verbose' } &&
      print "Creating : $config->{'output'}/index.rss\n";


    #
    #  If there is a theme-provided file then use it.
    #
    my $c = Chronicle::load_template("rss.tmpl");

    #
    #  If not then we're going to use our default, which is
    # contained in the __DATA__ section of this very module.
    #
    if ( !$c )
    {
        my $tmpl = do {local $/; <DATA>};

        #
        #  If there is no template read then something weird has happened
        #
        return unless ( $tmpl && length($tmpl) );

        #
        #  Load the template
        #
        $c = Chronicle::load_template( undef, $tmpl );

    }


    #
    #  At this point we should have one of the two templates loaded,
    # but if not .. we'll just return.
    #
    return unless ($c);

    #
    #  Add the entries.
    #



( run in 0.958 second using v1.01-cache-2.11-cpan-2398b32b56e )