亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? element.pm

?? ARM上的如果你對底層感興趣
?? PM
字號:
package HTML::Element;

# $Id: Element.pm,v 1.37 1997/12/02 12:48:09 aas Exp $

=head1 NAME

HTML::Element - Class for objects that represent HTML elements

=head1 SYNOPSIS

 require HTML::Element;
 $a = new HTML::Element 'a', href => 'http://www.oslonett.no/';
 $a->push_content("Oslonett AS");

 $tag = $a->tag;
 $tag = $a->starttag;
 $tag = $a->endtag;
 $ref = $a->attr('href');

 $links = $a->extract_links();

 print $a->as_HTML;

=head1 DESCRIPTION

Objects of the HTML::Element class can be used to represent elements
of HTML.  These objects have attributes and content.  The content is an
array of text segments and other HTML::Element objects.  Thus a
tree of HTML::Element objects as nodes can represent the syntax tree
for a HTML document.

The following methods are available:

=over 4

=cut


use strict;
use Carp ();
use HTML::Entities ();

use vars qw($VERSION
	    %emptyElement %optionalEndTag %linkElements %boolean_attr
           );

$VERSION = sprintf("%d.%02d", q$Revision: 1.37 $ =~ /(\d+)\.(\d+)/);
sub Version { $VERSION; }

# Elements that does not have corresponding end tags (i.e. are empty)
%emptyElement   = map { $_ => 1 } qw(base link meta isindex
			             img br hr wbr
			             input area param
			            );
%optionalEndTag = map { $_ => 1 } qw(p li dt dd option); # th tr td);

# Elements that might contain links and the name of the link attribute
%linkElements =
(
 body   => 'background',
 base   => 'href',
 a      => 'href',
 img    => [qw(src lowsrc usemap)],   # lowsrc is a Netscape invention
 form   => 'action',
 input  => 'src',
'link'  => 'href',          # need quoting since link is a perl builtin
 frame  => 'src',
 applet => 'codebase',
 area   => 'href',
);

# These attributes are normally printed without showing the "='value'".
# This representation works as long as no element has more than one
# attribute like this.
%boolean_attr = (
 area   => 'nohref',
 dir    => 'compact',
 dl     => 'compact',
 hr     => 'noshade',
 img    => 'ismap',
 input  => 'checked',
 menu   => 'compact',
 ol     => 'compact',
 option => 'selected',
'select'=> 'multiple',
 td     => 'nowrap',
 th     => 'nowrap',
 ul     => 'compact',
);

=item $h = HTML::Element->new('tag', 'attrname' => 'value',...)

The object constructor.  Takes a tag name as argument. Optionally,
allows you to specify initial attributes at object creation time.

=cut

#
# An HTML::Element is represented by blessed hash reference.  Key-names
# not starting with '_' are reserved for the SGML attributes of the element.
# The following special keys are used:
#
#    '_tag':    The tag name
#    '_parent': A reference to the HTML::Element above (when forming a tree)
#    '_pos':    The current position (a reference to a HTML::Element) is
#               where inserts will be placed (look at the insert_element method)
#
# Example: <img src="gisle.jpg" alt="Gisle's photo"> is represented like this:
#
#  bless {
#     _tag => 'img',
#     src  => 'gisle.jpg',
#     alt  => "Gisle's photo",
#  }, HTML::Element;
#

sub new
{
    my $class = shift;
    my $tag   = shift;
    Carp::croak("No tag") unless defined $tag or length $tag;
    my $self  = bless { _tag => lc $tag }, $class;
    my($attr, $val);
    while (($attr, $val) = splice(@_, 0, 2)) {
	$val = $attr unless defined $val;
	$self->{lc $attr} = $val;
    }
    if ($tag eq 'html') {
	$self->{'_pos'} = undef;
    }
    $self;
}



=item $h->tag()

Returns (optionally sets) the tag name for the element.  The tag is
always converted to lower case.

=cut

sub tag
{
    my $self = shift;
    if (@_) {
	$self->{'_tag'} = lc $_[0];
    } else {
	$self->{'_tag'};
    }
}



=item $h->starttag()

Returns the complete start tag for the element.  Including leading
"<", trailing ">" and attributes.

=cut

sub starttag
{
    my $self = shift;
    my $name = $self->{'_tag'};
    my $tag = "<\U$name";
    for (sort keys %$self) {
	next if /^_/;
	my $val = $self->{$_};
	if ($_ eq $val &&
	    exists($boolean_attr{$name}) && $boolean_attr{$name} eq $_) {
	    $tag .= " \U$_";
	} else {
	    if ($val !~ /^\d+$/) {
		# count number of " compared to number of '
		if (($val =~ tr/\"/\"/) > ($val =~ tr/\'/\'/)) {
		    # use single quotes around the attribute value
		    HTML::Entities::encode_entities($val, "&'>");
		    $val = qq('$val');
		} else {
		    HTML::Entities::encode_entities($val, '&">');
		    $val = qq{"$val"};
		}
	    }
	    $tag .= qq{ \U$_\E=$val};
	}
    }
    "$tag>";
}



=item $h->endtag()

Returns the complete end tag.  Includes leading "</" and the trailing
">".

=cut

sub endtag
{
    "</\U$_[0]->{'_tag'}>";
}



=item $h->parent([$newparent])

Returns (optionally sets) the parent for this element.

=cut

sub parent
{
    my $self = shift;
    if (@_) {
	$self->{'_parent'} = $_[0];
    } else {
	$self->{'_parent'};
    }
}



=item $h->implicit([$bool])

Returns (optionally sets) the implicit attribute.  This attribute is
used to indicate that the element was not originally present in the
source, but was inserted in order to conform to HTML strucure.

=cut

sub implicit
{
    shift->attr('_implicit', @_);
}



=item $h->is_inside('tag',...)

Returns true if this tag is contained inside one of the specified tags.

=cut

sub is_inside
{
    my $self = shift;
    my $p = $self;
    while (defined $p) {
	my $ptag = $p->{'_tag'};
	for (@_) {
	    return 1 if $ptag eq $_;
	}
	$p = $p->{'_parent'};
    }
    0;
}



=item $h->pos()

Returns (and optionally sets) the current position.  The position is a
reference to a HTML::Element object that is part of the tree that has
the current object as root.  This restriction is not enforced when
setting pos(), but unpredictable things will happen if this is not
true.


=cut

sub pos
{
    my $self = shift;
    my $pos = $self->{'_pos'};
    if (@_) {
	$self->{'_pos'} = $_[0];
    }
    return $pos if defined($pos);
    $self;
}



=item $h->attr('attr', [$value])

Returns (and optionally sets) the value of some attribute.

=cut

sub attr
{
    my $self = shift;
    my $attr = lc shift;
    my $old = $self->{$attr};
    if (@_) {
	$self->{$attr} = $_[0];
    }
    $old;
}



=item $h->content()

Returns the content of this element.  The content is represented as a
reference to an array of text segments and references to other
HTML::Element objects.

=cut

sub content
{
    shift->{'_content'};
}



=item $h->is_empty()

Returns true if there is no content.

=cut

sub is_empty
{
    my $self = shift;
    !exists($self->{'_content'}) || !@{$self->{'_content'}};
}



=item $h->insert_element($element, $implicit)

Inserts a new element at current position and updates pos() to point
to the inserted element.  Returns $element.

=cut

sub insert_element
{
    my($self, $tag, $implicit) = @_;
    my $e;
    if (ref $tag) {
	$e = $tag;
	$tag = $e->tag;
    } else {
	$e = new HTML::Element $tag;
    }
    $e->{'_implicit'} = 1 if $implicit;
    my $pos = $self->{'_pos'};
    $pos = $self unless defined $pos;
    $pos->push_content($e);
    unless ($emptyElement{$tag}) {
	$self->{'_pos'} = $e;
	$pos = $e;
    }
    $pos;
}


=item $h->push_content($element_or_text,...)

Adds to the content of the element.  The content should be a text
segment (scalar) or a reference to a HTML::Element object.

=cut

sub push_content
{
    my $self = shift;
    $self->{'_content'} = [] unless exists $self->{'_content'};
    my $content = $self->{'_content'};
    for (@_) {
	if (ref $_) {
	    $_->{'_parent'} = $self;
	    push(@$content, $_);
	} else {
	    # The current element is a text segment
	    if (@$content && !ref $content->[-1]) {
		# last content element is also text segment
		$content->[-1] .= $_;
	    } else {
		push(@$content, $_);
	    }
	}
    }
    $self;
}



=item $h->delete_content()

Clears the content.

=cut

sub delete_content
{
    my $self = shift;
    for (@{$self->{'_content'}}) {
	$_->delete if ref $_;
    }
    delete $self->{'_content'};
    $self;
}



=item $h->delete()

Frees memory associated with the element and all children.  This is
needed because perl's reference counting does not work since we use
circular references.

=cut
#'

sub delete
{
    $_[0]->delete_content;
    delete $_[0]->{'_parent'};
    delete $_[0]->{'_pos'};
    $_[0] = undef;
}



=item $h->traverse(\&callback, [$ignoretext])

Traverse the element and all of its children.  For each node visited, the
callback routine is called with the node, a startflag and the depth as
arguments.  If the $ignoretext parameter is true, then the callback
will not be called for text content.  The flag is 1 when we enter a
node and 0 when we leave the node.

If the returned value from the callback is false then we will not
traverse the children.

=cut

sub traverse
{
    my($self, $callback, $ignoretext, $depth) = @_;
    $depth ||= 0;

    if (&$callback($self, 1, $depth)) {
	for (@{$self->{'_content'}}) {
	    if (ref $_) {
		$_->traverse($callback, $ignoretext, $depth+1);
	    } else {
		&$callback($_, 1, $depth+1) unless $ignoretext;
	    }
	}
	&$callback($self, 0, $depth) unless $emptyElement{$self->{'_tag'}};
    }
    $self;
}



=item $h->extract_links([@wantedTypes])

Returns links found by traversing the element and all of its children.
The return value is a reference to an array.  Each element of the
array is an array with 2 values; the link value and a reference to the
corresponding element.

You might specify that you just want to extract some types of links.
For instance if you only want to extract <a href="..."> and <img
src="..."> links you might code it like this:

  for (@{ $e->extract_links(qw(a img)) }) {
      ($link, $linkelem) = @$_;
      ...
  }

=cut

sub extract_links
{
    my $self = shift;
    my %wantType; @wantType{map { lc $_ } @_} = (1) x @_;
    my $wantType = scalar(@_);
    my @links;
    $self->traverse(
	sub {
	    my($self, $start, $depth) = @_;
	    return 1 unless $start;
	    my $tag = $self->{'_tag'};
	    return 1 if $wantType && !$wantType{$tag};
	    my $attr = $linkElements{$tag};
	    return 1 unless defined $attr;
	    $attr = [$attr] unless ref $attr;
            for (@$attr) {
	       my $val = $self->attr($_);
	       push(@links, [$val, $self]) if defined $val;
            }
	    1;
	}, 'ignoretext');
    \@links;
}



=item $h->dump()

Prints the element and all its children to STDOUT.  Mainly useful for
debugging.  The structure of the document is shown by indentation (no
end tags).

=cut

sub dump
{
    my $self = shift;
    my $depth = shift || 0;
    print STDERR "  " x $depth;
    print STDERR $self->starttag, "\n";
    for (@{$self->{'_content'}}) {
	if (ref $_) {
	    $_->dump($depth+1);
	} else {
	    print STDERR "  " x ($depth + 1);
	    print STDERR qq{"$_"\n};
	}
    }
}



=item $h->as_HTML()

Returns a string (the HTML document) that represents the element and
its children.

=cut

sub as_HTML
{
    my $self = shift;
    my @html = ();
    $self->traverse(
        sub {
	    my($node, $start, $depth) = @_;
	    if (ref $node) {
		my $tag = $node->tag;
		if ($start) {
		    push(@html, $node->starttag);
		} elsif (not ($emptyElement{$tag} or $optionalEndTag{$tag})) {
		    push(@html, $node->endtag);
		}
	    } else {
		# simple text content
		HTML::Entities::encode_entities($node, "<>&");
		push(@html, $node);
	    }
        }
    );
    join('', @html, "\n");
}

sub format
{
    my($self, $formatter) = @_;
    unless (defined $formatter) {
	require HTML::FormatText;
	$formatter = new HTML::FormatText;
    }
    $formatter->format($self);
}


1;

__END__

=back

=head1 BUGS

If you want to free the memory assosiated with a tree built of
HTML::Element nodes then you will have to delete it explicitly.  The
reason for this is that perl currently has no proper garbage
collector, but depends on reference counts in the objects.  This
scheme fails because the parse tree contains circular references
(parents have references to their children and children have a
reference to their parent).

=head1 SEE ALSO

L<HTML::AsSubs>

=head1 COPYRIGHT

Copyright 1995-1997 Gisle Aas.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一本一道综合狠狠老| 制服.丝袜.亚洲.中文.综合| 欧美xxxx老人做受| 免费观看一级特黄欧美大片| 91麻豆高清视频| 性感美女久久精品| 欧美一级免费大片| 国产91精品久久久久久久网曝门| 久久久另类综合| 色8久久人人97超碰香蕉987| 亚洲一区中文在线| 国产亚洲婷婷免费| 在线观看一区二区精品视频| 美女在线一区二区| 成人欧美一区二区三区视频网页 | 国产美女久久久久| 在线播放91灌醉迷j高跟美女| 亚洲精品在线三区| 蜜臀av一区二区在线免费观看| 91一区二区三区在线播放| 国产激情视频一区二区三区欧美| 国产欧美一区视频| 欧美另类高清zo欧美| 国产成人免费视频网站| 亚洲午夜在线视频| 国产欧美日韩在线观看| 欧美日本一区二区| 在线一区二区三区四区五区 | 色婷婷av一区二区三区软件 | 亚洲成年人影院| 国产日产欧美精品一区二区三区| 成人午夜视频在线观看| 麻豆久久一区二区| 婷婷开心激情综合| 亚洲夂夂婷婷色拍ww47| 中文字幕在线一区免费| 久久久蜜桃精品| 久久夜色精品一区| 精品国产凹凸成av人导航| 91精品婷婷国产综合久久性色| 日本国产一区二区| 欧美性猛片xxxx免费看久爱| 色哟哟国产精品免费观看| 一本大道久久a久久精二百| 91一区在线观看| 欧美午夜电影一区| 91精品国产美女浴室洗澡无遮挡| 在线不卡的av| 国产日韩精品久久久| 国产精品电影一区二区| 午夜久久久久久久久久一区二区| 亚欧色一区w666天堂| 久久精品国产99久久6| 成人av在线一区二区| 欧美情侣在线播放| 日本一区二区高清| 香蕉久久一区二区不卡无毒影院| 美女www一区二区| 96av麻豆蜜桃一区二区| 日韩欧美一区二区免费| 中文字幕在线一区| 蜜桃av噜噜一区二区三区小说| 国产成人午夜高潮毛片| 制服丝袜日韩国产| 有码一区二区三区| 成人黄色国产精品网站大全在线免费观看| 色噜噜狠狠色综合中国| www久久久久| 免费人成网站在线观看欧美高清| youjizz久久| 国产精品久久久久久亚洲伦| 视频一区二区三区入口| 欧美视频一区在线| 一区二区三区免费看视频| 成人免费视频caoporn| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 成人av免费在线观看| 欧美国产一区二区| 国产成人av电影在线播放| 久久综合久久鬼色中文字| 午夜欧美在线一二页| 欧美三级视频在线| 三级精品在线观看| 日韩免费性生活视频播放| 视频在线观看一区二区三区| 91麻豆视频网站| 一区二区三区在线免费观看| www.久久精品| 亚洲国产一区二区三区| 欧美一区二区三区在线看| 九九精品一区二区| 中文字幕二三区不卡| 色老综合老女人久久久| 中文字幕在线播放不卡一区| 欧美日韩在线三区| 国产不卡视频在线播放| 亚洲激情在线激情| 国产午夜一区二区三区| 欧美日韩在线不卡| 亚洲一区二区三区中文字幕| 欧美顶级少妇做爰| 国产成人免费高清| 久久成人免费网| 偷拍自拍另类欧美| 亚洲图片欧美色图| 亚洲欧洲在线观看av| 国产喂奶挤奶一区二区三区| 欧美日本韩国一区二区三区视频 | 99re在线视频这里只有精品| 精品制服美女丁香| 丝袜亚洲精品中文字幕一区| 亚洲欧美日韩久久精品| 国产人妖乱国产精品人妖| 日韩欧美中文字幕制服| 欧美精品vⅰdeose4hd| 欧美欧美欧美欧美首页| 欧美曰成人黄网| 欧美午夜精品一区二区三区| 91精品91久久久中77777| 91小视频免费看| 欧美性极品少妇| 777xxx欧美| 国产亚洲欧美色| 亚洲色图清纯唯美| 亚洲国产综合在线| 久久精品国产亚洲5555| 国产精品亚洲第一区在线暖暖韩国 | 天天色天天操综合| 日本成人中文字幕| 国产伦精一区二区三区| 成人动漫一区二区在线| 91丨九色丨黑人外教| 欧美电影在线免费观看| 精品国产在天天线2019| 日韩久久一区二区| 日本最新不卡在线| 99国产精品久| 欧美成人官网二区| 国产精品午夜在线| 免费观看日韩av| 欧美婷婷六月丁香综合色| 精品福利在线导航| 亚洲第四色夜色| 91精品福利在线| 中文字幕一区二区三区在线不卡 | 国产精品大尺度| 日本成人在线视频网站| 在线视频欧美区| 国产精品久久久久一区| 国内精品视频666| 欧美日韩精品久久久| 一区二区三区波多野结衣在线观看 | 蜜桃视频免费观看一区| 欧美一a一片一级一片| 亚洲日本免费电影| www.66久久| 国产精品不卡一区二区三区| 国内精品在线播放| 精品电影一区二区三区| 日本美女一区二区三区| 3d成人h动漫网站入口| 亚洲国产成人av好男人在线观看| 91小视频免费观看| 一区二区国产视频| 欧美日韩国产三级| 天使萌一区二区三区免费观看| 欧美日韩一区二区三区在线看 | 亚洲综合偷拍欧美一区色| a在线播放不卡| 一区二区三区免费看视频| 色呦呦国产精品| 午夜不卡av在线| 国产欧美精品一区| 91激情五月电影| 久久国产夜色精品鲁鲁99| 中文字幕av一区二区三区免费看| 成人av资源在线| 污片在线观看一区二区| 久久久久久麻豆| 91麻豆文化传媒在线观看| 免费精品99久久国产综合精品| 中文字幕欧美区| 欧美日韩一本到| 一本大道综合伊人精品热热| 免费在线观看不卡| 亚洲国产欧美日韩另类综合| 精品99一区二区| 7777女厕盗摄久久久| av男人天堂一区| 国产精品一品视频| 石原莉奈在线亚洲三区| 中文字幕日韩一区| 久久久久久99久久久精品网站| 欧美女孩性生活视频| 91成人免费网站| 91视频一区二区| 99久久国产免费看| 成人免费福利片| 国产福利一区在线观看| 国产精品资源在线|