|
Revision 1025
(checked in by miyagawa, 3 years ago)
|
Rule::Deduped: Use entry's datetime as key if there's any. Fixes #312
|
| Line | |
|---|
| 1 |
package Plagger::Rule::Deduped::Base; |
|---|
| 2 |
use strict; |
|---|
| 3 |
|
|---|
| 4 |
sub new { |
|---|
| 5 |
my($class, $rule) = @_; |
|---|
| 6 |
|
|---|
| 7 |
my $self = bless { |
|---|
| 8 |
compare_body => $rule->{compare_body} || 0, |
|---|
| 9 |
}, $class; |
|---|
| 10 |
$self->init($rule); |
|---|
| 11 |
|
|---|
| 12 |
$self; |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
sub init { } |
|---|
| 16 |
|
|---|
| 17 |
sub id_for { |
|---|
| 18 |
my($self, $entry) = @_; |
|---|
| 19 |
|
|---|
| 20 |
if ($entry->date) { |
|---|
| 21 |
return join ":", $entry->permalink, $entry->date; |
|---|
| 22 |
} else { |
|---|
| 23 |
return $entry->permalink; |
|---|
| 24 |
} |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
sub is_new { |
|---|
| 28 |
my($self, $entry) = @_; |
|---|
| 29 |
|
|---|
| 30 |
my $exists = $self->find_entry( $self->id_for($entry) ) or return 1; |
|---|
| 31 |
|
|---|
| 32 |
if ($self->{compare_body}) { |
|---|
| 33 |
return $exists ne $entry->digest; |
|---|
| 34 |
} else { |
|---|
| 35 |
return 0; |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
sub add { |
|---|
| 40 |
my($self, $entry) = @_; |
|---|
| 41 |
$self->create_entry( $self->id_for($entry), $entry->digest ); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
sub find_entry { } |
|---|
| 45 |
sub create_entry { } |
|---|
| 46 |
|
|---|
| 47 |
1; |
|---|