added the other example to synopsis.t
Rok Ružič [Tue, 27 Apr 2010 00:17:24 +0000 (02:17 +0200)]
lib/HTML/Zoom.pm
maint/synopsis-extractor

index dac8bd7..1e078ef 100644 (file)
@@ -204,7 +204,7 @@ will produce:
 =begin testinfo
 
   HTML
-  is($output, $expect, 'Synopsis code works ok');
+  is($output, $expect, 'Synopsis example #1 ok');
 
 =end testinfo
 
@@ -271,11 +271,26 @@ and despaired of the fact that neither the HTML structure nor the logic are
 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 {
 
@@ -293,6 +308,23 @@ cleanly:
 
     } } @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
index 7c72d5b..e0341a9 100755 (executable)
@@ -7,7 +7,9 @@ my $from = do { local (@ARGV, $/) = ('lib/HTML/Zoom.pm'); <> };
 
 $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;