author = Terrence Brannon <metaperl@gmail.com>
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]
+
+
-our $VERSION = '4.3';
+
$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 {
$_;
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:
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());
'note',
[
'shopping',
- [
+
[
'item',
'bread'
'item',
'beans'
]
- ]
+
]
];
An L<HTML::Tree> - based module which allows for manipulation of HTML
trees using cartesian coordinations.
-=head2 * L<HTML::Seamstress>
+=head2 L<HTML::Seamstress>
An L<HTML::Tree> - based module inspired by
XMLC (L<http://xmlc.enhydra.org>), allowing for dynamic
HTML generation via tree rewriting.
-=head2 Push-style tmeplating systems
+=head2 Push-style templating systems
A comprehensive cross-language
L<list of push-style templating systems|http://perlmonks.org/?node_id=674225>.
=cut
-=head1 SEE ALSO
-
-L<HTML::Seamstress>
-=head1 AUTHOR / SOURCE
+=head1 AUTHOR and ACKS
Terrence Brannon, E<lt>tbone@cpan.orgE<gt>
Many thanks to BARBIE for his RT bug report.
+Many thanks to perlmonk kcott for his work on array rewriting:
+L<http://www.perlmonks.org/?node_id=912416>.
+It was crucial in the development of newchild.
+
+=head2 Source Repo
+
The source is at L<http://github.com/metaperl/html-element-library/tree/master>
=head1 COPYRIGHT AND LICENSE
use File::Slurp;
use Test::More qw(no_plan);
+use Test::XML;
use TestUtils;
use HTML::TreeBuilder;
$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");
}
--- /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::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;
+++ /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::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;