added some docs to each test point as a start to the eventual pod docs and to help...
John Napiorkowski [Tue, 5 Apr 2011 16:54:54 +0000 (12:54 -0400)]
t/fill.t

index 715fc7d..5fbfbe9 100644 (file)
--- a/t/fill.t
+++ b/t/fill.t
@@ -212,6 +212,9 @@ sub code_stream (&) {
       });
     });
   };
+
+  ## fill a selection from an array of targets, using a list.  Syntax is a bit
+  ## like DBIC->populate
   
   {
     ok my $z = HTML::Zoom
@@ -229,7 +232,8 @@ sub code_stream (&) {
       'Got correct from repeat_content'
     );  
   }
-  
+  ## Same as above but using an iterator coderef instead of a pregenerated list 
   {
     my @items = ( [0,1], [2,3] );
     ok my $z = HTML::Zoom
@@ -252,6 +256,9 @@ sub code_stream (&) {
       );
     }
   }
+
+  ## Target has a value of a coderef that is expected to take the item from the
+  ## list of data and provide the actual value that goes into the target
   
   {
     ok my $z = HTML::Zoom
@@ -274,6 +281,9 @@ sub code_stream (&) {
       );
     }
   }
+
+  ## Like above but showing how this can be used to get a value from any type of
+  ## list item.
   
   {
     ok my $z = HTML::Zoom
@@ -323,6 +333,9 @@ sub code_stream (&) {
       );
     }
   }
+
+  ## Just an example of above showing off how you can use Perl to generate the
+  ## needed structures.
   
   {
     ok my $even_or_odd = sub {
@@ -349,6 +362,8 @@ sub code_stream (&) {
       );
     }
   }
+
+  ## using a list of objects, we get replace values.
   
   {
     {
@@ -388,6 +403,9 @@ sub code_stream (&) {
     }
   }
 
+  ## Looks a lot like how pure.js uses 'directives' to map a selector to a value
+  ## from each item in the data list.
+  
   {
     ok my $z = HTML::Zoom
       ->from_html(q[<ul><li class="even">Even</li><li class="odd">Odd</li></ul>])
@@ -432,6 +450,10 @@ sub code_stream (&) {
     }
   }
 
+  ## Ideally the targets are an array so that you properly control the order that
+  ## the replaces happen, but if you don't care you can take advantage of the
+  ## shorthand target structure of a hashref
+  
   {
     ok my $z = HTML::Zoom
       ->from_html(q[<ul><li class="even">Even</li><li class="odd">Odd</li></ul>])
@@ -498,6 +520,29 @@ sub code_stream (&) {
       );
     }
   }
+  
+  ## Using above shortcut with iterator instead of fixed list
+
+  {
+    my @list = (
+      Test::HTML::Zoom::EvenOdd->new(0,1),
+      Test::HTML::Zoom::EvenOdd->new(2,3),         
+    );
+    
+    ok my $z = HTML::Zoom
+      ->from_html(q[<ul><li class="even">Even</li><li class="odd">Odd</li></ul>])
+      ->select('ul')
+      ->$fill(
+        [qw(even odd)],
+        sub { shift @list },       
+      ), 'Made Zoom object from declare accessors style';
+
+    is(
+      $z->to_html,
+      '<ul><li class="even">0</li><li class="odd">1</li><li class="even">2</li><li class="odd">3</li></ul>',
+      'Got correct from repeat_content',
+    );
+  }
 }
 
 done_testing;