Template::HTML::Context - A replacement for Template::Context that wraps filters


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

Index


Code Index:

NAME

Top

Template::HTML::Context - A replacement for Template::Context that wraps filters

SYNOPSIS

Top

  use Template::HTML;

  my $config = {
      # See Template.pm
  };

  my $template = Template::HTML->new($config);

  my $vars = {
      var1  => $value,
      var2  => \%hash,
      var3  => \@list,
      var4  => \&code,
      var5  => $object,
  };

  # specify input filename, or file handle, text reference, etc.
  my $input = 'myfile.html';

  # process input template, substituting variables
  $template->process($input, $vars)
      || die $template->error();

DESCRIPTION

Top

This is a subclass of Template::Context (the Template Toolkit context module). It wraps all filter calls to ensure that the automatic HTML encoding behaves correctly when other filters are applied.

An extra special filter called "none" is implemented here to "opt-out" of automatic encoding.

SEE ALSO

Top

http://git.dollyfish.net.nz/?p=Template-HTML

FUNCTIONS

Top

filter()

An overridden function from Template::Context that wraps filters to ensure the automatic HTML encoding works correctly.

AUTHOR

Top

Martyn Smith, <msmith@cpan.org>

COPYTIGHT AND LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.


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

package Template::HTML::Context;

use strict;
use warnings;
use Scalar::Util qw(blessed);
use base qw(Template::Context);

sub filter {
    my $self = shift;
    my ($name, $args, $alias) = @_;

    if ( $name eq 'none' ) {
        return sub {
            my $value = shift;
            return $value->plain if blessed($value) and $value->isa('Template::HTML::Variable');
            return $value;
        };
    }

    my $filter = $self->SUPER::filter(@_);

    return sub {
        my $value = shift;

        if ( ref $value eq 'Template::HTML::Variable' ) {
            return ref($value)->new($filter->($value->plain));
        }

        return $filter->($value);
    };
}

1;
__END__