line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::StickyQuery; |
2
|
|
|
|
|
|
|
# $Id: StickyQuery.pm,v 1.10 2003/10/08 09:46:55 ikebe Exp $ |
3
|
14
|
|
|
14
|
|
26525
|
use strict; |
|
14
|
|
|
|
|
36
|
|
|
14
|
|
|
|
|
639
|
|
4
|
14
|
|
|
14
|
|
14867
|
use parent qw(HTML::Parser); |
|
14
|
|
|
|
|
5983
|
|
|
14
|
|
|
|
|
116
|
|
5
|
14
|
|
|
14
|
|
183011
|
use URI; |
|
14
|
|
|
|
|
234889
|
|
|
14
|
|
|
|
|
1951
|
|
6
|
14
|
|
|
14
|
|
1594
|
use vars qw($VERSION); |
|
14
|
|
|
|
|
7002
|
|
|
14
|
|
|
|
|
30730
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.13'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
15
|
|
|
15
|
1
|
873
|
my $class = shift; |
12
|
15
|
50
|
|
|
|
137
|
_croak("odd number of " . __PACKAGE__ . "->new arguments") if @_ % 2; |
13
|
15
|
|
|
|
|
546
|
my %args = @_; |
14
|
15
|
|
|
|
|
168
|
my $self = bless { |
15
|
|
|
|
|
|
|
keep_original => 1, |
16
|
|
|
|
|
|
|
abs => 0, |
17
|
|
|
|
|
|
|
regexp => undef, |
18
|
|
|
|
|
|
|
}, $class; |
19
|
15
|
|
|
|
|
77
|
foreach my $key(qw(keep_original abs regexp)) { |
20
|
45
|
100
|
|
|
|
8651
|
$self->{$key} = $args{$key} if exists $args{$key}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
# backward compat |
23
|
15
|
50
|
|
|
|
66
|
$self->{keep_original} = !$args{override} if $args{override}; |
24
|
15
|
|
|
|
|
260
|
$self->SUPER::init; |
25
|
15
|
|
|
|
|
1400
|
$self->boolean_attribute_value('__BOOLEAN__'); |
26
|
15
|
|
|
|
|
68
|
$self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub sticky { |
30
|
15
|
|
|
15
|
1
|
24401
|
my $self = shift; |
31
|
15
|
|
|
|
|
74
|
my %args = @_; |
32
|
15
|
100
|
|
|
|
103
|
if (ref $args{param} eq 'HASH') { |
|
|
50
|
|
|
|
|
|
33
|
11
|
|
|
|
|
75
|
$self->{param} = $args{param} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif ($args{param}->can("param")) { |
36
|
4
|
|
|
|
|
72
|
my %data = (); |
37
|
4
|
|
|
|
|
17
|
for my $key($args{param}->param) { |
38
|
5
|
|
|
|
|
64
|
my @val = $args{param}->param($key); |
39
|
5
|
100
|
|
|
|
107
|
$data{$key} = scalar(@val) > 1 ? \@val : $val[0]; |
40
|
|
|
|
|
|
|
} |
41
|
4
|
|
|
|
|
70
|
$self->{param} = \%data; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
15
|
100
|
|
|
|
77
|
if ($args{sticky_keys}) { |
45
|
1
|
|
|
|
|
3
|
my %sticky = map { $_ => 1 } @{$args{sticky_keys}}; |
|
2
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
46
|
1
|
|
|
|
|
2
|
my %new; |
47
|
1
|
|
|
|
|
2
|
while (my($k, $v) = each %{$self->{param}}) { |
|
4
|
|
|
|
|
12
|
|
48
|
3
|
100
|
|
|
|
9
|
$new{$k} = $v if $sticky{$k} |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
|
|
|
3
|
$self->{param} = \%new; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
47
|
$self->{output} = ""; |
54
|
15
|
100
|
|
|
|
61
|
if ($args{file}) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
55
|
13
|
|
|
|
|
106
|
$self->parse_file($args{file}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($args{scalarref}) { |
58
|
1
|
|
|
|
|
2
|
$self->parse(${$args{scalarref}}); |
|
1
|
|
|
|
|
31
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ($args{arrayref}) { |
61
|
1
|
|
|
|
|
1
|
foreach my $line(@{$args{arrayref}}) { |
|
1
|
|
|
|
|
51
|
|
62
|
1
|
|
|
|
|
31
|
$self->parse($line); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
15
|
|
|
|
|
578
|
return $self->{output}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub output { |
69
|
24
|
|
|
24
|
0
|
108
|
my $self = shift; |
70
|
24
|
|
|
|
|
208
|
return $self->{output}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub start { |
74
|
25
|
|
|
25
|
1
|
1553
|
my ($self, $tagname, $attr, $attrseq, $orig) = @_; |
75
|
25
|
100
|
|
|
|
84
|
if ($tagname ne 'a') { |
76
|
7
|
|
|
|
|
18
|
$self->{output} .= $orig; |
77
|
7
|
|
|
|
|
2560
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
18
|
50
|
|
|
|
83
|
unless(exists $attr->{href}) { |
81
|
0
|
|
|
|
|
0
|
$self->{output} .= $orig; |
82
|
0
|
|
|
|
|
0
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
18
|
|
|
|
|
195
|
my $u = URI->new($attr->{href}); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# skip absolute URI |
87
|
18
|
100
|
100
|
|
|
96257
|
if (!$self->{abs} && $u->scheme) { |
88
|
1
|
|
|
|
|
173
|
$self->{output} .= $orig; |
89
|
1
|
|
|
|
|
26
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
# when URI has other scheme (ie. mailto ftp ..) |
92
|
17
|
50
|
66
|
|
|
2117
|
if(defined($u->scheme) && $u->scheme !~ m/^https?/) { |
93
|
0
|
|
|
|
|
0
|
$self->{output} .= $orig; |
94
|
0
|
|
|
|
|
0
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
17
|
100
|
100
|
|
|
330
|
if (!$self->{regexp} || $u->path =~ m/$self->{regexp}/) { |
98
|
16
|
100
|
|
|
|
91
|
if ($self->{keep_original}) { |
99
|
15
|
|
|
|
|
41
|
my %original; |
100
|
15
|
|
|
|
|
129
|
my @original = $u->query_form; |
101
|
15
|
|
|
|
|
515
|
while (my ($key, $val) = splice(@original, 0, 2)) { |
102
|
4
|
100
|
|
|
|
20
|
if (exists $original{$key}) { |
103
|
1
|
50
|
|
|
|
3
|
if (ref $original{$key} eq 'ARRAY') { |
104
|
0
|
|
|
|
|
0
|
push @{$original{$key}}, $val; |
|
0
|
|
|
|
|
0
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
1
|
|
|
|
|
10
|
$original{$key} = [ $original{$key}, $val ]; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
3
|
|
|
|
|
20
|
$original{$key} = $val; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
15
|
|
|
|
|
51
|
my %merged = (%original, %{$self->{param}}); |
|
15
|
|
|
|
|
97
|
|
115
|
15
|
|
|
|
|
80
|
$u->query_form(%merged); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
1
|
|
|
|
|
2
|
$u->query_form(%{$self->{param}}); |
|
1
|
|
|
|
|
6
|
|
119
|
|
|
|
|
|
|
} |
120
|
16
|
|
|
|
|
1361
|
$self->{output} .= qq{<$tagname}; |
121
|
|
|
|
|
|
|
# save attr order. |
122
|
16
|
|
|
|
|
51
|
foreach my $key(@$attrseq) { |
123
|
18
|
100
|
|
|
|
86
|
if ($key eq "href"){ |
|
|
100
|
|
|
|
|
|
124
|
16
|
|
|
|
|
172
|
$self->{output} .= sprintf(qq{ href="%s"}, |
125
|
|
|
|
|
|
|
$self->escapeHTML($u->as_string)); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif ($attr->{$key} eq '__BOOLEAN__') { |
128
|
1
|
|
|
|
|
5
|
$self->{output} .= " $key"; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
else { |
131
|
1
|
|
|
|
|
40
|
$self->{output} .= sprintf(qq{ $key="%s"}, |
132
|
|
|
|
|
|
|
$self->escapeHTML($attr->{$key})); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
16
|
|
|
|
|
48
|
$self->{output} .= '>'; |
136
|
16
|
|
|
|
|
308
|
return; |
137
|
|
|
|
|
|
|
} |
138
|
1
|
|
|
|
|
66
|
$self->{output} .= $orig; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub process { |
144
|
1
|
|
|
1
|
1
|
131
|
my($self, $text, $orig) = @_; |
145
|
1
|
|
|
|
|
13
|
$self->{output} .= $orig; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub end { |
149
|
8
|
|
|
8
|
1
|
18
|
my ($self, $tagname, $orig) = @_; |
150
|
8
|
|
|
|
|
76
|
$self->{output} .= $orig; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub text { |
154
|
21
|
|
|
21
|
1
|
112
|
my ($self, $orig) = @_; |
155
|
21
|
|
|
|
|
180
|
$self->{output} .= $orig; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub comment { |
159
|
1
|
|
|
1
|
1
|
8
|
my ($self, $orig) = @_; |
160
|
1
|
|
|
|
|
3
|
$self->{output} .= qq//; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub declaration { |
164
|
2
|
|
|
2
|
1
|
185
|
my ($self, $orig) = @_; |
165
|
2
|
|
|
|
|
31
|
$self->{output} .= qq//; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _croak { |
169
|
0
|
|
|
0
|
|
0
|
require Carp; |
170
|
0
|
|
|
|
|
0
|
Carp::croak(@_); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub escapeHTML { |
174
|
17
|
|
|
17
|
0
|
137
|
my $self = shift; |
175
|
17
|
|
|
|
|
43
|
my $text = shift; |
176
|
17
|
|
|
|
|
67
|
$text =~ s/&/&/g; |
177
|
17
|
|
|
|
|
43
|
$text =~ s/"/"/g; |
178
|
17
|
|
|
|
|
50
|
$text =~ s/</g; |
179
|
17
|
|
|
|
|
40
|
$text =~ s/>/>/g; |
180
|
17
|
|
|
|
|
145
|
return $text; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
__END__ |