NAME
WWW::Adblock - a simple implementation of Adblock Plus in Perl
SYNOPSIS
use WWW::Adblock;
my $adblock = WWW::Adblock->new();
$adblock->load('/path/to/filters.txt');
if ($adblock->filter('http://example.com/1x1.gif')) {
# it matched a filter rule
}
DESCRIPTION
This is a very simplified implementation of Adblock Plus (the popular browser extension) in Perl. Currently it only supports URI filtering and does not implement the per-element blocking offered by the extension.
Methods
new
my $adblock = WWW::Adblock->new();
my $adblock = WWW::Adblock->new( filters => $target );
Creates a new object. If $filters
is given it is passed to $adblock->load
.
load
$adblock->load('/path/to/rules.txt');
Loads and parses a ruleset. May be called multiple times, new rules are added to the existing ones.
filter
# Check a $uri
$adblock->filter($uri);
# Check a $uri that appeared on a page on $domain
$adblock->filter($uri, $domain);
Checks a URI to see whether it matches any rules. Returns 0 for no match, 1 for positive match, 2 for whitelist.
AUTHOR
The idea for this code comes from Adblock Plus. Find out more at http://adblockplus.org/en/.
Implementation in Perl by David Cannings <david@edeca.net>
COPYRIGHT / LICENSE
Copyright (c) 2010 David Cannings. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.