=begin testinfo
HTML
- is($output, $expect, 'Synopsis code works ok');
+ is($output, $expect, 'Synopsis example #1 ok');
=end testinfo
remotely easy to read? Fortunately, with HTML::Zoom we can separate the two
cleanly:
+=begin testinfo
+ my $html = <<HTML;
+=end testinfo
<form class="myform" action="/somewhere">
<label />
<input />
</form>
+=begin testinfo
+ HTML
+ my $zoom = HTML::Zoom->from_html($html);
+ my @fields = ({id => 'email', label=> 'Please enter your email',
+ name => 'email', type => 'text', value => 'replace this text'},
+ {id => 'username', label=> 'Please enter your username',
+ name => 'username', type => 'text', value => ''},
+ {id => 'password', label=> 'Please enter your password',
+ name => 'password', type => 'password', value => ''});
+
+ $zoom =
+=end testinfo
$zoom->select('.myform')->repeat_content([
map { my $field = $_; sub {
} } @fields
]);
+=begin testinfo
+ $output = $zoom->to_html;
+ $expect = <<HTML;
+ <form class="myform" action="/somewhere">
+ <label for="email">Please enter your email</label>
+ <input name="email" type="text" value="replace this text" />
+
+ <label for="username">Please enter your username</label>
+ <input name="username" type="text" value="" />
+
+ <label for="password">Please enter your password</label>
+ <input name="password" type="password" value="" />
+ </form>
+ HTML
+
+ is($output, $expect, 'Synopsis example #2 ok');
+=end testinfo
This is, admittedly, very much not shorter. However, it makes it extremely
clear what's happening and therefore less hassle to maintain. Especially
$from =~ s/.*^=head1 SYNOPSIS\n//sm;
-$from =~ s/^=head1.*//sm;
+$from =~ s/^=head1.*\ncleanly:\n//sm;
+
+$from =~ s/^This is, admittedly, very much not shorter\..*//sm;
my $code = join "\n", map { s/^ // ? ($_) : () } split "\n", $from;