Template::Extract
I ran across the Template::Extract module while reading Spidering Hacks on the O’Reilly Hacks site and realized that I may have found the tool I need to migrate sites from Dreamweaver sites to a CMS backed system such as OpenACS (in as lazy a way as possible). What’s needed is really simple – just need to “balance the tags”.
With zero ado, here’s the simple test case I wrote that works quite nicely. Hope it forms a basis for a good project for someone else because none of the other samples I found on the web worked out of the box.
#!/usr/bin/perl -T
use Template::Extract;
use Data::Dumper;
use LWP::Simple qw(get);my $obj = Template::Extract->new;
my $template = < < '.';
[% ... %]<!-- #BeginTemplate "[% Template %]" -->[% ... %]
[% FOREACH editable %]
[% ... %]
<!– #BeginEditable “[% regionname %]” –>
[% ... %]
<!– #EndEditable –>
[% END %]
[% ... %]
<!– #EndTemplate –>
[% ... %]
.# – Network version
my $document = get “http://www.cmbs.org/career_main.htm” or die “Can’t get page”;# – Filesystem version
#open INPUT, “;
#close INPUT;#print Dumper @document;
print Data::Dumper::Dumper( $obj->extract($template, $document));
Here is some example output:
$VAR1 = {
‘editable’ => [
{
'regionname' => 'doctitle'
},
{
'regionname' => 'topnav'
},
{
'regionname' => 'subtitle'
},
{
'regionname' => 'body'
}
],
‘Template’ => ‘/Templates/final.dwt’
};