Guest User

Untitled

a guest
Jul 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm
  2. index 50398b3..809e267 100644
  3. --- a/lib/HTML/Zoom/FilterBuilder.pm
  4. +++ b/lib/HTML/Zoom/FilterBuilder.pm
  5. @@ -381,7 +381,7 @@ alter the content of that stream.
  6.  
  7. This class defines the following public API
  8.  
  9. -=head2 set_attribute ( $attr=>value | {name=>$attr,value=>$value} )
  10. +=head2 set_attribute ( $attr=>$value | {name=>$attr,value=>$value} )
  11.  
  12. Sets an attribute of a given name to a given value for all matching selections.
  13.  
  14. @@ -396,7 +396,7 @@ Overrides existing values, if such exist. When multiple L</set_attribute>
  15. calls are made against the same or overlapping selection sets, the final
  16. call wins.
  17.  
  18. -=head2 add_to_attribute ( $attr=>value | {name=>$attr,value=>$value} )
  19. +=head2 add_to_attribute ( $attr=>$value | {name=>$attr,value=>$value} )
  20.  
  21. Adds a value to an existing attribute, or creates one if the attribute does not
  22. yet exist.
  23. @@ -421,21 +421,101 @@ Removes an attribute and all its values.
  24.  
  25. Removes attributes from the original stream or events already added.
  26.  
  27. -=head2 collect
  28. +=head2 collect ( [options] )
  29.  
  30. - TBD
  31. +Collects and extracts results of L<HTML::Zoom/select>. It takes the following
  32. +optional common options as hash reference.
  33.  
  34. -=head2 collect_content
  35. +=over
  36.  
  37. - TBD
  38. +=item into [ARRAY REFERENCE]
  39.  
  40. -=head2 add_before
  41. +Where to save collected events (selected elements).
  42.  
  43. - TBD
  44. + $z1->select('#main-content')
  45. + ->collect({ into => \@body })
  46. + ->run;
  47. + $z2->select('#main-content')
  48. + ->replace(\@body)
  49. + ->memoize;
  50.  
  51. -=head2 add_after
  52. +=item filter [CODE]
  53.  
  54. - TBD
  55. +Run filter on collected elements (locally setting $_ to stream, and passing
  56. +stream as an argument to given code reference). Note that $_ is an alias to the
  57. +stream, so it can be used to modify stream.
  58. +
  59. + $z->select('.outer')
  60. + ->collect({
  61. + filter => sub { $_->select('.inner')->replace_content('bar!') },
  62. + passthrough => 1
  63. + })
  64. +
  65. +=item passthrough [BOOLEAN]
  66. +
  67. +Extract copy of elements; the stream is unchanged (it does not remove collected
  68. +elements).
  69. +
  70. + HTML::Zoom->from_html('<foo><bar /></foo>')
  71. + ->select('foo')
  72. + ->collect({ content => 1 })
  73. + ->to_html
  74. +
  75. +returns '<foo></foo>', while with C<passthrough>
  76. +
  77. + HTML::Zoom->from_html('<foo><bar /></foo>')
  78. + ->select('foo')
  79. + ->collect({ content => 1, passthough => 1 })
  80. + ->to_html
  81. +
  82. +returns '<foo><bar /></foo>'.
  83. +
  84. +Using simply '$zoom->collect({ passthrough => 1 });' turns
  85. +L<HTML::Zoom> object into list of events.
  86. +
  87. +=item content [BOOLEAN]
  88. +
  89. +Collect content of the element, and not element itself.
  90. +
  91. +See also L</collect_content>.
  92. +
  93. +=item flush_before [BOOLEAN]
  94. +
  95. +Generate C<flush> event before collecting, to ensure that the HTML generated up
  96. +to selected element being collected is thushed throught to the browser.
  97. +
  98. +=back
  99. +
  100. +=head2 collect_content ( [options] )
  101. +
  102. +Collects contents of L<HTML::Zoom/select> result.
  103. +
  104. + HTML::Zoom->from_file($foo)
  105. + ->select('#main-content')
  106. + ->collect_content({ into => \@foo_body })
  107. + ->run;
  108. + $z->select('#foo')
  109. + ->replace_content(\@foo_body)
  110. + ->memoize;
  111. +
  112. +Equivalent to running L</collect> with C<content> option.
  113. +
  114. +=head2 add_before ( $content )
  115. +
  116. +Given a L<HTML::Zoom/select> result, add given content (which might be string,
  117. +array or another L<HTML::Zoom> object) before it.
  118. +
  119. + $html_zoom
  120. + ->select('input[name="foo"]')
  121. + ->add_before(\ '<span class="warning">required field</span>');
  122. +
  123. +=head2 add_after ( $content )
  124. +
  125. +Like L</add_before>, only after L<HTML::Zoom/select> result.
  126. +
  127. + $html_zoom
  128. + ->select('p')
  129. + ->add_after("\n\n");
  130.  
  131. =head2 prepend_content
  132.  
  133. @@ -445,22 +525,76 @@ Removes attributes from the original stream or events already added.
  134.  
  135. TBD
  136.  
  137. -=head2 replace
  138. +=head2 replace ( $replacement, [ options ] )
  139.  
  140. - TBD
  141. +Given a L<HTML::Zoom/select> result, replace it with a string, array or another
  142. +L<HTML::Zoom> object. It takes the same optional common options as L</collect>
  143. +(via hash reference).
  144.  
  145. =head2 replace_content
  146.  
  147. Given a L<HTML::Zoom/select> result, replace the content with a string, array
  148. or another L<HTML::Zoom> object.
  149.  
  150. -=head2 repeat
  151. + $html_zoom
  152. + ->select('title, #greeting')
  153. + ->replace_content('Hello world!');
  154.  
  155. - TBD
  156. +=head2 repeat ( $repeat_for, [ options ] )
  157.  
  158. -=head2 repeat_content
  159. +Replace result of L<HTML::Zoom/select> (of collected elements) with list of
  160. +elements, given as array reference, iterator (code reference) or L<HTML::Zoom>
  161. +object.
  162. +
  163. + my @list = qw(foo bar baz);
  164. + my $z2 = $zoom->select('.item')->repeat(sub {
  165. + if (my $name = shift @list) {
  166. + return sub { $_->select('.item-name')->replace_content($name) }
  167. + } else {
  168. + return
  169. + }
  170. + }, { flush_before => 1 });
  171. +
  172. +In addition to common options as in L</collect>, it also supports
  173. +
  174. +=over
  175. +
  176. +=item repeat_between [SELECTOR]
  177. +
  178. +Selects object to be repeated between items. In the case of array this object
  179. +is put between elements, in case of iterator it is put between results of
  180. +subsequent iterations, in the case of stream it is put between events
  181. +($stream->next).
  182. +
  183. +=back
  184. +
  185. +=head2 repeat_content ( $repeat_for, [ options ] )
  186. +
  187. +Given a L<HTML::Zoom/select> result, replace the content with provided or
  188. +generated list of elements. Accepts the same options as L</repeat>.
  189. +
  190. +Equivalent to using C<contents> option with L</repeat>.
  191. +
  192. + $html_zoom
  193. + ->select('#list')
  194. + ->repeat_content(
  195. + [
  196. + sub {
  197. + $_->select('.name')->replace_content('Matt')
  198. + ->select('.age')->replace_content('26')
  199. + },
  200. + sub {
  201. + $_->select('.name')->replace_content('Mark')
  202. + ->select('.age')->replace_content('0x29')
  203. + },
  204. + sub {
  205. + $_->select('.name')->replace_content('Epitaph')
  206. + ->select('.age')->replace_content('<redacted>')
  207. + },
  208. + ],
  209. + { repeat_between => '.between' }
  210. + );
  211.  
  212. - TBD
  213.  
  214. =head1 ALSO SEE
Add Comment
Please, Sign In to add comment