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)!
$1!g;
\$_;
}
1;
__END__
=head1 NAME
Template::Semantic::Filter - Template::Semantic Defined filters
=head1 FILTERS
=head2 chomp
$ts->process($template, {
'h1' => [ "foo\n", 'chomp' ], # =>
foo & foo
# bar