CGI::AppToolkit::Template::Filter - A superclass for CGI::AppToolkit::Template filters


CGI::AppToolkit::Template::Filter is intended for subclassing and overriding it's filter() method.

filter() is called as an object with two parameters. The first parameter (after the object reference) is a hashref of the arguments specified in the calling template. The second parameter is the value to be 'filtered.'

Provided Filters

In addition to being able to write your own filters easily, CGI::AppToolkit comes with several filters:

BR - Adds <BR> tags (or the first parameter passed) to the end of every line.
HTML - Escapes HTML entities into their &whatever; form.
URL - Escapes the given text for safe use in URLs. If the first parameter is passed as non-zero then spaces are translated to pluses (+) instead of %20.
Money - Reformats numbers as 'money.' The first parameter is a sprintf() format. It defaults to %.2f. (NOTE: This can be used as a general sprintf() filter.)
Abs - Calls abs() in the given number, making it positive. If the first parameter is true, then it makes it negative.


This is the complete code of CGI::AppToolkit::Template::Filter::BR.

  package CGI::AppToolkit::Template::Filter::BR;
  $VERSION = '0.05';
  require 5.004;
  use Carp;
  use base 'CGI::AppToolkit::Template::Filter';
  use strict;
  sub filter {
    my $self = shift;
    my $args = shift;
    my $text = shift;
    my $br = ref $args && @$args ? $args->[0] : '<br>';
    $text =~ s/(\r?\n)/$br\1/g;