element #2: _tag: 'head'
_parent: element #1
_content: [element #3, element #4]
element #3: _tag: 'title'
_parent: element #2
_content: [text segment "Stuff"]
element #4 _tag: 'meta'
_parent: element #2
_content: none
name: author
content: Jojo
element #5 _tag: 'body'
_parent: element #1
_content: [element #6]
element #6 _tag: 'h1'
_parent: element #5
_content: [text segment "I like potatoes"]
The "treeness" of the tree-structure that these elements comprise is
not an aspect of any particular object, but is emergent from the
relatedness attributes (_parent and _content) of these element-objects
and from how you use them to get from element to element.
While you could access the content of a tree by writing code that says
"access the 'src' attribute of the root's I<first> child's I<seventh>
child's I<third> child", you're more likely to have to scan the contents
of a tree, looking for whatever nodes, or kinds of nodes, you want to
do something with. The most straightforward way to look over a tree
is to "traverse" it; an HTML::Element method (C<< $h->traverse >>) is
provided for this purpose; and several other HTML::Element methods are
based on it.
(For everything you ever wanted to know about trees, and then some,
see Niklaus Wirth's I<Algorithms + Data Structures = Programs> or
Donald Knuth's I<The Art of Computer Programming, Volume 1>.)
=cut
use strict;
use Carp ();
use HTML::Entities ();
use HTML::Tagset ();
use integer; # vroom vroom!
use vars qw($html_uc $Debug $ID_COUNTER %list_type_to_sub);
$Debug = 0 unless defined $Debug;
sub Version { $VERSION; }
my $nillio = [];
*HTML::Element::emptyElement = \%HTML::Tagset::emptyElement; # legacy
*HTML::Element::optionalEndTag = \%HTML::Tagset::optionalEndTag; # legacy
*HTML::Element::linkElements = \%HTML::Tagset::linkElements; # legacy
*HTML::Element::boolean_attr = \%HTML::Tagset::boolean_attr; # legacy
*HTML::Element::canTighten = \%HTML::Tagset::canTighten; # legacy
# Constants for signalling back to the traverser:
my $travsignal_package = __PACKAGE__ . '::_travsignal';
my(
$ABORT, $PRUNE, $PRUNE_SOFTLY, $OK, $PRUNE_UP
) =
map
{my $x = $_ ; bless \$x, $travsignal_package;}
qw(
ABORT PRUNE PRUNE_SOFTLY OK PRUNE_UP
)
;
sub ABORT () {$ABORT}
sub PRUNE () {$PRUNE}
sub PRUNE_SOFTLY () {$PRUNE_SOFTLY}
sub OK () {$OK}
sub PRUNE_UP () {$PRUNE_UP}
$html_uc = 0;
# set to 1 if you want tag and attribute names from starttag and endtag
# to be uc'd
# Elements that does not have corresponding end tags (i.e. are empty)
#==========================================================================
=head1 BASIC METHODS
=head2 $h = HTML::Element->new('tag', 'attrname' => 'value', ... )
This constructor method returns a new HTML::Element object. The tag
name is a required argument; it will be forced to lowercase.
Optionally, you can specify other initial attributes at object
creation time.
=cut
=2= |