WWW::Adblock - a simple implementation of Adblock Plus in Perl
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 }
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.
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.
$filters
$adblock->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.
# 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.
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 (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.
To install WWW::Adblock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Adblock
CPAN shell
perl -MCPAN -e shell install WWW::Adblock
For more information on module installation, please visit the detailed CPAN module installation guide.