Changeset 20

Show
Ignore:
Timestamp:
02/05/06 10:48:56
Author:
miyagawa
Message:

updated subscription and aggregator.aggregate API so you can register custom feed type

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger.pm

    r18 r20  
    100100 
    101101    $self->run_hook('subscription.load'); 
    102     $self->run_hook('aggregator.aggregate'); 
     102 
     103    for my $type ($self->subscription->types) { 
     104        for my $feed ($self->subscription->feeds_by_type($type)) { 
     105            $self->run_hook("aggregator.aggregate.$type", $feed); 
     106        } 
     107    } 
    103108 
    104109    for my $feed ($self->update->feeds) { 
  • trunk/plagger/lib/Plagger/Feed.pm

    r18 r20  
    33 
    44use base qw( Class::Accessor::Fast ); 
    5 __PACKAGE__->mk_accessors(qw( link url image description language author updated tags stash )); 
     5__PACKAGE__->mk_accessors(qw( link url image description language author updated tags stash type )); 
    66 
    77sub new { 
     
    1111        tags  => [], 
    1212        entries => [], 
     13        type  => 'feed', 
    1314    }, $class; 
    1415} 
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm

    r17 r20  
    11package Plagger::Plugin::Aggregator::Simple; 
    22use strict; 
    3 use base qw( Plagger::Plugin); 
     3use base qw( Plagger::Plugin ); 
    44 
    55use URI; 
     
    1313    $context->register_hook( 
    1414        $self, 
    15         'aggregator.aggregate' => \&aggregate, 
     15        'aggregator.aggregate.feed' => \&aggregate, 
    1616    ); 
    1717} 
    1818 
    1919sub aggregate { 
    20     my($self, $context) = @_; 
     20    my($self, $context, $sub) = @_; 
    2121 
    22     for my $sub ($context->subscription->feeds) { 
    23         my $url = $sub->url; 
    24         $context->log(info => "Fetch $url"); 
    25         my $remote = eval { XML::Feed->parse(URI->new($url)) }; 
     22    my $url = $sub->url; 
     23    $context->log(info => "Fetch $url"); 
     24    my $remote = eval { XML::Feed->parse(URI->new($url)) }; 
    2625 
    27         unless ($remote) { 
    28             $context->log(info => "Parsing $url failed. " . XML::Feed->errstr); 
    29             next; 
    30        
     26    unless ($remote) { 
     27        $context->log(info => "Parsing $url failed. " . XML::Feed->errstr); 
     28        next; 
     29   
    3130 
    32         my $feed = Plagger::Feed->new; 
    33         $feed->title($remote->title); 
    34         $feed->url($sub->url); 
    35         $feed->link($remote->link); 
    36         $feed->description($remote->tagline); 
    37         $feed->language($remote->language); 
    38         $feed->author($remote->author); 
    39         $feed->updated($remote->modified); 
     31    my $feed = Plagger::Feed->new; 
     32    $feed->title($remote->title); 
     33    $feed->url($sub->url); 
     34    $feed->link($remote->link); 
     35    $feed->description($remote->tagline); 
     36    $feed->language($remote->language); 
     37    $feed->author($remote->author); 
     38    $feed->updated($remote->modified); 
    4039 
    41         for my $e ($remote->entries) { 
    42             my $entry = Plagger::Entry->new; 
    43             $entry->title($e->title); 
    44             $entry->author($e->author); 
    45             $entry->tags([ $e->category ]) if $e->category; 
    46             $entry->date( Plagger::Date->rebless($e->issued) ) 
    47                 if eval { $e->issued }; 
    48             $entry->link($e->link); 
    49             $entry->id($e->id); 
    50             $entry->body($e->content->body); 
     40    for my $e ($remote->entries) { 
     41        my $entry = Plagger::Entry->new; 
     42        $entry->title($e->title); 
     43        $entry->author($e->author); 
     44        $entry->tags([ $e->category ]) if $e->category; 
     45        $entry->date( Plagger::Date->rebless($e->issued) ) 
     46            if eval { $e->issued }; 
     47        $entry->link($e->link); 
     48        $entry->id($e->id); 
     49        $entry->body($e->content->body); 
    5150 
    52             $feed->add_entry($entry); 
    53        
     51        $feed->add_entry($entry); 
     52   
    5453 
    55         $context->log(info => "Aggregate $url success: " . $feed->count . " entries."); 
    56         $context->update->add($feed); 
    57     } 
     54    $context->log(info => "Aggregate $url success: " . $feed->count . " entries."); 
     55    $context->update->add($feed); 
    5856} 
    5957 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm

    r7 r20  
    1414        $context->register_hook( 
    1515            $self, 
    16             'subscription.load'    => \&getsubs, 
     16            'subscription.load' => \&getsubs, 
    1717        ); 
    1818    } else { 
    1919        $context->register_hook( 
    2020            $self, 
    21             'subscription.load'    => \&notifier, 
    22             'aggregator.aggregate' => \&sync, 
     21            'subscription.load' => \&notifier, 
     22            'aggregator.aggregate.bloglines' => \&sync, 
    2323        ); 
    2424    } 
     
    6363    my $count = $self->{bloglines}->notify(); 
    6464    $context->log(debug => "You have $count unread item(s) on Bloglines."); 
    65     $self->{bloglines_new} = $count; 
     65    if ($count) { 
     66        my $feed = Plagger::Feed->new; 
     67        $feed->type('bloglines'); 
     68        $context->subscription->add($feed); 
     69    } 
    6670} 
    6771 
    6872sub sync { 
    69     my($self, $context) = @_; 
    70  
    71     return unless $self->{bloglines_new}; 
     73    my($self, $context, $sub) = @_; 
    7274 
    7375    my @updates = $self->{bloglines}->getitems(0, $self->conf->{mark_read}); 
  • trunk/plagger/lib/Plagger/Subscription.pm

    r7 r20  
    33use base qw( Plagger::Update ); 
    44 
     5sub new { 
     6    my $class = shift; 
     7    bless { feeds => [], by_tags => {}, by_types => {} }, $class; 
     8} 
     9 
     10sub add { 
     11    my($self, $feed) = @_; 
     12    push @{ $self->{feeds} }, $feed; 
     13    for my $tag ( @{$feed->tags} ) { 
     14        push @{ $self->{by_tags}->{$tag} }, $feed; 
     15    } 
     16    push @{ $self->{by_types}->{$feed->type} }, $feed; 
     17} 
     18 
     19sub types { 
     20    my $self = shift; 
     21    keys %{ $self->{by_types} }; 
     22} 
     23 
     24sub feeds_by_type { 
     25    my($self, $type) = @_; 
     26    @{ $self->{by_types}->{$type} || [] }; 
     27} 
     28 
    5291;