|
Revision 78
(checked in by miyagawa, 3 years ago)
|
- Reverted hooks method on rules.
- Added rule_hook to Plugin, which is the only point where rule can control. Refs #22
|
| Line | |
|---|
| 1 |
package Plagger::Rule::FeedType; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Rule ); |
|---|
| 4 |
|
|---|
| 5 |
use Plagger::Operator; |
|---|
| 6 |
|
|---|
| 7 |
sub init { |
|---|
| 8 |
my $self = shift; |
|---|
| 9 |
|
|---|
| 10 |
if (my $type = $self->{type}) { |
|---|
| 11 |
$type = [ $type ] if ref($type) ne 'ARRAY'; |
|---|
| 12 |
$self->{type} = $type; |
|---|
| 13 |
} else { |
|---|
| 14 |
Plagger->context->error("Can't parse type"); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
$self->{op} ||= 'OR'; |
|---|
| 18 |
unless (Plagger::Operator->is_valid_op($self->{op})) { |
|---|
| 19 |
Plagger->context->error("Unsupported operator $self->{op}"); |
|---|
| 20 |
} |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
sub dispatch { |
|---|
| 24 |
my($self, $args) = @_; |
|---|
| 25 |
|
|---|
| 26 |
my $feed = $args->{feed} |
|---|
| 27 |
or Plagger->context->error("No feed object in this plugin phase"); |
|---|
| 28 |
|
|---|
| 29 |
my @bool; |
|---|
| 30 |
for my $want (@{$self->{type}}) { |
|---|
| 31 |
push @bool, ($feed->type eq $want); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
Plagger::Operator->call($self->{op}, @bool); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
1; |
|---|