line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::WidgetValidator::HTMLParser;
|
2
|
45
|
|
|
45
|
|
244
|
use warnings;
|
|
45
|
|
|
|
|
78
|
|
|
45
|
|
|
|
|
1230
|
|
3
|
45
|
|
|
45
|
|
223
|
use strict;
|
|
45
|
|
|
|
|
84
|
|
|
45
|
|
|
|
|
1184
|
|
4
|
45
|
|
|
45
|
|
49980
|
use HTML::Parser;
|
|
45
|
|
|
|
|
396587
|
|
|
45
|
|
|
|
|
1957
|
|
5
|
45
|
|
|
45
|
|
29075
|
use HTML::WidgetValidator::HTMLElement;
|
|
45
|
|
|
|
|
160
|
|
|
45
|
|
|
|
|
357
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new {
|
8
|
1
|
|
|
1
|
0
|
4
|
my ($class, %args) = @_;
|
9
|
1
|
|
|
|
|
5
|
my $self = bless { %args }, $class;
|
10
|
1
|
|
|
|
|
7
|
$self->{parser} = HTML::Parser->new(
|
11
|
|
|
|
|
|
|
api_version => 3,
|
12
|
|
|
|
|
|
|
handlers => {
|
13
|
|
|
|
|
|
|
start => [$self->starthandler, 'text, tagname, attr'],
|
14
|
|
|
|
|
|
|
end => [$self->endhandler, 'text, tagname'],
|
15
|
|
|
|
|
|
|
text => [$self->texthandler, 'text'],
|
16
|
|
|
|
|
|
|
comment => [$self->texthandler, 'text'],
|
17
|
|
|
|
|
|
|
default => [$self->defaulthandler, 'event, text'],
|
18
|
|
|
|
|
|
|
},
|
19
|
|
|
|
|
|
|
);
|
20
|
1
|
|
|
|
|
94
|
$self->{parser}->empty_element_tags( 1 );
|
21
|
1
|
|
|
|
|
13
|
return $self;
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub parse {
|
25
|
0
|
|
|
0
|
0
|
0
|
my ($self,$html) = @_;
|
26
|
0
|
|
|
|
|
0
|
$self->{result} = [];
|
27
|
0
|
|
|
|
|
0
|
$self->{parser}->parse($html);
|
28
|
0
|
|
|
|
|
0
|
return $self->{result};
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub starthandler {
|
32
|
1
|
|
|
1
|
0
|
2
|
my $self = shift;
|
33
|
|
|
|
|
|
|
return sub {
|
34
|
0
|
|
|
0
|
|
0
|
my ($text, $tag, $attr) = @_;
|
35
|
0
|
|
|
|
|
0
|
$text =~ s|/>$|>|;
|
36
|
0
|
|
|
|
|
0
|
push @{$self->{result}},
|
|
0
|
|
|
|
|
0
|
|
37
|
|
|
|
|
|
|
HTML::WidgetValidator::HTMLElement->new(
|
38
|
|
|
|
|
|
|
type=>'start',name=>$tag,attr=>$attr,text=>$text );
|
39
|
|
|
|
|
|
|
}
|
40
|
1
|
|
|
|
|
14
|
}
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub endhandler {
|
43
|
1
|
|
|
1
|
0
|
2
|
my $self = shift;
|
44
|
|
|
|
|
|
|
return sub {
|
45
|
0
|
|
|
0
|
|
0
|
my ($text, $tag) = @_;
|
46
|
0
|
|
|
|
|
0
|
push @{$self->{result}},
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
HTML::WidgetValidator::HTMLElement->new(
|
48
|
|
|
|
|
|
|
type=>'end',name=>$tag, text=>"$tag>" );
|
49
|
|
|
|
|
|
|
}
|
50
|
1
|
|
|
|
|
9
|
}
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub texthandler {
|
53
|
2
|
|
|
2
|
0
|
4
|
my $self = shift;
|
54
|
|
|
|
|
|
|
return sub {
|
55
|
0
|
|
|
0
|
|
0
|
my ($text) = @_;
|
56
|
0
|
0
|
|
|
|
0
|
return if( $text =~ /^\s+$/s );
|
57
|
0
|
|
|
|
|
0
|
push @{$self->{result}},
|
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
HTML::WidgetValidator::HTMLElement->new(
|
59
|
|
|
|
|
|
|
type=>'text',text=>$text );
|
60
|
|
|
|
|
|
|
}
|
61
|
2
|
|
|
|
|
15
|
}
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub defaulthandler {
|
64
|
1
|
|
|
1
|
0
|
2
|
my $self = shift;
|
65
|
1
|
|
|
0
|
|
17
|
return sub {};
|
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1;
|
69
|
|
|
|
|
|
|
__END__
|