started to fill out the set_attribute stub
John Napiorkowski [Thu, 30 Sep 2010 02:34:12 +0000 (22:34 -0400)]
lib/HTML/Zoom/FilterBuilder.pm
t/synopsis/filterbuilder.t

index 7b0eea0..58237ca 100644 (file)
@@ -303,18 +303,22 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream
       ->from_html(<<BODY);
   <div id="stuff">
       <p>Well Now</p>
-      <p>Is the Time</p>
+      <p id="p2">Is the Time</p>
   </div>
   BODY
 
   my $output =  $root
-  ->select('title')
-  ->replace_content('Hello World')
-  ->select('body')
-  ->replace_content($body)
-  ->select('p')
-  ->set_attribute(class=>'para')
-  ->to_html;
+    ->select('title')
+    ->replace_content('Hello World')
+    ->select('body')
+    ->replace_content($body)
+    ->then
+    ->set_attribute(class=>'main')
+    ->select('p')
+    ->set_attribute(class=>'para')
+    ->select('#p2')
+    ->set_attribute(class=>'para2')
+    ->to_html;
 
 will produce:
 
@@ -328,9 +332,9 @@ will produce:
     <head>
       <title>Hello World</title>
     </head>
-    <body><div id="stuff">
+    <body class="main"><div id="stuff">
       <p class="para">Well Now</p>
-      <p class="para">Is the Time</p>
+      <p id="p2" class="para2">Is the Time</p>
   </div>
   </body>
   </html>
@@ -353,7 +357,17 @@ This class defines the following public API
 
 =head2 set_attribute
 
-    TBD
+Sets an attribute of a given name to a given value for all matching selections.
+
+    $html_zoom
+      ->select('p')
+      ->set_attribute(class=>'paragraph')
+      ->select('div')
+      ->set_attribute(name=>'class', value=>'divider')
+
+Overrides existing values, if such exist.  When multiple L</set_attribute>
+calls are made against the same or overlapping selection sets, the final
+call wins.
 
 =head2 add_to_attribute
 
index 59048ae..9fc9f41 100644 (file)
@@ -19,18 +19,22 @@ my $body = HTML::Zoom
     ->from_html(<<BODY);
 <div id="stuff">
     <p>Well Now</p>
-    <p>Is the Time</p>
+    <p id="p2">Is the Time</p>
 </div>
 BODY
 
 my $output =  $root
-->select('title')
-->replace_content('Hello World')
-->select('body')
-->replace_content($body)
-->select('p')
-->set_attribute(class=>'para')
-->to_html;
+  ->select('title')
+  ->replace_content('Hello World')
+  ->select('body')
+  ->replace_content($body)
+  ->then
+  ->set_attribute(class=>'main')
+  ->select('p')
+  ->set_attribute(class=>'para')
+  ->select('#p2')
+  ->set_attribute(class=>'para2')
+  ->to_html;
 
 
 my $expect = <<HTML;
@@ -38,9 +42,9 @@ my $expect = <<HTML;
   <head>
     <title>Hello World</title>
   </head>
-  <body><div id="stuff">
+  <body class="main"><div id="stuff">
     <p class="para">Well Now</p>
-    <p class="para">Is the Time</p>
+    <p id="p2" class="para2">Is the Time</p>
 </div>
 </body>
 </html>