From ce4e9192aee74dad8e8131803f127f66ee3a1c3b Mon Sep 17 00:00:00 2001 From: Terrence Brannon Date: Tue, 5 Jul 2011 11:23:34 -0400 Subject: [PATCH] 'fixd' --- MANIFEST | 119 ------------------------------------ META.yml | 31 ---------- Makefile.PL | 55 ----------------- dist.ini | 14 +++++ lib/HTML/Element/Library.pm | 29 ++++++++- t/prune.t | 51 ++++++++++++++++ 6 files changed, 93 insertions(+), 206 deletions(-) delete mode 100644 MANIFEST delete mode 100644 META.yml delete mode 100644 Makefile.PL create mode 100644 dist.ini create mode 100644 t/prune.t diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 03c4738..0000000 --- a/MANIFEST +++ /dev/null @@ -1,119 +0,0 @@ -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 diff --git a/META.yml b/META.yml deleted file mode 100644 index 022aea1..0000000 --- a/META.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- #YAML:1.0 -name: HTML-Element-Library -version: 4.2.a -abstract: ~ -author: - - Terrence Brannon -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 diff --git a/Makefile.PL b/Makefile.PL deleted file mode 100644 index 27f6eb4..0000000 --- a/Makefile.PL +++ /dev/null @@ -1,55 +0,0 @@ -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 ') : ()), - ); - -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 - -}; } diff --git a/dist.ini b/dist.ini new file mode 100644 index 0000000..ed727c1 --- /dev/null +++ b/dist.ini @@ -0,0 +1,14 @@ +name = HTML-Element-Library +author = Terrence Brannon +license = Perl_5 +copyright_holder = Terrence Brannon +version = 4.4 + +[@Basic] + +[@GitHub] + +[AutoPrereqs] + +[Prereqs] +Test::XML = 0 \ No newline at end of file diff --git a/lib/HTML/Element/Library.pm b/lib/HTML/Element/Library.pm index dbbd62e..024e114 100644 --- a/lib/HTML/Element/Library.pm +++ b/lib/HTML/Element/Library.pm @@ -1,5 +1,5 @@ package HTML::Element::Library; - +# ABSTRACT: Convenience methods for HTML::TreeBuilder and HTML::Element use strict; use warnings; @@ -72,6 +72,33 @@ 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; diff --git a/t/prune.t b/t/prune.t new file mode 100644 index 0000000..5086257 --- /dev/null +++ b/t/prune.t @@ -0,0 +1,51 @@ +#!/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'; + + + + + +
There was man named Jed
+
He did not have a head
+
He lived beneath a sled
+
Now he's afraid of Fred...
+
+
+ + +EOHTML + +$root->parse($html); +$root->delete_ignorable_whitespace; +$root->prune; + +my $expected = ' + + +
There was man named Jed
He did not have a head
He lived beneath a sled
Now he's afraid of Fred...
+ +'; + +#warn sprintf 'HTML:%s:HTML', $root->as_HTML; + +is_xml($root->as_HTML, $expected, 'test pruning'); + + + +done_testing; -- 2.39.2