Skip to content

Commit

Permalink
Added ability to override number of entries for a specific feed
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Sep 24, 2020
1 parent a774740 commit ecf544c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 4 deletions.
3 changes: 3 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ t/05_cache.t
t/06_youtube.t
t/07_page.t
t/08_opml.t
t/09_entries.t
t/pod.t
t/pod_coverage.t
t/testrc
Expand All @@ -33,6 +34,8 @@ t/cacherc
t/mprc
t/youtuberc
t/youtube2rc
t/allentriesrc
t/5entriesrc
t/index.tt
README
Changes
Expand Down
5 changes: 4 additions & 1 deletion bin/perlanet
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ to identify the entries that originate from this feed. The optional C<web>
sub-option gives a web site URL associated with the feed (often the address
of the web site that the feed comes from). This can be used to create a list
of the aggregated sites. The C<web> sub-option becomes mandatory if you are
creating an OPML file.
creating an OPML file. You can also add a C<max_entries> option which will
override the global C<entries_per_feed> setting. If this setting exists
and is set to zero, then the output feed will contain all of the entries
from this input feed.

=back

Expand Down
10 changes: 7 additions & 3 deletions lib/Perlanet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use XML::Feed;
use vars qw{$VERSION};

BEGIN {
$VERSION = '2.0.1';
$VERSION = '2.0.2';
}

with 'MooseX::Traits';
Expand Down Expand Up @@ -230,8 +230,12 @@ sub select_entries {

@entries = @{ $self->sort_entries(\@entries) };

if ($self->entries_per_feed and @entries > $self->entries_per_feed) {
$#entries = $self->entries_per_feed - 1;
my $number_of_entries =
defined $feed->max_entries ? $feed->max_entries
: $self->entries_per_feed;

if ($number_of_entries and @entries > $number_of_entries) {
$#entries = $number_of_entries - 1;
}

push @feed_entries,
Expand Down
5 changes: 5 additions & 0 deletions lib/Perlanet/Feed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ has 'modified' => (
is => 'rw',
);

has 'max_entries' => (
is => 'ro',
isa => 'Int',
);

has 'entries' => (
isa => 'ArrayRef',
is => 'rw',
Expand Down
25 changes: 25 additions & 0 deletions t/09_entries.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
use Perlanet::Simple;

chdir $Bin;

my @tests = ({
rc => '5',
count => 5,
}, {
rc => 'all',
count => 10,
});

for (@tests) {
my $p = Perlanet::Simple->new_with_config(configfile => "$_->{rc}entriesrc");

my $feeds = $p->fetch_feeds($p->feeds);
my $selected = $p->select_entries($feeds);
is(@$selected, $_->{count}, "Override to get $_->{rc} selected entries");
}

done_testing();
22 changes: 22 additions & 0 deletions t/5entriesrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
title: planet test
description: Testing stuff
url: http://theplanetarium.org/
self_link: http://theplanetarium.org/
agent: Testing Perlanet
entries_per_feed: 1
author:
name: Dave Cross
email: dave@dave.org.uk
max_entries: 20
page:
file: index.html
template: index.tt
feed:
file: rss.xml
format: Atom
feeds:
- url: file:data/davblog.xml
title: davblog
web: http://blogs.dave.org.uk/
max_entries: 5

22 changes: 22 additions & 0 deletions t/allentriesrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
title: planet test
description: Testing stuff
url: http://theplanetarium.org/
self_link: http://theplanetarium.org/
agent: Testing Perlanet
entries_per_feed: 1
author:
name: Dave Cross
email: dave@dave.org.uk
max_entries: 20
page:
file: index.html
template: index.tt
feed:
file: rss.xml
format: Atom
feeds:
- url: file:data/davblog.xml
title: davblog
web: http://blogs.dave.org.uk/
max_entries: 0

0 comments on commit ecf544c

Please sign in to comment.