| Template-Semantic documentation | Contained in the Template-Semantic distribution. |
Template::Semantic::Filter - Template::Semantic Defined filters
$ts->process($template, {
'h1' => [ "foo\n", 'chomp' ], # => <h1>foo</h1>
})
$ts->process($template, {
'h1' => [ " foo ", 'trim' ], # => <h1>foo</h1>
})
$ts->process($template, {
'h1@class' => [ "zzz xxx yyy", 'sort' ], # => <h1 class="xxx yyy zzz">foo</h1>
})
$ts->process($template, {
'h1@chass' => [ "foo bar foo", 'uniq' ], # => <h1 class="foo bar">foo</h1>
})
$ts->process($template, {
'h1' => [ "10000", 'comma' ], # => <h1>10,000</h1>
})
codes from: Template::Plugin::Comma.
$ts->process($template, {
'p' => [ "foo & foo\nbar\n", 'html_line_break' ],
# =>
# <p>foo & foo<br />
# bar <br /></p>
})
codes from: Template::Filters::html_line_break().
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__