* disappears
},
'div.foo a' => undef, # same as above
});
Loop
* selector => [ \%row, \%row, ... ]
*Array-ref of Hash-refs:* Loop the part as template. Each item of
the array-ref should be hash-ref.
$ts->process(\*DATA, {
'table.list tr' => [
{ 'th' => 'aaa', 'td' => '001' },
{ 'th' => 'bbb', 'td' => '002' },
{ 'th' => 'ccc', 'td' => '003' },
],
});
__DATA__
Output:
Filter
* selector => [ $value, filter, filter, ... ]
*Array-ref of Scalars:* Value and filters. Filter can take
A) Callback subroutine
B) Defined filter name
C) Object like Text::Pipe ("it->can('filter')")
$ts->process($template, {
'h1' => [ 'foo', sub { uc }, sub { "$_!" } ], # =>
FOO!
'h2' => [ ' foo ', 'trim', sub { "$_!" } ], # =>
FOO!
'h3' => [ 'foo', PIPE('UppercaseFirst') ], # =>
Foo
});
Defined basic filters
Some basic filters included. See Template::Semantic::Filter.
$ts->define_filter($filter_name, \&code)
You can define the your filter name using "define_filter()".
use Text::Markdown qw/markdown/;
$ts->define_filter(markdown => sub { \ markdown($_) })
$ts->process($template, {
'div.content' => [ $text, 'markdown' ],
});
$code = $ts->call_filter($filter_name)
Accessor to defined filter.
$ts->process($template, {
'div.entry' => ...,
'div.entry-more' => ...,
})->process({
'div.entry, div.entry-more' => $ts->call_filter('markdown'),
});
SEE ALSO
Template::Semantic::Cookbook
XML::LibXML, HTML::Selector::XPath
I got a lot of ideas from Template, Template::Refine, Web::Scraper.
thanks!
AUTHOR
Naoki Tomita
Feedback, patches, POD English check are always welcome!
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.