Changeset 36

Show
Ignore:
Timestamp:
02/06/06 15:11:24
Author:
miyagawa
Message:

Plugin API change: now args are all in a hashref, rather than ordered params

Files:

Legend:

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

    r31 r36  
    8787 
    8888sub run_hook { 
    89     my($self, $hook, @args) = @_; 
     89    my($self, $hook, $args) = @_; 
    9090    for my $action (@{ $self->{hooks}->{$hook} }) { 
    9191        my $plugin = $action->{plugin}; 
    92         if ( $plugin->rule->dispatch(@args) ) { 
    93             $action->{callback}->($plugin, $self, @args); 
     92        if ( $plugin->rule->dispatch($args) ) { 
     93            $action->{callback}->($plugin, $self, $args); 
    9494        } 
    9595    } 
     
    103103    for my $type ($self->subscription->types) { 
    104104        for my $feed ($self->subscription->feeds_by_type($type)) { 
    105             $self->run_hook("aggregator.aggregate.$type", $feed); 
     105            $self->run_hook("aggregator.aggregate.$type", { feed => $feed }); 
    106106        } 
    107107    } 
     
    109109    for my $feed ($self->update->feeds) { 
    110110        for my $entry ($feed->entries) { 
    111             $self->run_hook('filter.content', $entry, $entry->text); 
     111            $self->run_hook('filter.content', { entry => $entry, content => $entry->text }); 
    112112        } 
    113  
    114         $self->run_hook('publish.notify', $feed); 
     113        $self->run_hook('publish.notify', { feed => $feed }); 
    115114    } 
    116115 
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm

    r20 r36  
    1818 
    1919sub aggregate { 
    20     my($self, $context, $sub) = @_; 
     20    my($self, $context, $args) = @_; 
    2121 
    22     my $url = $sub->url; 
     22    my $url = $args->{feed}->url; 
    2323    $context->log(info => "Fetch $url"); 
    2424    my $remote = eval { XML::Feed->parse(URI->new($url)) }; 
     
    3131    my $feed = Plagger::Feed->new; 
    3232    $feed->title($remote->title); 
    33     $feed->url($sub->url); 
     33    $feed->url($url); 
    3434    $feed->link($remote->link); 
    3535    $feed->description($remote->tagline); 
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Mixi.pm

    r28 r36  
    2727 
    2828sub aggregate { 
    29     my($self, $context, $sub) = @_; 
     29    my($self, $context, $args) = @_; 
    3030 
    3131    my $response = $self->{mixi}->login; 
  • trunk/plagger/lib/Plagger/Plugin/Filter/URLBL.pm

    r7 r36  
    1818 
    1919sub content { 
    20     my($self, $context, $entry, $content) = @_; 
     20    my($self, $context, $args) = @_; 
    2121 
    2222    my @urls; 
     
    3030        }, 
    3131    ); 
    32     $finder->find(\$content); 
     32    $finder->find(\$args->{content}); 
    3333 
    3434    my $res = Net::DNS::Resolver->new; 
     
    4949                my $rate = $self->conf->{rate} || -1; 
    5050                $context->log(warn => "$domain.$dns found. Add rate $rate"); 
    51                 $entry->add_rate($rate); 
     51                $args->{entry}->add_rate($rate); 
    5252            } 
    5353        } 
  • trunk/plagger/lib/Plagger/Plugin/Publish/Debug.pm

    r3 r36  
    1414 
    1515sub notify { 
    16     my($self, $context, $feed) = @_; 
    17     $context->dumper($feed); 
     16    my($self, $context, $args) = @_; 
     17    $context->dumper($args->{feed}); 
    1818} 
    1919 
  • trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm

    r35 r36  
    2020 
    2121sub notify { 
    22     my($self, $context, $feed) = @_; 
     22    my($self, $context, $args) = @_; 
    2323 
     24    my $feed = $args->{feed}; 
    2425    my $subject = $feed->title || '(no-title)'; 
    2526    my $body = $self->templatize($context, $feed); 
  • trunk/plagger/lib/Plagger/Plugin/Publish/JavaScript.pm

    r32 r36  
    1515 
    1616sub notify { 
    17     my($self, $context, $feed) = @_; 
     17    my($self, $context, $args) = @_; 
    1818 
    1919    my $dir = $self->conf->{dir}; 
     
    2222    } 
    2323 
    24     my $file = $self->gen_filename($feed); 
     24    my $file = $self->gen_filename($args->{feed}); 
    2525    my $path = File::Spec->catfile($dir, $file); 
    2626    $context->log(info => "writing output to $path"); 
    2727 
    28     my $body = $self->templatize($context, $feed); 
     28    my $body = $self->templatize($context, $args->{feed}); 
    2929 
    3030    open my $out, ">:utf8", $path or $context->error("$path: $!"); 
  • trunk/plagger/lib/Plagger/Plugin/Publish/PSP.pm

    r31 r36  
    1515 
    1616sub notify { 
    17     my($self, $context, $feed) = @_; 
    18  
    19     $feed->{title} = $feed->{title} || '(no-title)'; 
    20     $context->log(warn => "Store $feed->{title}"); 
     17    my($self, $context, $args) = @_; 
    2118    push @{ $self->{__feeds} }, $feed; 
    2219} 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm

    r20 r36  
    7171 
    7272sub sync { 
    73     my($self, $context, $sub) = @_; 
     73    my($self, $context, $args) = @_; 
    7474 
    7575    my @updates = $self->{bloglines}->getitems(0, $self->conf->{mark_read}); 
  • trunk/plagger/lib/Plagger/Plugin/Widget/Delicious.pm

    r11 r36  
    1616 
    1717sub add { 
    18     my($self, $context, $entry, $content) = @_; 
    19     $entry->add_widget($self); 
     18    my($self, $context, $args) = @_; 
     19    $args->{entry}->add_widget($self); 
    2020} 
    2121 
  • trunk/plagger/lib/Plagger/Plugin/Widget/HatenaBookmark.pm

    r10 r36  
    1616 
    1717sub add { 
    18     my($self, $context, $entry, $content) = @_; 
    19     $entry->add_widget($self); 
     18    my($self, $context, $args) = @_; 
     19    $args->{entry}->add_widget($self); 
    2020} 
    2121 
  • trunk/plagger/lib/Plagger/Rule/Compound.pm

    r7 r36  
    1010 
    1111sub dispatch { 
    12     my($self, @args) = @_; 
     12    my($self, $args) = @_; 
    1313 
    1414    my $bool = 1; 
    1515    for my $rule (@{ $self->{rules} }) { 
    16         $bool = 0 unless $rule->dispatch(@args); # AND mode 
     16        $bool = 0 unless $rule->dispatch($args); # AND mode 
    1717    } 
    1818 
  • trunk/plagger/lib/Plagger/Rule/Expression.pm

    r30 r36  
    44 
    55sub dispatch { 
    6     my($self, $feed) = @_; 
     6    my($self, $args) = @_; 
    77    my $status = eval $self->{expression}; 
    88    if ($@) { 
  • trunk/plagger/lib/Plagger/Rule/Rating.pm

    r7 r36  
    2424 
    2525sub dispatch { 
    26     my($self, $feed) = @_; 
     26    my($self, $args) = @_; 
     27 
     28    my $feed = $args->{feed} 
     29        or Plagger->context->error("No feed object in this plugin phase"); 
    2730 
    2831    my $rate = 0; 
  • trunk/plagger/lib/Plagger/UserAgent.pm

    r8 r36  
    66    my $class = shift; 
    77    my $self  = $class->SUPER::new(); 
    8     $self->agent("Plagger/$Plagger::VERSION"); 
     8    $self->agent("Plagger/$Plagger::VERSION (http://plagger.bulknews.net/)"); 
    99    $self; 
    1010} 
  • trunk/plagger/templates/plugins/psp.tt

    r23 r36  
    1818[% IF item.body.match('(?i)^<p[ >]') %][% item.body %][% ELSE %]<div class="item_body">[% item.body %]</div>[% END %] 
    1919[% ELSE %]<br />[% END %] 
    20 <div class="post">[% IF item.date %]Posted on [% item.date.format('Mail') %][% END %] | <a href="[% link | html %]">permalink</a> | <a href="[% feed.link | html %]">[% feed.title | html %]</a>[% FOREACH widget = item.widgets %] | [% widget.html(item) %][% END %]<br clear="all" /></div> 
     20<div class="post">[% IF item.date %]Posted on [% item.date.format('Mail') %][% END %] | <a href="[% link | html %]">permalink</a> | <a href="[% feed.link | html %]">[% (feed.title || '(no-title)') | html %]</a>[% FOREACH widget = item.widgets %] | [% widget.html(item) %][% END %]<br clear="all" /></div> 
    2121</div> 
    2222[% END %]