root/trunk/plagger/lib/Plagger/Update.pm

Revision 1293 (checked in by miyagawa, 14 years ago)

Filter::BreakEntriesToFeeds?: support Rule to handle which feeds to braek. Suggested by otsune

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Update;
2 use strict;
3
4 sub new {
5     my $class = shift;
6     bless { feeds => [], by_tags => {} }, $class;
7 }
8
9 sub add {
10     my($self, $feed) = @_;
11     push @{ $self->{feeds} }, $feed;
12     for my $tag ( @{$feed->tags} ) {
13         push @{ $self->{by_tags}->{$tag} }, $feed;
14     }
15 }
16
17 sub delete_feed {
18     my($self, $feed) = @_;
19     my @feeds = grep { $_ ne $feed } $self->feeds;
20     $self->{feeds} = \@feeds;
21
22     for my $tag ( @{$feed->tags} ) {
23         my @feeds = grep { $_ ne $feed } @{ $self->{by_tags}->{$tag} };
24         $self->{by_tags}->{$tag} = \@feeds;
25     }
26 }
27
28 sub feeds {
29     my $self = shift;
30     wantarray ? @{ $self->{feeds} } : $self->{feeds};
31 }
32
33 sub count {
34     my $self = shift;
35     scalar @{ $self->{feeds} };
36 }
37
38 sub feeds_by_tag {
39     my($self, $tag) = @_;
40     my @feeds = @{ $self->{by_tags}->{$tag} || [] };
41     wantarray ? @feeds : \@feeds;
42 }
43
44 sub tags {
45     my $self = shift;
46     keys %{ $self->{by_tags} };
47 }
48
49 1;
Note: See TracBrowser for help on using the browser.