=head1 SYNOPSIS
- use HTML::Zoom;
- my $root = HTML::Zoom
- ->from_html(<<MAIN);
- <html>
- <head>
- <title>Default Title</title>
- </head>
- <body>
- Default Content
- </body>
- </html>
- MAIN
-
- my $body = HTML::Zoom
- ->from_html(<<BODY);
- <div id="stuff">
- <p>Stuff</p>
- <p id="p1">Stuff</p>
- </div>
- BODY
-
- print $root
- ->select('title')
- ->replace_content('Hello World')
- ->select('body')
- ->replace_content($body)
- ->select('#p1')
- ->replace_content(sub {
- ## Ask mst...
-
- })
- ->to_html;
-
+ use HTML::Zoom;
+ my $root = HTML::Zoom
+ ->from_html(<<MAIN);
+ <html>
+ <head>
+ <title>Default Title</title>
+ </head>
+ <body>
+ Default Content
+ </body>
+ </html>
+ MAIN
+
+ my $body = HTML::Zoom
+ ->from_html(<<BODY);
+ <div id="stuff">
+ <p>Stuff</p>
+ </div>
+ BODY
+
+ my $output = $root
+ ->select('title')
+ ->replace_content('Hello World')
+ ->select('body')
+ ->replace_content($body)
+ ->to_html;
+
+will produce:
+
+=begin testinfo
+
+ my $expect = <<HTML;
+
+=end testinfo
+
+ <html>
+ <head>
+ <title>Hello World</title>
+ </head>
+ <body><div id="stuff">
+ <p>Stuff</p>
+ </div>
+ </body>
+ </html>
+
+=begin testinfo
+
+ HTML
+ is($output, $expect, 'Synopsis code works ok');
+
+=end testinfo
=head1 DESCRIPTION
--- /dev/null
+use strict;
+use warnings FATAL => 'all';
+use Test::More qw(no_plan);
+
+use HTML::Zoom;
+my $root = HTML::Zoom
+ ->from_html(<<MAIN);
+<html>
+ <head>
+ <title>Default Title</title>
+ </head>
+ <body>
+ Default Content
+ </body>
+</html>
+MAIN
+
+my $body = HTML::Zoom
+ ->from_html(<<BODY);
+<div id="stuff">
+ <p>Stuff</p>
+</div>
+BODY
+
+my $output = $root
+->select('title')
+->replace_content('Hello World')
+->select('body')
+->replace_content($body)
+->to_html;
+
+
+my $expect = <<HTML;
+<html>
+ <head>
+ <title>Hello World</title>
+ </head>
+ <body><div id="stuff">
+ <p>Stuff</p>
+</div>
+</body>
+</html>
+HTML
+is($output, $expect, 'Synopsis code works ok');
+
--- /dev/null
+use strict;
+use warnings FATAL => 'all';
+use Test::More qw(no_plan);
+
+use HTML::Zoom;
+
+my $template = <<HTML;
+<html>
+ <head>
+ <title>Hello people</title>
+ </head>
+ <body>
+ <h1 id="greeting">Placeholder</h1>
+ <div id="list">
+ <span>
+ <p>Name: <span class="name">Bob</span></p>
+ <p>Age: <span class="age">23</span></p>
+ </span>
+ <hr class="between" />
+ </div>
+ </body>
+</html>
+HTML
+
+my $output = HTML::Zoom
+ ->from_html($template)
+ ->select('title, #greeting')->replace_content('Hello world & dog!')
+ ->select('#list')->repeat_content(
+ [
+ sub {
+ $_->select('.name')->replace_content('Matt')
+ ->select('.age')->replace_content('26')
+ },
+ sub {
+ $_->select('.name')->replace_content('Mark')
+ ->select('.age')->replace_content('0x29')
+ },
+ sub {
+ $_->select('.name')->replace_content('Epitaph')
+ ->select('.age')->replace_content('<redacted>')
+ },
+ ],
+ { repeat_between => '.between' }
+ )
+ ->to_html;
+
+
+my $expect = <<HTML;
+<html>
+ <head>
+ <title>Hello world & dog!</title>
+ </head>
+ <body>
+ <h1 id="greeting">Hello world & dog!</h1>
+ <div id="list">
+ <span>
+ <p>Name: <span class="name">Matt</span></p>
+ <p>Age: <span class="age">26</span></p>
+ </span>
+ <hr class="between" />
+ <span>
+ <p>Name: <span class="name">Mark</span></p>
+ <p>Age: <span class="age">0x29</span></p>
+ </span>
+ <hr class="between" />
+ <span>
+ <p>Name: <span class="name">Epitaph</span></p>
+ <p>Age: <span class="age"><redacted></span></p>
+ </span>
+
+ </div>
+ </body>
+</html>
+HTML
+is($output, $expect, 'Synopsis code works ok');
+