$tree->fillinform
authorTerrence Brannon <TBrannon@SmartFinancial.com>
Fri, 13 Mar 2009 18:29:41 +0000 (14:29 -0400)
committerTerrence Brannon <TBrannon@SmartFinancial.com>
Fri, 13 Mar 2009 18:29:41 +0000 (14:29 -0400)
lib/HTML/Element/Library.pm

index cf49bfcb793ca29399d94dca4759ca81575d9454..df9681f9d73b269e40d0ca65be585f931139f1b7 100644 (file)
@@ -28,8 +28,20 @@ our @EXPORT      = qw();
 our $VERSION = '3.53';
 
 
+
 # Preloaded methods go here.
 
+# https://rt.cpan.org/Ticket/Display.html?id=44105
+sub HTML::Element::fillinform {
+
+    my ($tree, $hashref)=@_;
+
+    use HTML::FillInForm;
+    my $html = $tree->as_HTML;
+    my $new_html = HTML::FillInForm->fill(\$html, $hashref);
+
+}
+
 sub HTML::Element::siblings {
   my $element = shift;
   my $p = $element->parent;
@@ -797,6 +809,27 @@ One of these days, I'll around to writing a nice C<EXPORT> section.
 
 =head2 Tree Rewriting Methods
 
+=head3 Simplifying calls to HTML::FillInForm
+
+Since HTML::FillInForm gets and returns strings, using HTML::Element instances 
+becomes tedious:
+
+   1. Seamstress has an HTML tree that it wants the form filled in on
+   2. Seamstress converts this tree to a string
+   3. FillInForm parses the string into an HTML tree and then fills in the form
+   4. FillInForm converts the HTML tree to a string
+   5. Seamstress re-parses the HTML for additional processing 
+
+I've filed a bug about this:
+L<https://rt.cpan.org/Ticket/Display.html?id=44105>
+
+This function, fillinform, 
+allows you to pass a tree to fillinform (along with your data structure) and
+get back a tree:
+
+   my $new_tree = $html_tree->fillinform($data_structure);
+  
+
 =head3 Mapping a hashref to HTML elements
 
 It is very common to get a hashref of data from some external source - flat file, database, XML, etc.
This page took 0.011621 seconds and 4 git commands to generate.