HTML::Seamstress::Quickstart 4.26 review

Download
by rbytes.net on

HTML::Seamstress::Quickstart is a gentle introduction to HTML::Seamstress. Introduction This guide is designed to get you start

License: Perl Artistic License
File size: 47K
Developer: Terrence Brannon
0 stars award from rbytes.net

HTML::Seamstress::Quickstart is a gentle introduction to HTML::Seamstress.

Introduction

This guide is designed to get you started with dynamically generating and modifying ("templating") HTML with HTML::Seamstress.

We will work through several examples, with each one increasing your ability to work with Seamstress effectively.

Sample files

All the files for the samples are in the directory lib/HTML/Seamstress/Quickstart

Pure TreeBuilder

Welcome to the first example. This is our bare-bones example. Let's say we want to dynamically modify the following HTML:

< html >

< head >
< title >Greetings< /title >
< /head >

< body >

< h1 >Greetings< /h1 >

Hello there < span id=name >person< /span >, your lucky number is
< span id=lucky_number >666< /span >

< /body >

< /html >

Let's not use Seamstress at all in this case. Remember Seamstress just makes using HTML::Tree more convenient when writing software - it is completely optional and totally non-magical. So here's the (admittedly verbose) pure TreeBuilder solution:

use strict;
use warnings;

use HTML::TreeBuilder;

my $name = 'Redd Foxx';
my $number = 887;

my $tree = HTML::TreeBuilder->new_from_file('html/greeting.html');

my $name_elem = $tree->look_down(id => 'name');
$name_elem->delete_content;
$name_elem->push_content($name);

my $number_elem = $tree->look_down(id => 'lucky_number');
$number_elem->delete_content;
$number_elem->push_content($number);


print $tree->as_HTML(undef, ' ');

There's a convenience function in HTML::Element::Library which makes it easy to replace all the content of an element. This will make our script shorter. If we simply use Seamstress, its new_from_file() method will bless the HTML tree into a class which inherits from HTML::Element::Library, making it easy for us to shorten our program. So let's rework the example using bare-bones Seamstress.

Requirements:
Perl

HTML::Seamstress::Quickstart 4.26 search tags