From: Terrence Brannon Date: Fri, 5 Aug 2011 21:32:42 +0000 (-0400) Subject: fixes X-Git-Tag: 5.200_001~23 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=855ca7e94970d4e83a351938645f8e007f7b8b63;p=html-element-library.git fixes --- diff --git a/dist.ini b/dist.ini index d8740f8..65cb38c 100644 --- a/dist.ini +++ b/dist.ini @@ -2,13 +2,24 @@ name = HTML-Element-Library author = Terrence Brannon license = Perl_5 copyright_holder = Terrence Brannon -version = 4.4 + [@Basic] -[@GitHub] +[PkgVersion] + +[AutoVersion] +major = 5 + + [AutoPrereqs] skip = (Test::XML|Arsenal|SimpleClass|SelectData|TestUtils|data::table2) + + +[TestRelease] +[ConfirmRelease] + + diff --git a/lib/HTML/Element/Library.pm b/lib/HTML/Element/Library.pm index cb9cec3..beb1245 100644 --- a/lib/HTML/Element/Library.pm +++ b/lib/HTML/Element/Library.pm @@ -25,7 +25,7 @@ our @EXPORT = qw(); -our $VERSION = '4.3'; + @@ -98,16 +98,16 @@ sub HTML::Element::prune { $self; } -sub HTML::Element::newnode { - my ($lol, $node_label, $new_node)=@_; +sub HTML::Element::newchild { + my ($lol, $parent_label, @newchild)=@_; use Data::Rmap qw(rmap_array); my ($mapresult) = rmap_array { - if ($_->[0] eq $node_label) { - $_ = $new_node; + if ($_->[0] eq $parent_label) { + $_ = [ $parent_label => @newchild ]; Data::Rmap::cut($_); } else { $_; diff --git a/lib/HTML/Element/Library.pod b/lib/HTML/Element/Library.pod index 909aa9e..267537a 100644 --- a/lib/HTML/Element/Library.pod +++ b/lib/HTML/Element/Library.pod @@ -1106,7 +1106,7 @@ you manipulate a loltree programmatically. These could not be methods because if you bless a loltree, then HTML::Tree will barf. -=head3 HTML::Element::replace_node($lol, $node_label, $new_node) +=head3 HTML::Element::newchild($lol, $parent_label, @newchild) Given this initial loltree: @@ -1116,7 +1116,7 @@ This code: sub shopping_items { my @shopping_items = map { [ item => _ ] } qw(bread butter beans) ; - \@shopping_items; + @shopping_items; } my $new_lol = HTML::Element::newnode($initial_lol, item => shopping_items()); @@ -1128,7 +1128,7 @@ This code: 'note', [ 'shopping', - [ + [ 'item', 'bread' @@ -1141,7 +1141,7 @@ This code: 'item', 'beans' ] - ] + ] ]; @@ -1160,13 +1160,13 @@ A perl package for creating and manipulating HTML trees. An L - based module which allows for manipulation of HTML trees using cartesian coordinations. -=head2 * L +=head2 L An L - based module inspired by XMLC (L), allowing for dynamic HTML generation via tree rewriting. -=head2 Push-style tmeplating systems +=head2 Push-style templating systems A comprehensive cross-language L. @@ -1218,16 +1218,19 @@ down instead: =cut -=head1 SEE ALSO - -L -=head1 AUTHOR / SOURCE +=head1 AUTHOR and ACKS Terrence Brannon, Etbone@cpan.orgE Many thanks to BARBIE for his RT bug report. +Many thanks to perlmonk kcott for his work on array rewriting: +L. +It was crucial in the development of newchild. + +=head2 Source Repo + The source is at L =head1 COPYRIGHT AND LICENSE diff --git a/t/defmap.t b/t/defmap.t index 05c930d..c26ab43 100644 --- a/t/defmap.t +++ b/t/defmap.t @@ -4,6 +4,7 @@ use lib qw(t/ t/m/); use File::Slurp; use Test::More qw(no_plan); +use Test::XML; use TestUtils; use HTML::TreeBuilder; @@ -21,9 +22,11 @@ sub tage { $tree->defmap(smap => \%data, 1); - my $generated_html = ptree($tree, "$root.gen"); + my $g = ptree($tree, "$root.gen"); + my $e = File::Slurp::read_file("$root.exp"); + warn "generated:$g:\nexpected:$e:"; - is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as"); + is_xml ($g, $e, "HTML for defmap"); } diff --git a/t/newchild.t b/t/newchild.t new file mode 100644 index 0000000..43b641d --- /dev/null +++ b/t/newchild.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::Library'); +} + + +my $initial_lol = [ note => [ shopping => [ item => 'sample' ] ] ]; +my $new_lol = HTML::Element::newchild($initial_lol, shopping => shopping_items()); + + +sub shopping_items { + my @shopping_items = map { [ item => $_ ] } qw(bread butter beans); + @shopping_items; +} + +my $expected = [ + 'note', + [ + 'shopping', + [ + 'item', + 'bread' + ], + [ + 'item', + 'butter' + ], + [ + 'item', + 'beans' + ] + ] + ]; + +use Data::Dumper; +warn Dumper($new_lol); + +is_deeply($new_lol, $expected, 'test unrolling'); + + + +done_testing; diff --git a/t/newnode.t b/t/newnode.t deleted file mode 100644 index 5ca7122..0000000 --- a/t/newnode.t +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/perl -T - - -use warnings; -use strict; - -use Test::More; -use Test::XML; - -BEGIN { - use_ok('HTML::TreeBuilder'); - use_ok('HTML::Element::Library'); -} - - -my $initial_lol = [ note => [ shopping => [ item => 'sample' ] ] ]; -my $new_lol = HTML::Element::newnode($initial_lol, item => shopping_items()); - - -sub shopping_items { - my @shopping_items = map { [ item => $_ ] } qw(bread butter beans); - \@shopping_items; -} - -my $expected = [ - 'note', - [ - 'shopping', - [ - [ - 'item', - 'bread' - ], - [ - 'item', - 'butter' - ], - [ - 'item', - 'beans' - ] - ] - ] - ]; - -is_deeply($new_lol, $expected, 'test unrolling'); - - - -done_testing;