Plagger/Plugin/Filter/Regexp.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 34 CC 3 SCAR 14.6
CC
3
Cov
0%
init
6.0
filter
6.0
BEGIN
2.0
CRAP 4.3
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__