NAME

HTML::LinkChanger::URLFilter - abstract class that can be subclassed to implement filters for HTML::LinkChanger.

SYNOPSIS

use HTML::LinkChanger; use HTML::LinkChanger::Absolutizer; use HTML::LinkChanger::URLFilter;

package MyFilter;

use vars qw($VERSION @ISA);

@ISA = qw(HTML::LinkChanger::URLFilter);

sub url_filter { my $self = shift; my %args = @_;

my $url = $args{url};   # url of the link
my $tag = $args{tag};   # tag containing a link to change
my $attr = $args{attr}; # attribute containing a link to change

# replacing URL with click counter
return 'http://www.mysite.com/counter?url='.$url;
}

package main;

# # make links absolute and then replace them with click counter URL # my $filter_chain = [ new HTML::LinkChanger::Absolutizer(base_url => 'http://www.google.com/'), new MyFilter() ];

my $changer = new HTML::LinkChanger(url_filters=>$filter_chain);

my $out = $changer->filter($in);

DESCRIPTION

HTML::LinkChanger::URLFilter can be subclassed to create a transforming class that can be used in HTML::LinkChanger to convert all URLs in the document.

Filters can be applied in any sequence and they get link url, tag name and attribute name as arguments so developer can base rewriting decisions based on them.

One of the examples of useful URL filter is HTML::LinkChanger::Absolutizer which replaces all relative URLs in HTML with absolute.

AUTHOR

Sergey Chernyshev <sergeyche@cpan.org>

SEE ALSO

HTML::LinkChanger, HTML::LinkChanger::Absolutizer