]> iEval git - html-element-library.git/blobdiff - lib/HTML/Element/Library.pm
'fixd'
[html-element-library.git] / lib / HTML / Element / Library.pm
index fa037657ea21e95eda9f5800418f99e31d306215..024e114e441a0878ee698adccfc8125bc0a11324 100644 (file)
@@ -1,5 +1,5 @@
 package HTML::Element::Library;
-
+# ABSTRACT: Convenience methods for HTML::TreeBuilder and HTML::Element
 
 use strict;
 use warnings;
@@ -25,7 +25,7 @@ our @EXPORT      = qw();
 
 
 
-our $VERSION = '4.2.b';
+our $VERSION = '4.3';
 
 
 
@@ -72,6 +72,51 @@ sub HTML::Element::defmap {
 
 }
 
+sub HTML::Element::_only_empty_content {
+  my ($self)=@_;
+  my @c = $self->content_list;
+  my $length  = scalar @c;
+
+  #use Data::Dumper;
+  #warn sprintf 'Testing %s (%s)' , $self->starttag, Dumper(\@c);
+  #warn sprintf "\t\tlength of content: %d ", $length;
+
+  scalar @c == 1 and not length($c[0]);
+}
+
+sub HTML::Element::prune {
+  my ($self)=@_;
+
+  for my $c ($self->content_list) {
+    next unless ref $c;
+    #warn "C: " . Dumper($c);
+    $c->prune;
+  }
+
+  # post-order:
+  $self->delete if ($self->is_empty or $self->_only_empty_content);
+  $self;
+}
+
+
+sub HTML::Element::crunch {
+    my $container = shift;
+
+    my %p = validate(@_, {
+                         look_down => { type => ARRAYREF },
+                         leave => { default => 1 },
+                        });
+
+    my @look_down = @{$p{look_down}} ;
+    my @elem = $container->look_down( @look_down ) ;
+    
+    my $left;
+    
+    for my $elem (@elem) {
+       $elem->detach if $left++ >= $p{leave} ;
+    }
+
+}
 
 sub HTML::Element::hash_map {
     my $container = shift;
This page took 0.02688 seconds and 4 git commands to generate.