# TODO: document more fully?
sub parse_content { # from any number of scalars
my $tree = shift;
my $retval;
foreach my $whunk (@_) {
if(ref($whunk) eq 'SCALAR') {
$retval = $tree->parse($$whunk);
} else {
$retval = $tree->parse($whunk);
}
last if $tree->{'_stunted'}; # might as well check that.
}
$tree->eof();
return $retval;
}
#---------------------------------------------------------------------------
sub new { # constructor!
my $class = shift;
$class = ref($class) || $class;
my $self = HTML::Element->new('html'); # Initialize HTML::Element part
{
# A hack for certain strange versions of Parser:
my $other_self = HTML::Parser->new();
%$self = (%$self, %$other_self); # copy fields
# Yes, multiple inheritance is messy. Kids, don't try this at home.
bless $other_self, "HTML::TreeBuilder::_hideyhole";
# whack it out of the HTML::Parser class, to avoid the destructor
}
# The root of the tree is special, as it has these funny attributes,
# and gets reblessed into this class.
# Initialize parser settings
$self->{'_implicit_tags'} = 1;
$self->{'_implicit_body_p_tag'} = 0;
# If true, trying to insert text, or any of %isPhraseMarkup right
# under 'body' will implicate a 'p'. If false, will just go there.
$self->{'_tighten'} = 1;
# whether ignorable WS in this tree should be deleted
$self->{'_implicit'} = 1; # to delete, once we find a real open-"html" tag
$self->{'_element_class'} = 'HTML::Element';
$self->{'_ignore_unknown'} = 1;
$self->{'_ignore_text'} = 0;
$self->{'_warn'} = 0;
$self->{'_no_space_compacting'}= 0;
$self->{'_store_comments'} = 0;
$self->{'_store_declarations'} = 1;
$self->{'_store_pis'} = 0;
$self->{'_p_strict'} = 0;
# Parse attributes passed in as arguments
if(@_) {
my %attr = @_;
for (keys %attr) {
$self->{"_$_"} = $attr{$_};
}
}
# rebless to our class
bless $self, $class;
$self->{'_element_count'} = 1;
# undocumented, informal, and maybe not exactly correct
$self->{'_head'} = $self->insert_element('head',1);
$self->{'_pos'} = undef; # pull it back up
$self->{'_body'} = $self->insert_element('body',1);
$self->{'_pos'} = undef; # pull it back up again
return $self;
}
#==========================================================================
sub _elem # universal accessor...
{
my($self, $elem, $val) = @_;
my $old = $self->{$elem};
$self->{$elem} = $val if defined $val;
return $old;
}
# accessors....
sub implicit_tags { shift->_elem('_implicit_tags', @_); }
sub implicit_body_p_tag { shift->_elem('_implicit_body_p_tag', @_); }
sub p_strict { shift->_elem('_p_strict', @_); }
sub no_space_compacting { shift->_elem('_no_space_compacting', @_); }
sub ignore_unknown { shift->_elem('_ignore_unknown', @_); }
sub ignore_text { shift->_elem('_ignore_text', @_); }
sub ignore_ignorable_whitespace { shift->_elem('_tighten', @_); }
sub store_comments { shift->_elem('_store_comments', @_); }
sub store_declarations { shift->_elem('_store_declarations', @_); }
sub store_pis { shift->_elem('_store_pis', @_); }
=2= |