From d9f4bd5ad20ac5d784c901ec745a50522b69d4a8 Mon Sep 17 00:00:00 2001
From: Terrence Brannon <TBrannon@SmartFinancial.com>
Date: Wed, 4 Feb 2009 11:06:05 -0500
Subject: [PATCH] fixed test suite

---
 lib/HTML/Element/Library.pm    | 21 ++++++++++++++++-----
 t/html/same_as/same_as.exp     |  6 +++---
 t/html/same_as/same_as.gen     |  6 +++---
 t/html/same_as/same_as.initial |  2 +-
 t/same_as.t                    | 11 ++++++++---
 5 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/lib/HTML/Element/Library.pm b/lib/HTML/Element/Library.pm
index 7c6cf75..60c7a4a 100644
--- a/lib/HTML/Element/Library.pm
+++ b/lib/HTML/Element/Library.pm
@@ -43,16 +43,27 @@ sub HTML::Element::hash_map {
     my %p = validate(@_, {
 			  hash => { type => HASHREF },
 			  to_attr => 1,
-			  excluding => { type => ARRAYREF },
+			  excluding => { type => ARRAYREF , default => [] },
 			  debug => { default => 0 },
 			 });
 
-    my @same_as = $container->look_down('_attr' => $p{to_attr});
+    warn 'The container tag is ', $container->tag if $p{debug} ;
+    warn 'hash' . Dumper($p{hash}) if $p{debug} ;
+    warn 'at_under' . Dumper(\@_);
+
+    my @same_as = $container->look_down( $p{to_attr} => qr/.+/ ) ;
+
+    warn 'Found ' . scalar(@same_as) . ' nodes' if $p{debug} ;
+
 
     for my $same_as (@same_as) {
-	next if first { $same_as->attr($p{to_attr})  eq $_ } @{$p{excluding}} ;
-	my $hash_key =  $same_as->attr($p{to_attr}) ;
-	$same_as->replace_content( $p{hash}->{$hash_key} ) ;
+	my $attr_val = $same_as->attr($p{to_attr}) ;
+	if (first { $attr_val eq $_ } @{$p{excluding}}) {
+	    warn "excluding $attr_val" if $p{debug} ;
+	    next;
+	}
+	warn "processing $attr_val" if $p{debug} ;
+	$same_as->replace_content( $p{hash}->{$attr_val} ) ;
     }
 
 }
diff --git a/t/html/same_as/same_as.exp b/t/html/same_as/same_as.exp
index 3eac36a..22486ba 100644
--- a/t/html/same_as/same_as.exp
+++ b/t/html/same_as/same_as.exp
@@ -5,9 +5,9 @@
   <body>
     <table>
       <tr align="left" sclass="tr" valign="top" class="alt">
-        <td sid="people_id">1</td>
-        <td sid="phone">(877) 255-3239</td>
-        <td sid="email"><a sid="a_email" href="mailto:leave-me-alone@gmail.com"
+        <td sid="people_id">888</td>
+        <td sid="phone">444-4444</td>
+        <td sid="email"><a href="mailto:leave-me-alone@gmail.com" id="a_email"
             >should-not-be-touched@seamstress.com</a></td>
       </tr>
     </table>
diff --git a/t/html/same_as/same_as.gen b/t/html/same_as/same_as.gen
index 3eac36a..22486ba 100644
--- a/t/html/same_as/same_as.gen
+++ b/t/html/same_as/same_as.gen
@@ -5,9 +5,9 @@
   <body>
     <table>
       <tr align="left" sclass="tr" valign="top" class="alt">
-        <td sid="people_id">1</td>
-        <td sid="phone">(877) 255-3239</td>
-        <td sid="email"><a sid="a_email" href="mailto:leave-me-alone@gmail.com"
+        <td sid="people_id">888</td>
+        <td sid="phone">444-4444</td>
+        <td sid="email"><a href="mailto:leave-me-alone@gmail.com" id="a_email"
             >should-not-be-touched@seamstress.com</a></td>
       </tr>
     </table>
diff --git a/t/html/same_as/same_as.initial b/t/html/same_as/same_as.initial
index 555abaa..6d818cd 100644
--- a/t/html/same_as/same_as.initial
+++ b/t/html/same_as/same_as.initial
@@ -8,7 +8,7 @@
     <tr sclass="tr" class="alt" align="left" valign="top">
       <td sid="people_id">1</td>
       <td sid="phone">(877) 255-3239</td>
-      <td sid="email"><a sid="a_email" href="mailto:leave-me-alone@gmail.com">should-not-be-touched@seamstress.com</a></td>
+      <td sid="email"><a id="a_email" href="mailto:leave-me-alone@gmail.com">should-not-be-touched@seamstress.com</a></td>
     </tr>
   </table>
 </body>
diff --git a/t/same_as.t b/t/same_as.t
index c4df836..285f64c 100644
--- a/t/same_as.t
+++ b/t/same_as.t
@@ -24,9 +24,14 @@ sub tage {
 
   #warn "TREE: $tree" . $tree->as_HTML;
 
-  my %data = (people_id => 888, phone => '444-4444', email => 'dont-you-dare-render@xml.com');
-
-  $tree->hash_map(hash => \%data, to_attr => 'sid', excluding => ['email']);
+  my %data = (people_id => 888, phone => '444-4444', email => 'm@xml.com');
+
+  $tree->hash_map
+    (hash    => \%data, 
+     to_attr => 'sid', 
+     excluding => [ 'email' ],
+     debug   => 1
+    );
 
   my $generated_html = ptree($tree, "$root.gen");
 
-- 
2.39.5