+++ /dev/null
-Changes
-CHANGES
-lib/HTML/Element/Library.pm
-lib/HTML/Element/Library.pod
-lib/HTML/Element/Library/Changes.pod
-Makefile.PL
-MANIFEST This list of files
-META.yml
-README
-t/00system.t
-t/Arsenal.pl
-t/Arsenal.pm
-t/content_handler.t
-t/crunch.t
-t/data/3dig.dat
-t/data/4dig.dat
-t/data/table2.pm
-t/defmap.t
-t/dual_iter.t
-t/fillinform.t
-t/hashmap.t
-t/highlander.t
-t/highlander2.t
-t/HTML-Element-Library.t
-t/html/crunch/crunch.initial
-t/html/crunch/crunch.exp
-t/html/defmap/defmap.exp
-t/html/defmap/defmap.gen
-t/html/defmap/defmap.initial
-t/html/dual_iter.exp
-t/html/dual_iter.gen
-t/html/dual_iter.html
-t/html/fillinform/fillinform.exp
-t/html/fillinform/fillinform.gen
-t/html/fillinform/fillinform.initial
-t/html/highlander-15.exp
-t/html/highlander-15.gen
-t/html/highlander-5.exp
-t/html/highlander-5.gen
-t/html/highlander-50.exp
-t/html/highlander-50.gen
-t/html/highlander.html
-t/html/highlander2-15.exp
-t/html/highlander2-15.gen
-t/html/highlander2-27.exp
-t/html/highlander2-27.gen
-t/html/highlander2-5.exp
-t/html/highlander2-5.gen
-t/html/highlander2-passover.exp
-t/html/highlander2-passover.gen
-t/html/highlander2.html
-t/html/iter.exp
-t/html/iter.gen
-t/html/iter.html
-t/html/iter2.exp
-t/html/iter2.gen
-t/html/iter2.html
-t/html/same_as.html
-t/html/same_as/same_as.exp
-t/html/same_as/same_as.gen
-t/html/same_as/same_as.initial
-t/html/table-alt.exp
-t/html/table-alt.gen
-t/html/table-alt.html
-t/html/table.exp
-t/html/table.gen
-t/html/table.html
-t/html/table2-table_ld-arrayref.exp
-t/html/table2-table_ld-arrayref.gen
-t/html/table2-table_ld-arrayref.html
-t/html/table2-table_ld-coderef.exp
-t/html/table2-table_ld-coderef.gen
-t/html/table2-table_ld-coderef.html
-t/html/table2-table_ld-default.exp
-t/html/table2-table_ld-default.gen
-t/html/table2-table_ld-default.html
-t/html/table2-tr_ld-arrayref.exp
-t/html/table2-tr_ld-arrayref.gen
-t/html/table2-tr_ld-arrayref.html
-t/html/table2-tr_ld-coderef.exp
-t/html/table2-tr_ld-coderef.gen
-t/html/table2-tr_ld-coderef.html
-t/html/table2-tr_ld-default.gen
-t/html/table2-tr_ld-default.html
-t/html/table2-tr_ld_coderef.exp
-t/html/table2.exp
-t/html/table2.gen
-t/html/table2.html
-t/html/table2_code.html
-t/html/table2_id.exp
-t/html/table2_id.html
-t/html/table2_tr_proc.html
-t/html/unroll_select.exp
-t/html/unroll_select.gen
-t/html/unroll_select.html
-t/iter.t
-t/iter2.t
-t/m/SelectData.pm
-t/m/SimpleClass.pm
-t/m/TestUtils.pm
-t/not-used/Arsenal.pl
-t/not-used/Arsenal.pm
-t/passover.t
-t/position.t
-t/q
-t/replace_content.t
-t/SelectData.pm
-t/set_child_content.t
-t/sibdex.t
-t/siblings.t
-t/SimpleClass.pm
-t/table-alt.t
-t/table.t
-t/table2-table_ld.t
-t/table2-tr_ld.t
-t/table2.t
-t/TestUtils.pm
-t/unroll_select.t
-t/wrap_content.t
+++ /dev/null
---- #YAML:1.0
-name: HTML-Element-Library
-version: 4.2.a
-abstract: ~
-author:
- - Terrence Brannon <tbone@cpan.org>
-license: unknown
-distribution_type: module
-configure_requires:
- ExtUtils::MakeMaker: 0
-build_requires:
- ExtUtils::MakeMaker: 0
-requires:
- Array::Group: 1
- File::Slurp: 9999.06
- HTML::FillInForm: 0
- HTML::PrettyPrinter: 0.03
- HTML::Tree: 3.19
- List::MoreUtils: 0.09
- List::Rotation::Cycle: 1.003
- Moose: 0
- Params::Validate: 0.8
- Scalar::Listify: 0.02
-no_index:
- directory:
- - t
- - inc
-generated_by: ExtUtils::MakeMaker version 6.54
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
+++ /dev/null
-use 5.006001;
-use ExtUtils::MakeMaker;
-# See lib/ExtUtils/MakeMaker.pm for details of how to influence
-# the contents of the Makefile that is written.
-WriteMakefile
- (
- NAME => 'HTML::Element::Library',
- VERSION_FROM => 'lib/HTML/Element/Library.pm', # finds $VERSION
- PREREQ_PM =>
- {
- Array::Group => 1.00,
-
- Moose => 0,
- File::Slurp => 9999.06,
-
- HTML::FillInForm => 0,
- HTML::PrettyPrinter => 0.03,
- HTML::Tree => 4.1,
-
- List::Rotation::Cycle => 1.003,
- List::MoreUtils => 0.09,
-
- Params::Validate => 0.80,
-
- Scalar::Listify => 0.02,
- },
- ($] >= 5.005 ? ## Add these new keywords supported since 5.005
- (
-
- AUTHOR => 'Terrence Brannon <tbone@cpan.org>') : ()),
- );
-
-sub MY::postamble { q{
-
-cleandist: FORCE
- make again; make cleanmanifest; make docs; make dist
-
-again: FORCE
- make clean; perl Makefile.PL; make pm_to_blib
-
-cleanmanifest: realclean FORCE
- rm MANIFEST ; perl Makefile.PL; touch MANIFEST; make manifest
-
-%.t: pm_to_blib FORCE
- make; perl -Iblib/lib $@
-
-docs : README CHANGES
-
-README: lib/HTML/Element/Library.pm
- pod2text lib/HTML/Element/Library.pm > README
-
-CHANGES: lib/HTML/Element/Library/Changes.pod
- pod2text lib/HTML/Element/Library/Changes.pod > CHANGES
-
-}; }
--- /dev/null
+name = HTML-Element-Library
+author = Terrence Brannon <metaperl@gmail.com>
+license = Perl_5
+copyright_holder = Terrence Brannon
+version = 4.4
+
+[@Basic]
+
+[@GitHub]
+
+[AutoPrereqs]
+
+[Prereqs]
+Test::XML = 0
\ No newline at end of file
package HTML::Element::Library;
-
+# ABSTRACT: Convenience methods for HTML::TreeBuilder and HTML::Element
use strict;
use warnings;
}
+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;
--- /dev/null
+#!/usr/bin/perl -T
+
+
+use warnings;
+use strict;
+
+use Test::More;
+use Test::XML;
+
+BEGIN {
+ use_ok('HTML::TreeBuilder');
+ use_ok('HTML::Element::Prune');
+}
+
+
+
+my $root = HTML::TreeBuilder->new();
+my $html =<<'EOHTML';
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+ <div>There was man named Jed</div>
+<div>He did not have a head</div>
+<div>He lived beneath a sled</div>
+<div>Now he's afraid of Fred...</div>
+<div>
+</div>
+ </body>
+</html>
+EOHTML
+
+$root->parse($html);
+$root->delete_ignorable_whitespace;
+$root->prune;
+
+my $expected = '
+<html>
+<body>
+<div>There was man named Jed</div><div>He did not have a head</div><div>He lived beneath a sled</div><div>Now he's afraid of Fred...</div> </body>
+</html>
+';
+
+#warn sprintf 'HTML:%s:HTML', $root->as_HTML;
+
+is_xml($root->as_HTML, $expected, 'test pruning');
+
+
+
+done_testing;