HTML::Template::Filter::URIdecode - Allow tmpl_ tags to be URL-encoded.


HTML-Template-Filter-URIdecode documentation Contained in the HTML-Template-Filter-URIdecode distribution.

Index


Code Index:

NAME

Top

HTML::Template::Filter::URIdecode - Allow tmpl_ tags to be URL-encoded.

SYNOPSIS

Top

  use HTML::Template::Filter::URIdecode 'ht_uri_decode';

  my $t = HTML::Template->new(
    filename => 'zap.tmpl',
    filter   => \&ht_uri_decode
 );

DESCRIPTION

Top

This filter primarily does URI-decoding of HTML::Template <tmpl_...> tags. It was designed for use Dreamweaver. Sometimes a <tmpl_var> tag is used in a way that would be invalid HTML:

 <a href="<tmpl_var my_url>"></a>

Dreamweaver fixes the invalid HTML in this case by URL encoding it. Rather than fight it, I've used this filter for the last several years, and Dreamweavers practice of URL-encoding these tags has never been a problem since.

Dreamweaver may also automatically "fix" URLS like this by adding one or more "../" in front of the <tmpl_var_> tag. This filter strips those as well.

AUTHOR

Top

    Mark Stosberg
    CPAN ID: MARKSTOS
    mark@summersault.com

COPYRIGHT

Top

SEE ALSO

Top

perl(1).

HTML::Template

CGI::Application - a elegant web framework which integrates with HTML::Template.


HTML-Template-Filter-URIdecode documentation Contained in the HTML-Template-Filter-URIdecode distribution.

package HTML::Template::Filter::URIdecode;
use strict;
use warnings;

BEGIN {
    use Exporter ();
    use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
    $VERSION     = '1.00';
    @ISA         = qw(Exporter);
    #Give a hoot don't pollute, do not export more than needed by default
    @EXPORT      = qw(&ht_uri_decode);
    @EXPORT_OK   = qw();
    %EXPORT_TAGS = ();
}

sub ht_uri_decode {
    my $text_ref = shift;
    require URI::Escape;
    import URI::Escape qw/uri_unescape/;
    # We also remove extra "../" that DW may put before a tmpl_var tag
$$text_ref =~ s!(?:\.\./)*%3C(?:%21--)?\s*[Tt][Mm][Pp][Ll]_[Vv][Aa][Rr]([^>]*?)(?:--)?%3E!'<TMPL_VAR'.uri_unescape($1).'>'!ge;
}

1; # The preceding line will help the module return a true value