root/trunk/plagger/lib/Plagger/Plugin/SmartFeed.pm

Revision 307 (checked in by miyagawa, 15 years ago)
  • Added clone, clear_entries to $feed
  • Added source to $entry, if it's copied to SmartFeed?
  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::SmartFeed;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Plagger::Tag;
6
7 sub rule_hook { 'smartfeed.entry' }
8
9 sub register {
10     my($self, $context) = @_;
11     $context->register_hook(
12         $self,
13         'smartfeed.init'  => \&feed_init,
14         'smartfeed.entry' => \&feed_entry,
15         'smartfeed.finalize' => \&feed_finalize,
16     );
17 }
18
19 sub feed_init {
20     my($self, $context, $args) = @_;
21
22     my $feed = Plagger::Feed->new;
23     $feed->type('smartfeed');
24     $feed->id( $self->conf->{id} || ('smartfeed:' . $self->rule->id) );
25     $feed->title( $self->conf->{title} || "Entries " . $self->rule->as_title );
26
27     $self->{feed} = $feed;
28 }
29
30 sub feed_entry {
31     my($self, $context, $args) = @_;
32
33     my $entry = $args->{entry}->clone;
34     my $feed  = $args->{feed}->clone;
35        $feed->clear_entries;
36     $entry->source($feed); # xxx is it only valid for SmartFeed
37
38     $self->{feed}->add_entry($entry);
39 }
40
41 sub feed_finalize {
42     my($self, $context, $args) = @_;
43     $context->update->add($self->{feed}) if $self->{feed}->count;
44 }
45
46 1;
Note: See TracBrowser for help on using the browser.