Template::Semantic::Filter - Template::Semantic Defined filters


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

Index


Code Index:

NAME

Top

Template::Semantic::Filter - Template::Semantic Defined filters

FILTERS

Top

chomp

  $ts->process($template, {
      'h1' => [ "foo\n", 'chomp' ], # => <h1>foo</h1>
  })

trim

  $ts->process($template, {
      'h1' => [ " foo ", 'trim' ], # => <h1>foo</h1>
  })

sort

  $ts->process($template, {
      'h1@class' => [ "zzz xxx yyy", 'sort' ], # => <h1 class="xxx yyy zzz">foo</h1>
  })

uniq

  $ts->process($template, {
      'h1@chass' => [ "foo bar foo", 'uniq' ], # => <h1 class="foo bar">foo</h1>
  })

comma

  $ts->process($template, {
      'h1' => [ "10000", 'comma' ], # => <h1>10,000</h1>
  })

codes from: Template::Plugin::Comma.

html_line_break

  $ts->process($template, {
      'p' => [ "foo & foo\nbar\n", 'html_line_break' ],
      # =>
      # <p>foo &amp; foo<br />
      # bar <br /></p>
  })

codes from: Template::Filters::html_line_break().

SEE ALSO

Top

Template::Semantic

AUTHOR

Top

Naoki Tomita <tomita@cpan.org>


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

package Template::Semantic::Filter;
use strict;
use warnings;
use base 'Exporter';

our @EXPORT_OK = qw(
    chomp
    trim
    sort
    uniq
    comma
    html_line_break
);

sub chomp {
    chomp;
    $_;
}

sub trim {
    s/^ *| *$//g;
    $_;
}

sub sort {
    join " ", sort split /\s+/;
}

sub uniq {
    my %h;
    join " ", map { $h{$_}++ == 0 ? $_ : () } split /\s+/;
}

sub comma {
   1 while s/((?:\A|[^.0-9])[-+]?\d+)(\d{3})/$1,$2/s;
   $_;
}

sub html_line_break {
    s!(\r?\n)!<br />$1!g;
    \$_;
}

1;
__END__