エントリの重複チェックを行う Rule::Deduped のサブクラス。Store::DBIC で保存した entry から検索するもの。
Store::DBIC を愛用しているので、僭越ながら書いてみました。
- module: Filter::Rule
rule:
module: Deduped
engine: DBIC
- module: Store::DBIC
config:
schema_class: Plagger::Schema::SQLite
connect_info: [ 'dbi:SQLite:/path/to/plagger.db', ]
ソースはこんなので。
[追記] MD5 求めるところが間違ってた。とりあえず Plagger::Entry からコピペしたが…
package Plagger::Rule::Deduped::DBIC;
use strict;
use base qw( Plagger::Rule::Deduped::Base );
use Plagger::Plugin::Store::DBIC;
sub find_entry {
my($self, $url) = @_;
my $c = Plagger->context;
unless($self->{db}){
my $plugins = $c->{plugins};
my ($db) = grep { $_->isa('Plagger::Plugin::Store::DBIC') } @$plugins;
return unless $db;
$self->{db} = $db;
}
my $entry = $self->{db}->schema->resultset('Entry')->find({
link => $url,
});
if($entry){
# XXX see Plagger::Entry::digest
my $data = $entry->title . ($entry->body || '');
Encode::_utf8_off($data);
return Digest::MD5::md5_hex($data);
}
$c->log( debug => "not found." );
return;
}
sub create_entry {
my($self, $url, $digest) = @_;
Plagger->context->log( debug => "$url stored later by Store::DBIC" );
1;
}
1;