Template::Plugin::XML::Escape - Escape variables to suit being placed into XML


Template-Plugin-XML-Escape documentation Contained in the Template-Plugin-XML-Escape distribution.

Index


Code Index:

NAME

Top

Template::Plugin::XML::Escape - Escape variables to suit being placed into XML

SYNOPSIS

Top

  [% USE XML.Escape %]
  ...
  <foo bar="[% c.variable | xml_escape %]" />

DESCRIPTION

Top

Escapes XML entities from text, so that you don't fall prey to people putting quotes, less-than/greater-than, and ampersands, into variables that end up in TT templates.

SEE ALSO

Top

 * Template Toolkit

AUTHOR

Top

Toby Corkindale, <cpan@corkindale.net>

COPYRIGHT AND LICENSE

Top


Template-Plugin-XML-Escape documentation Contained in the Template-Plugin-XML-Escape distribution.

package Template::Plugin::XML::Escape;
# $Id$

use 5.006001;
use strict;
use warnings;
use Template::Plugin::Filter;
use base 'Template::Plugin::Filter';

our $VERSION = '0.02';

our $NAME = 'xml_escape';

sub init {
    my $self = shift;
    $self->install_filter($self->{_ARGS}->[0] || $NAME);

    return $self;
}

sub filter {
    my ($self, $text, undef, $config) = @_;
    $text =~ s/&/&amp;/go;
    $text =~ s/</&lt;/go;
    $text =~ s/>/&gt;/go;
    $text =~ s/'/&apos;/go;
    $text =~ s/"/&quot;/go;
    return $text;
}

1;
__END__