| 1 | package Plagger::Plugin::Summary::Auto; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | use Plagger::Util; | ||
| 6 | |||
| 7 | sub register { | ||
| 8 | my($self, $context) = @_; | ||
| 9 | $context->register_hook( | ||
| 10 | $self, | ||
| 11 | 'update.entry.fixup' => \&auto_summarize, | ||
| 12 | ); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub auto_summarize { | ||
| 16 | my($self, $context, $args) = @_; | ||
| 17 | |||
| 18 | if ($args->{entry}->body && !$args->{entry}->summary) { | ||
| 19 | # give plugins a chance | ||
| 20 | my $summary = $context->run_hook_once('summarizer.summarize', { | ||
| 21 | entry => $args->{entry}, | ||
| 22 | feed => $args->{feed}, | ||
| 23 | text => $args->{entry}->body, | ||
| 24 | }); | ||
| 25 | $args->{entry}->summary($summary) if defined $summary; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | __END__ |