Changeset 3

Show
Ignore:
Timestamp:
02/02/06 22:01:25
Author:
miyagawa
Message:

* Added $plugin->condition to conditionally dispatch plugins
* Added Filter::URLBL, Widget::Delicious plugins to demonstrate the new 'filter.content' API hook
* Added Publish::Debug for debugging of conditions/widgets
- Misc bug fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/config.yaml.sample

    r2 r3  
    1212      mark_read: 1 
    1313 
     14  - module: Filter::URLBL 
     15    config: 
     16      dnsbl: rbl.bulkfeeds.jp 
     17      rate:  -1 
     18 
     19  - module: Widget::Delicious 
     20    config: 
     21      username: miyagawa 
     22 
    1423  - module: Publish::Gmail 
     24    condition: 
     25      - module: Rating 
     26        rate:   '>= 0' 
    1527    config: 
    1628      mailto:   miyagawa@example.com 
  • trunk/plagger/lib/Plagger.pm

    r2 r3  
    7676    while (my($hook, $callback) = splice @hooks, 0, 2) { 
    7777        push @{ $self->{hooks}->{$hook} }, +{ 
    78             callback => $callback, 
    79             plugin   => $plugin, 
     78            callback => $callback, 
     79            plugin    => $plugin, 
    8080        }; 
    8181    } 
     
    8585    my($self, $hook, @args) = @_; 
    8686    for my $action (@{ $self->{hooks}->{$hook} }) { 
    87         $action->{callback}->($action->{plugin}, $self, @args); 
     87        my $plugin = $action->{plugin}; 
     88        if ( $plugin->condition->dispatch(@args) ) { 
     89            $action->{callback}->($plugin, $self, @args); 
     90        } 
    8891    } 
    8992} 
     
    9699 
    97100    for my $feed ($self->update->feeds) { 
     101        for my $entry ($feed->entries) { 
     102            $self->run_hook('filter.content', $entry, $entry->text); 
     103        } 
     104 
    98105        $self->run_hook('publish.notify', $feed); 
    99106    } 
     
    106113    my $caller = caller(0); 
    107114    chomp($msg); 
    108     warn "$caller: $msg\n"; 
     115    warn "$caller [$level] $msg\n"; 
     116
     117 
     118sub error { 
     119    my($self, $msg) = @_; 
     120    my $caller = caller(0); 
     121    chomp($msg); 
     122    die "$caller $msg\n"; 
    109123} 
    110124 
  • trunk/plagger/lib/Plagger/Entry.pm

    r2 r3  
    33 
    44use base qw( Class::Accessor::Fast ); 
    5 __PACKAGE__->mk_accessors(qw( title author tags date link id summary body )); 
     5__PACKAGE__->mk_accessors(qw( title author tags date link id summary body rate )); 
    66 
    77use DateTime::Format::Mail; 
     
    2323        id     => $item->{guid}, 
    2424        body   => $item->{description}, 
     25        rate   => 0, 
     26        widgets => [], 
    2527    }, $class; 
     28} 
     29 
     30sub add_rate { 
     31    my($self, $rate) = @_; 
     32    $self->rate( $self->rate + $rate ); 
     33} 
     34 
     35sub text { 
     36    my $self = shift; 
     37    join "\n", $self->link, $self->title, $self->body; 
     38} 
     39 
     40sub add_widget { 
     41    my($self, $widget) = @_; 
     42    push @{ $self->{widgets} }, $widget; 
     43} 
     44 
     45sub widgets { 
     46    my $self = shift; 
     47    wantarray ? @{ $self->{widgets} } : $self->{widgets}; 
    2648} 
    2749 
  • trunk/plagger/lib/Plagger/Plugin.pm

    r2 r3  
    22use strict; 
    33 
     4use Plagger::Condition; 
     5use Plagger::Condition::Compound; 
     6 
    47sub new { 
    58    my($class, $opt) = @_; 
    6     bless { conf => $opt->{config}, stash => {} }, $class; 
     9    my $self = bless { 
     10        conf => $opt->{config} || {}, 
     11        condition => $opt->{condition}, 
     12        stash => {}, 
     13    }, $class; 
     14    $self->init(); 
     15    $self; 
    716} 
    817 
    9 sub conf  { $_[0]->{conf} } 
     18sub init { 
     19    my $self = shift; 
     20    if (my $cond = $self->{condition}) { 
     21        $cond = [ $cond ] if ref($cond) eq 'HASH'; 
     22        $self->{condition} = Plagger::Condition::Compound->new(@$cond); 
     23    } else { 
     24        $self->{condition} = Plagger::Condition->new({ module => 'Always' }); 
     25    } 
     26
     27 
     28sub conf      { $_[0]->{conf} } 
     29sub condition { $_[0]->{condition} } 
    1030 
    11311; 
  • trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm

    r2 r3  
    7171    my $route = $cfg->{mailroute} || { via => 'smtp', host => 'localhost' }; 
    7272    my @args  = $route->{host} ? ($route->{host}) : (); 
    73     $msg->send($route->{via}, @args); 
     73#    $msg->send($route->{via}, @args); 
     74    $context->dumper($msg); 
    7475} 
    7576 
  • trunk/plagger/lib/Plagger/Update.pm

    r2 r3  
    44sub new { 
    55    my $class = shift; 
    6     bless {}, $class; 
     6    bless { feeds => [] }, $class; 
    77} 
    88 
  • trunk/plagger/templates/plugins/gmail_notify.tt

    r2 r3  
    99[% IF item.body.match('(?i)^<p[ >]') %][% item.body %][% ELSE %]<div style="padding: 1em 0">[% item.body %]</div>[% END %] 
    1010[% ELSE %]<br />[% END %] 
    11 <div style="font-size:0.8em">[% 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>[% var = 'delicious-username'; IF cfg.$var %][% SET u = "http://del.icio.us/" _ cfg.$var; USE delicious = url(u) %] | <a href="[% SET t = feed.title _ ": " _ item.title; delicious(v=3, url=item.link, title=utf8(t)) %]">Post to del.icio.us</a>[% END %]<br clear="all" /></div> 
     11<div style="font-size:0.8em">[% 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 %][% END %]<br clear="all" /></div> 
    1212</div>