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