/usr/share/perl5/HTML/TokeParser/Simple/Token/Tag/End.pm is in libhtml-tokeparser-simple-perl 3.16-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | package HTML::TokeParser::Simple::Token::Tag::End;
use strict;
our $VERSION = '3.16';
use base 'HTML::TokeParser::Simple::Token::Tag';
my %TOKEN = (
tag => 1,
text => 2
);
# in order to maintain the 'drop-in replacement' ability with HTML::TokeParser,
# we cannot alter the array refs. Thus we must store instance data here. Ugh.
my %INSTANCE;
sub _init {
my $self = shift;
if ('E' eq $self->[0]) {
$INSTANCE{$self}{offset} = 0;
$INSTANCE{$self}{tag} = $self->[1];
}
else {
$INSTANCE{$self}{offset} = -1;
my $tag = $self->[0];
$tag =~ s/^\///;
$INSTANCE{$self}{tag} = $tag;
}
return $self;
}
sub _get_offset { return $INSTANCE{+shift}{offset} }
sub _get_text { return shift->[-1] }
sub _get_tag {
my $self = shift;
return $INSTANCE{$self}{tag};
}
sub DESTROY { delete $INSTANCE{+shift} }
sub rewrite_tag {
my $self = shift;
# capture the final slash if the tag is self-closing
my ($self_closing) = $self->_get_text =~ m{(\s?/)>$};
$self_closing ||= '';
my $first = $self->is_end_tag ? '/' : '';
my $tag = sprintf '<%s%s%s>', $first, $self->get_tag, $self_closing;
$self->_set_text($tag);
return $self;
}
sub return_text {
require Carp;
Carp::carp('return_text() is deprecated. Use as_is() instead');
goto &as_is;
}
sub as_is {
return shift->_get_text;
}
sub get_tag {
return shift->_get_tag;
}
# is_foo methods
sub is_tag {
my $self = shift;
return $self->is_end_tag( @_ );
}
sub is_end_tag {
my ($self, $tag) = @_;
return $tag ? $self->_match_tag($tag) : 1;
}
sub _match_tag {
my ($self, $tag) = @_;
if ('Regexp' eq ref $tag) {
return $self->_get_tag =~ $tag;
}
else {
$tag = lc $tag;
$tag =~ s/^\///;
return $self->_get_tag eq $tag;
}
}
1;
__END__
=head1 NAME
HTML::TokeParser::Simple::Token::Tag::End - Token.pm "end tag" class.
=head1 SYNOPSIS
use HTML::TokeParser::Simple;
my $p = HTML::TokeParser::Simple->new( $somefile );
while ( my $token = $p->get_token ) {
# This prints all text in an HTML doc (i.e., it strips the HTML)
next unless $token->is_text;
print $token->as_is;
}
=head1 DESCRIPTION
This class does most of the heavy lifting for C<HTML::TokeParser::Simple>. See
the C<HTML::TokeParser::Simple> docs for details.
=head1 OVERRIDDEN METHODS
=over 4
=item * as_is
=item * get_tag
=item * is_end_tag
=item * is_tag
=item * return_text
=item * rewrite_tag
=back
=cut
|