rsstootalizer/RSSTootalizer/Filter.pm

46 lines
763 B
Perl
Raw Normal View History

2017-04-22 18:49:49 +00:00
# vim: set foldmarker={,}:
use strict;
2017-04-23 18:51:48 +00:00
use RSSTootalizer::Base;
2017-04-22 18:49:49 +00:00
2017-04-23 18:51:48 +00:00
package RSSTootalizer::Filter;
@RSSTootalizer::Filter::ISA = qw(RSSTootalizer::Base);
2017-04-22 18:49:49 +00:00
use JSON;
use Data::Dumper;
use URI::Escape;
sub dbTable :lvalue { "filters"; }
sub orderBy :lvalue { "ID ASC"; }
# Class functions
# Object methods
sub apply {
my $self = shift;
my $entry = shift;
my $match = 1;
my $arg = $self->{data}->{field};
if ($arg eq "content"){
$arg = $entry->content()->body;
} else {
$arg = $entry->$arg();
}
my $regex = uri_unescape($self->{data}->{regex});
$regex =~ s,\\\\,\\,g;
if ($self->{data}->{match} eq "positive"){
if ($arg =~ /$regex/i){
return 1;
}
return 0;
} else {
if ($arg !~ /$regex/i){
return 1;
}
return 0;
}
return 0;
}
1;