Plagger::Plugin::Filter::Regexp - Rewrite entry body using regular expression


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::Filter::Regexp - Rewrite entry body using regular expression

SYNOPSIS

Top

  - module: Filter::Regexp
    config:
      regexp: s/Plagger/$1, the pluggable Aggregator/g
      text_only: 1

DESCRIPTION

Top

This plugin applies regular expression to each entry body by using eval.

CONFIG

Top

text_only

When set to 1, uses HTML::Parser so that the regexp substitution should be applied only to HTML text part. Defaults to 0.

AUTHOR

Top

Tatsuhiko Miyagawa

SEE ALSO

Top

Plagger, HTML::Parser


Plagger documentation Contained in the Plagger distribution.

package Plagger::Plugin::Filter::Regexp;
use strict;
use base qw( Plagger::Plugin::Filter::Base );
use Encode;

sub init {
    my $self = shift;
    $self->SUPER::init(@_);

    unless ($self->conf->{regexp}) {
        Plagger->context->error("regexp is missing");
        return;
    }
}

sub filter {
    my($self, $body) = @_;

    local $_ = $body;
    my $regexp = decode_utf8($self->conf->{regexp}, Encode::FB_CROAK);
    my $count = eval $regexp;

    if ($@) {
        Plagger->context->log(error => "Error: $@ in " . $self->conf->{regexp});
        return (0, $body);
    }

    return ($count, $_);
}

1;

__END__