| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# SOAP::Lite style Hoobot::Page |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Hoobot::Page; |
|
4
|
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
25
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
119
|
|
|
6
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
80
|
|
|
7
|
4
|
|
|
4
|
|
2026
|
use Hoobot; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
118
|
|
|
8
|
4
|
|
|
4
|
|
6559
|
use URI; |
|
|
4
|
|
|
|
|
39076
|
|
|
|
4
|
|
|
|
|
148
|
|
|
9
|
4
|
|
|
4
|
|
4299
|
use HTTP::Request::Common; |
|
|
4
|
|
|
|
|
113508
|
|
|
|
4
|
|
|
|
|
356
|
|
|
10
|
4
|
|
|
4
|
|
5819
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw/Hoobot/; |
|
13
|
|
|
|
|
|
|
my $parser; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# accessor |
|
16
|
|
|
|
|
|
|
sub page { |
|
17
|
|
|
|
|
|
|
my $self = shift; |
|
18
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
19
|
|
|
|
|
|
|
return $self->{uri}{page} unless @_; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$self->{uri}{page} = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $self; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# accessor |
|
27
|
|
|
|
|
|
|
sub skin { |
|
28
|
|
|
|
|
|
|
my $self = shift; |
|
29
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
30
|
|
|
|
|
|
|
return $self->{uri}{skin} unless @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$self->{uri}{skin} = shift; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $self; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# accessor |
|
38
|
|
|
|
|
|
|
sub site { |
|
39
|
|
|
|
|
|
|
my $self = shift; |
|
40
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
41
|
|
|
|
|
|
|
unless (@_) { |
|
42
|
|
|
|
|
|
|
return $self->{uri}{site} if defined $self->{uri}{site}; |
|
43
|
|
|
|
|
|
|
return $self->{uri}{site} = 'h2g2'; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{uri}{site} = shift; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $self; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# accessor |
|
52
|
|
|
|
|
|
|
sub method { |
|
53
|
|
|
|
|
|
|
my $self = shift; |
|
54
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
55
|
|
|
|
|
|
|
unless (@_) { |
|
56
|
|
|
|
|
|
|
return $self->{method} if defined $self->{method}; |
|
57
|
|
|
|
|
|
|
return $self->{method} = 'GET'; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$self->{method} = shift; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return $self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# method |
|
66
|
|
|
|
|
|
|
sub clear_params { |
|
67
|
|
|
|
|
|
|
my $self = shift; |
|
68
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$self->{params} = undef; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return $self; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# accessor: add deletion etc |
|
76
|
|
|
|
|
|
|
sub param { |
|
77
|
|
|
|
|
|
|
my $self = shift; |
|
78
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->{params} ||= []; |
|
81
|
|
|
|
|
|
|
push @{$self->{params}}, shift, shift; # hehe, fix this code! |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return $self; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# accessor |
|
87
|
|
|
|
|
|
|
sub response { |
|
88
|
|
|
|
|
|
|
my $self = shift; |
|
89
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
90
|
|
|
|
|
|
|
return $self->{response} unless @_; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$self->{response} = shift; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $self; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# accessor |
|
98
|
|
|
|
|
|
|
sub document { |
|
99
|
|
|
|
|
|
|
my $self = shift; |
|
100
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
101
|
|
|
|
|
|
|
unless (@_) { |
|
102
|
|
|
|
|
|
|
return $self->{document} if defined $self->{document}; |
|
103
|
|
|
|
|
|
|
return $self->xml_parse->{document}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$self->{document} = shift; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return $self; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub prepare_update { |
|
112
|
|
|
|
|
|
|
my $self = shift; |
|
113
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return $self; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# method (do the actual downloading thing) |
|
119
|
|
|
|
|
|
|
sub update { |
|
120
|
|
|
|
|
|
|
my $self = shift; |
|
121
|
|
|
|
|
|
|
$self = $self->new unless ref $self; # does this make sense?! |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->prepare_update; # setup anything necessary before updating |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $url = URI->new($self->host); |
|
126
|
|
|
|
|
|
|
$url->scheme or $url->scheme('http'); |
|
127
|
|
|
|
|
|
|
$url->path_segments( |
|
128
|
|
|
|
|
|
|
$url->path_segments, |
|
129
|
|
|
|
|
|
|
'dna', |
|
130
|
|
|
|
|
|
|
$self->site ? $self->site : (), |
|
131
|
|
|
|
|
|
|
$self->skin ? $self->skin : (), |
|
132
|
|
|
|
|
|
|
$self->page || '', |
|
133
|
|
|
|
|
|
|
); |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$url->query_form(@{$self->{params}}) |
|
136
|
|
|
|
|
|
|
if lc $self->method eq 'get' and ref $self->{params} eq 'ARRAY'; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
print STDERR "Update requested: (details follow)\n"; |
|
139
|
|
|
|
|
|
|
print STDERR " host: ", $self->host || '', "\n"; |
|
140
|
|
|
|
|
|
|
print STDERR " site: ", $self->site || '', "\n"; |
|
141
|
|
|
|
|
|
|
print STDERR " skin: ", $self->skin || '', "\n"; |
|
142
|
|
|
|
|
|
|
print STDERR " page: ", $self->page || '', "\n"; |
|
143
|
|
|
|
|
|
|
print STDERR " url: ", $url, "\n"; |
|
144
|
|
|
|
|
|
|
print STDERR " method: ", $self->method || '', "\n"; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $request; |
|
147
|
|
|
|
|
|
|
if (lc($self->method) eq 'post') { |
|
148
|
|
|
|
|
|
|
$request = POST $url, $self->{params}; |
|
149
|
|
|
|
|
|
|
} else { |
|
150
|
|
|
|
|
|
|
$request = GET $url; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $response = $self->ua->request($request); |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$self->response($response); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$self->post_update(); # setup anything necessary after updating |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
return $self; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# method |
|
163
|
|
|
|
|
|
|
sub post_update { |
|
164
|
|
|
|
|
|
|
my $self = shift; |
|
165
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
return $self; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
# |
|
170
|
|
|
|
|
|
|
# method: currently extracts the XML, change to callback? |
|
171
|
|
|
|
|
|
|
sub xml_parse { |
|
172
|
|
|
|
|
|
|
my $self = shift; |
|
173
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
if (lc($self->response->content_type) eq 'text/html') { |
|
176
|
|
|
|
|
|
|
$parser ||= XML::LibXML->new; |
|
177
|
|
|
|
|
|
|
$self->document( |
|
178
|
|
|
|
|
|
|
$parser->parse_html_string( |
|
179
|
|
|
|
|
|
|
$self->response->content, |
|
180
|
|
|
|
|
|
|
), |
|
181
|
|
|
|
|
|
|
); |
|
182
|
|
|
|
|
|
|
} elsif (lc($self->response->content_type) eq 'text/xml') { |
|
183
|
|
|
|
|
|
|
$parser ||= XML::LibXML->new; |
|
184
|
|
|
|
|
|
|
$self->document( |
|
185
|
|
|
|
|
|
|
$parser->parse_string( |
|
186
|
|
|
|
|
|
|
$self->response->content, |
|
187
|
|
|
|
|
|
|
), |
|
188
|
|
|
|
|
|
|
); |
|
189
|
|
|
|
|
|
|
} else { |
|
190
|
|
|
|
|
|
|
warn "Couldn't parse document\n"; |
|
191
|
|
|
|
|
|
|
print STDERR $self->response->as_string, "\n"; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
return $self; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |