#!/usr/bin/perl
package MyElement;
use HTML::Element;
#inherit from Element
@ISA = qw(HTML::Element);
sub dummy{
#HTML::Element::_fold_case_NOT;
@a = HTML::Element::_fold_case_NOT(@_);
return @a;
}
*HTML::Element::_fold_case = \&HTML::Element::_fold_case_NOT;
#*_fold_case = \&dummy;
#constructor
sub new {
my $class = shift;
$class = ref($class) || $class;
#invoke base constructor
my $self = $class->SUPER::new(@_);
bless($self, $class);
return $self;
}
sub starttag {
my ( $self, $entities ) = @_;
my $name = $self->{'_tag'};
return $self->{'text'} if $name eq '~literal';
return "{'text'} . ">" if $name eq '~declaration';
return "" . $self->{'text'} . ">" if $name eq '~pi';
if ( $name eq '~comment' ) {
if ( ref( $self->{'text'} || '' ) eq 'ARRAY' ) {
# Does this ever get used? And is this right?
return
"{'text'} } ) ) . ">";
}
else {
return "";
}
}
my $tag = "<$name";
my $val;
for ( sort keys %$self ) { # predictable ordering
next if !length $_ or m/^_/s or $_ eq '/';
$val = $self->{$_};
next if !defined $val; # or ref $val;
if ($_ eq $val && # if attribute is boolean, for this element
exists( $HTML::Element::boolean_attr{$name} )
&& (ref( $HTML::Element::boolean_attr{$name} )
? $HTML::Element::boolean_attr{$name}{$_}
: $HTML::Element::boolean_attr{$name} eq $_
)
)
{
$tag .= " $_";
}
else { # non-boolean attribute
if ( ref $val eq 'HTML::Element'
and $val->{_tag} eq '~literal' )
{
$val = $val->{text};
}
else {
HTML::Entities::encode_entities( $val, $entities )
unless (
defined($entities) && !length($entities)
|| $encoded_content
);
}
$val = qq{"$val"};
$tag .= qq{ $_\E=$val};
}
} # for keys
if ( scalar $self->content_list == 0
&& $self->_empty_element_map->{ $self->tag } )
{
return $tag . " />";
}
else {
return $tag . ">";
}
}
sub endtag {
"$_[0]->{'_tag'}>";
}
return 1;