From: John Napiorkowski Date: Thu, 30 Sep 2010 02:34:12 +0000 (-0400) Subject: started to fill out the set_attribute stub X-Git-Tag: release_0.009004~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=f8ad684db84b3770391673ec6e740db8e8d2f994 started to fill out the set_attribute stub --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 7b0eea0..58237ca 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -303,18 +303,22 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream ->from_html(<

Well Now

-

Is the Time

+

Is the Time

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: Hello World -
+

Well Now

-

Is the Time

+

Is the Time

@@ -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 +calls are made against the same or overlapping selection sets, the final +call wins. =head2 add_to_attribute diff --git a/t/synopsis/filterbuilder.t b/t/synopsis/filterbuilder.t index 59048ae..9fc9f41 100644 --- a/t/synopsis/filterbuilder.t +++ b/t/synopsis/filterbuilder.t @@ -19,18 +19,22 @@ my $body = HTML::Zoom ->from_html(<

Well Now

-

Is the Time

+

Is the Time

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 = < Hello World -
+

Well Now

-

Is the Time

+

Is the Time