| 1 | package Plagger::Plugin::Filter::Regexp; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin::Filter::Base ); | ||
| 4 | use Encode; | ||
| 5 | |||
| 6 | sub init { | ||
| 7 | my $self = shift; | ||
| 8 | $self->SUPER::init(@_); | ||
| 9 | |||
| 10 | unless ($self->conf->{regexp}) { | ||
| 11 | Plagger->context->error("regexp is missing"); | ||
| 12 | return; | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | sub filter { | ||
| 17 | my($self, $body) = @_; | ||
| 18 | |||
| 19 | local $_ = $body; | ||
| 20 | my $regexp = decode_utf8($self->conf->{regexp}, Encode::FB_CROAK); | ||
| 21 | my $count = eval $regexp; | ||
| 22 | |||
| 23 | if ($@) { | ||
| 24 | Plagger->context->log(error => "Error: $@ in " . $self->conf->{regexp}); | ||
| 25 | return (0, $body); | ||
| 26 | } | ||
| 27 | |||
| 28 | return ($count, $_); | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; | ||
| 32 | |||
| 33 | __END__ |