View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Sergey Chernyshev > HTML-LinkChanger > HTML::LinkChanger::URLFilter



Annotate this POD

View/Report Bugs
Module Version: 2.4   Source  


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


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 ''.$url;

package main;

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

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

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


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.


Sergey Chernyshev <>


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

syntax highlighting: