Changeset 3
- Timestamp:
- 02/02/06 22:01:25
- Files:
-
- trunk/plagger/config.yaml.sample (modified) (1 diff)
- trunk/plagger/lib/Plagger.pm (modified) (4 diffs)
- trunk/plagger/lib/Plagger/Condition (added)
- trunk/plagger/lib/Plagger/Condition.pm (added)
- trunk/plagger/lib/Plagger/Condition/Always.pm (added)
- trunk/plagger/lib/Plagger/Condition/Compound.pm (added)
- trunk/plagger/lib/Plagger/Condition/Rating.pm (added)
- trunk/plagger/lib/Plagger/Entry.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Plugin.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Filter (added)
- trunk/plagger/lib/Plagger/Plugin/Filter/URLBL.pm (added)
- trunk/plagger/lib/Plagger/Plugin/Publish/Debug.pm (added)
- trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Widget (added)
- trunk/plagger/lib/Plagger/Plugin/Widget/Delicious.pm (added)
- trunk/plagger/lib/Plagger/Update.pm (modified) (1 diff)
- trunk/plagger/templates/plugins/gmail_notify.tt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/config.yaml.sample
r2 r3 12 12 mark_read: 1 13 13 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 14 23 - module: Publish::Gmail 24 condition: 25 - module: Rating 26 rate: '>= 0' 15 27 config: 16 28 mailto: miyagawa@example.com trunk/plagger/lib/Plagger.pm
r2 r3 76 76 while (my($hook, $callback) = splice @hooks, 0, 2) { 77 77 push @{ $self->{hooks}->{$hook} }, +{ 78 callback => $callback,79 plugin => $plugin,78 callback => $callback, 79 plugin => $plugin, 80 80 }; 81 81 } … … 85 85 my($self, $hook, @args) = @_; 86 86 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 } 88 91 } 89 92 } … … 96 99 97 100 for my $feed ($self->update->feeds) { 101 for my $entry ($feed->entries) { 102 $self->run_hook('filter.content', $entry, $entry->text); 103 } 104 98 105 $self->run_hook('publish.notify', $feed); 99 106 } … … 106 113 my $caller = caller(0); 107 114 chomp($msg); 108 warn "$caller: $msg\n"; 115 warn "$caller [$level] $msg\n"; 116 } 117 118 sub error { 119 my($self, $msg) = @_; 120 my $caller = caller(0); 121 chomp($msg); 122 die "$caller $msg\n"; 109 123 } 110 124 trunk/plagger/lib/Plagger/Entry.pm
r2 r3 3 3 4 4 use 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 )); 6 6 7 7 use DateTime::Format::Mail; … … 23 23 id => $item->{guid}, 24 24 body => $item->{description}, 25 rate => 0, 26 widgets => [], 25 27 }, $class; 28 } 29 30 sub add_rate { 31 my($self, $rate) = @_; 32 $self->rate( $self->rate + $rate ); 33 } 34 35 sub text { 36 my $self = shift; 37 join "\n", $self->link, $self->title, $self->body; 38 } 39 40 sub add_widget { 41 my($self, $widget) = @_; 42 push @{ $self->{widgets} }, $widget; 43 } 44 45 sub widgets { 46 my $self = shift; 47 wantarray ? @{ $self->{widgets} } : $self->{widgets}; 26 48 } 27 49 trunk/plagger/lib/Plagger/Plugin.pm
r2 r3 2 2 use strict; 3 3 4 use Plagger::Condition; 5 use Plagger::Condition::Compound; 6 4 7 sub new { 5 8 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; 7 16 } 8 17 9 sub conf { $_[0]->{conf} } 18 sub 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 28 sub conf { $_[0]->{conf} } 29 sub condition { $_[0]->{condition} } 10 30 11 31 1; trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm
r2 r3 71 71 my $route = $cfg->{mailroute} || { via => 'smtp', host => 'localhost' }; 72 72 my @args = $route->{host} ? ($route->{host}) : (); 73 $msg->send($route->{via}, @args); 73 # $msg->send($route->{via}, @args); 74 $context->dumper($msg); 74 75 } 75 76 trunk/plagger/lib/Plagger/Update.pm
r2 r3 4 4 sub new { 5 5 my $class = shift; 6 bless { }, $class;6 bless { feeds => [] }, $class; 7 7 } 8 8 trunk/plagger/templates/plugins/gmail_notify.tt
r2 r3 9 9 [% IF item.body.match('(?i)^<p[ >]') %][% item.body %][% ELSE %]<div style="padding: 1em 0">[% item.body %]</div>[% END %] 10 10 [% 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> 12 12 </div>
