|
Revision 1734
(checked in by miyagawa, 2 years ago)
|
added Test::Spelling and fixed typoes
|
| Line | |
|---|
| 1 |
package Plagger::Rule::Deduped; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Rule ); |
|---|
| 4 |
|
|---|
| 5 |
use UNIVERSAL::require; |
|---|
| 6 |
|
|---|
| 7 |
sub init { |
|---|
| 8 |
my $self = shift; |
|---|
| 9 |
|
|---|
| 10 |
$self->{engine} ||= 'DB_File'; |
|---|
| 11 |
|
|---|
| 12 |
my $class = "Plagger::Rule::Deduped::$self->{engine}"; |
|---|
| 13 |
$class->require or Plagger->context->error("Error loading $class: $@"); |
|---|
| 14 |
|
|---|
| 15 |
my $deduper = $class->new($self); |
|---|
| 16 |
$self->{deduper} = $deduper; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
sub id { |
|---|
| 20 |
my $self = shift; |
|---|
| 21 |
return "Deduped"; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
sub as_title { |
|---|
| 25 |
my $self = shift; |
|---|
| 26 |
return "Deduped entries"; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
sub dispatch { |
|---|
| 30 |
my($self, $args) = @_; |
|---|
| 31 |
|
|---|
| 32 |
unless ($args->{entry}) { |
|---|
| 33 |
Plagger->context->error("This rule needs entry object to work."); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
my $is_new = $self->{deduper}->is_new($args->{entry}); |
|---|
| 37 |
$self->{deduper}->add($args->{entry}) if $is_new; |
|---|
| 38 |
|
|---|
| 39 |
return $is_new; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
1; |
|---|
| 43 |
|
|---|
| 44 |
__END__ |
|---|
| 45 |
|
|---|
| 46 |
=head1 NAME |
|---|
| 47 |
|
|---|
| 48 |
Plagger::Rule::Deduped - Rule to get Deduped entries based on the database |
|---|
| 49 |
|
|---|
| 50 |
=head1 SYNOPSIS |
|---|
| 51 |
|
|---|
| 52 |
# remove entries you already seen |
|---|
| 53 |
- module: Filter::Rule |
|---|
| 54 |
rule: |
|---|
| 55 |
module: Deduped |
|---|
| 56 |
path: /tmp/var.db |
|---|
| 57 |
|
|---|
| 58 |
=head1 DESCRIPTION |
|---|
| 59 |
|
|---|
| 60 |
This rule de-duplicates entry based on cached index (database). |
|---|
| 61 |
|
|---|
| 62 |
=head1 CONFIG |
|---|
| 63 |
|
|---|
| 64 |
=over 4 |
|---|
| 65 |
|
|---|
| 66 |
=item path |
|---|
| 67 |
|
|---|
| 68 |
Specified path to the database. This config is dependent for the |
|---|
| 69 |
DB_File backend. |
|---|
| 70 |
|
|---|
| 71 |
=item compare_body |
|---|
| 72 |
|
|---|
| 73 |
If set, this rule checks digest of entry, which is a MD5 hash of |
|---|
| 74 |
entry's title with body. Defaults to 0. |
|---|
| 75 |
|
|---|
| 76 |
=back |
|---|
| 77 |
|
|---|
| 78 |
=head1 AUTHOR |
|---|
| 79 |
|
|---|
| 80 |
Tatsuhiko Miyagawa |
|---|
| 81 |
|
|---|
| 82 |
Kazuhiro Osawa created Plagger::Plugin::Cache in early days, which |
|---|
| 83 |
gives me a base idea of this module. |
|---|
| 84 |
|
|---|
| 85 |
=head1 SEE ALSO |
|---|
| 86 |
|
|---|
| 87 |
L<Plagger>, L<DB_File> |
|---|
| 88 |
|
|---|
| 89 |
=cut |
|---|