| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- cperl -*- |
|
2
|
|
|
|
|
|
|
# copyright (C) 2005 Topia . all rights reserved. |
|
3
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it |
|
4
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
|
5
|
|
|
|
|
|
|
# $Id: TableListPage.pm 100 2005-02-04 19:19:55Z topia $ |
|
6
|
|
|
|
|
|
|
# $URL: file:///usr/minetools/svnroot/mixi/trunk/WWW-Mixi-OO/lib/WWW/Mixi/OO/TableListPage.pm $ |
|
7
|
|
|
|
|
|
|
package WWW::Mixi::OO::TableListPage; |
|
8
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
69
|
|
|
9
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
46
|
|
|
10
|
2
|
|
|
2
|
|
12
|
use URI; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
35
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use URI::QueryParam; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
48
|
|
|
12
|
2
|
|
|
2
|
|
11
|
use base qw(WWW::Mixi::OO::ListPage); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1563
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
WWW::Mixi::OO::TableListPage - WWW::Mixi::OO's Table style List Pages base class |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package WWW::Mixi::OO::Foo; |
|
21
|
|
|
|
|
|
|
use base qw(WWW::Mixi::OO::TableListPage); |
|
22
|
|
|
|
|
|
|
# some implementations... |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
table style list pages base class. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over 4 |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item parse |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
see parent class (L), |
|
37
|
|
|
|
|
|
|
and some implementation class. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item parse_navi_prev |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item parse_navi_current |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item parse_navi_next |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
parse previous(or current, or next) navigation. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
see some implementation class. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=back |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS MAYBE IMPLEMENTATION AT SUBCLASS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over 4 |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item parse_title |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
parse title message. return scalar or array of scalar. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub parse { |
|
62
|
0
|
|
|
0
|
1
|
|
my $body = shift->parse_body; |
|
63
|
0
|
0
|
|
|
|
|
return () unless defined $body; |
|
64
|
0
|
|
|
|
|
|
return @$body; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
foreach (qw(prev current next)) { |
|
68
|
0
|
0
|
|
0
|
1
|
|
eval <<"END"; |
|
|
0
|
0
|
|
0
|
1
|
|
|
|
|
0
|
0
|
|
0
|
1
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub parse_navi_$_ \{ |
|
70
|
|
|
|
|
|
|
my \$this = shift; |
|
71
|
|
|
|
|
|
|
my \$navi = \$this->parse_navi; |
|
72
|
|
|
|
|
|
|
return () unless defined \$navi; |
|
73
|
|
|
|
|
|
|
return () unless defined \$navi->{$_}; |
|
74
|
|
|
|
|
|
|
return \$navi->{$_}; |
|
75
|
|
|
|
|
|
|
\} |
|
76
|
|
|
|
|
|
|
END |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
these methods used from internal (such as subclass). |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 4 |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item parse_table |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item parse_navi |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item parse_body |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
cached parser methods for _parse_table, _parse_navi, _parse_body. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__PACKAGE__->mk_cached_parser(qw(table navi body)); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item _parse_table |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# subclass |
|
102
|
|
|
|
|
|
|
sub _parse_table { |
|
103
|
|
|
|
|
|
|
my $this = shift; |
|
104
|
|
|
|
|
|
|
return $this->SUPER::_parse_table(@_) if @_ == 1; # overridable |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my %options = @_; |
|
107
|
|
|
|
|
|
|
$this->SUPER::_parse_table(qr/.../); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return main table. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _parse_table { |
|
115
|
0
|
|
|
0
|
|
|
my $this = shift; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $part = $this->parse_extract_parts(shift); |
|
118
|
0
|
0
|
|
|
|
|
return () unless defined $part; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# split to each tables |
|
121
|
0
|
|
|
|
|
|
$this->_split_tables($part); |
|
122
|
0
|
|
|
|
|
|
return $part; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item _split_tables |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# subclass |
|
128
|
|
|
|
|
|
|
sub _split_tables { |
|
129
|
|
|
|
|
|
|
my ($this, $part) = @_; |
|
130
|
|
|
|
|
|
|
my @tables = /(...)/g; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# set tables |
|
133
|
|
|
|
|
|
|
$this->cache->{tables} = \@tables; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# set indecies to tables... |
|
136
|
|
|
|
|
|
|
$this->cache->{indecies}->{title} = 0; |
|
137
|
|
|
|
|
|
|
$this->cache->{indecies}->{navi} = 1; |
|
138
|
|
|
|
|
|
|
$this->cache->{indecies}->{body} = 2; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
split main tables to some parts. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _split_tables { |
|
146
|
0
|
|
|
0
|
|
|
my ($this, $part) = @_; |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $maybe_attrs_regex = $this->regex_parts->{html_maybe_attrs}; |
|
149
|
0
|
|
|
|
|
|
my @tables = $this->extract_balanced_html_parts( |
|
150
|
|
|
|
|
|
|
element => 'table', |
|
151
|
|
|
|
|
|
|
text => $part); |
|
152
|
0
|
|
|
|
|
|
$this->cache->{tables} = \@tables; |
|
153
|
0
|
|
|
|
|
|
$this->cache->{indecies}->{title} = 0; |
|
154
|
0
|
0
|
|
|
|
|
if (@tables > 2) { |
|
155
|
|
|
|
|
|
|
# remove no-need footer |
|
156
|
0
|
|
|
|
|
|
pop(@tables); |
|
157
|
0
|
|
|
|
|
|
$this->cache->{indecies}->{navi} = 1; |
|
158
|
0
|
|
|
|
|
|
$this->cache->{indecies}->{body} = 2; |
|
159
|
|
|
|
|
|
|
} else { |
|
160
|
0
|
|
|
|
|
|
$this->cache->{indecies}->{body} = 1; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item parse_table_item_with_index |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# call from subclass |
|
167
|
|
|
|
|
|
|
sub _parse_foo { |
|
168
|
|
|
|
|
|
|
my ($this, %options) = @_; |
|
169
|
|
|
|
|
|
|
my $part = $this->parse_table_item_with_index(0); |
|
170
|
|
|
|
|
|
|
return () unless defined $part; |
|
171
|
|
|
|
|
|
|
# ... |
|
172
|
|
|
|
|
|
|
return $1; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return split part with index. (maybe useless) |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub parse_table_item_with_index { |
|
180
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
181
|
0
|
|
|
|
|
|
$this->parse_table; |
|
182
|
0
|
|
|
|
|
|
return $this->cache->{tables}->[shift]; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item parse_table_item |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# call from subclass |
|
188
|
|
|
|
|
|
|
sub _parse_body { |
|
189
|
|
|
|
|
|
|
my ($this, %options) = @_; |
|
190
|
|
|
|
|
|
|
my $part = $this->parse_table_item('body'); |
|
191
|
|
|
|
|
|
|
return () unless defined $part; |
|
192
|
|
|
|
|
|
|
# ... |
|
193
|
|
|
|
|
|
|
return $1; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
return split part with keyword. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub parse_table_item { |
|
201
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
202
|
0
|
|
|
|
|
|
$this->parse_table; |
|
203
|
0
|
|
|
|
|
|
my $index = $this->cache->{indecies}->{+shift}; |
|
204
|
0
|
0
|
|
|
|
|
if (defined $index) { |
|
205
|
0
|
|
|
|
|
|
return $this->cache->{tables}->[$index]; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item parse_table_items |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# call from subclass |
|
212
|
|
|
|
|
|
|
my $table_count = $this->parse_table_items; |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
return split parts count. (maybe useless) |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub parse_table_items { |
|
219
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
220
|
0
|
|
|
|
|
|
$this->parse_table; |
|
221
|
0
|
|
|
|
|
|
return scalar @{$this->cache->{tables}}; |
|
|
0
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub _parse_navi { |
|
225
|
0
|
|
|
0
|
|
|
my $this = shift; |
|
226
|
0
|
|
|
|
|
|
my $part = $this->parse_table_item('navi'); |
|
227
|
0
|
0
|
|
|
|
|
return () unless defined $part; |
|
228
|
0
|
|
|
|
|
|
my $maybe_attrs_regex = $this->regex_parts->{html_maybe_attrs}; |
|
229
|
0
|
|
|
|
|
|
my $non_metas_regex = $this->regex_parts->{non_metas}; |
|
230
|
0
|
|
|
|
|
|
my $regex = qr| |
|
231
|
|
|
|
|
|
|
| |
|
232
|
|
|
|
|
|
|
(?:($non_metas_regex) )? |
|
233
|
|
|
|
|
|
|
($non_metas_regex) |
|
234
|
|
|
|
|
|
|
(?: ($non_metas_regex))? |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|iox; |
|
237
|
0
|
0
|
|
|
|
|
return () unless $part =~ m/$regex/; |
|
238
|
0
|
0
|
|
|
|
|
$this->_parse_navi_link('prev', $1, $2) if defined $1; |
|
239
|
0
|
0
|
|
|
|
|
$this->_parse_navi_link('next', $4, $5) if defined $4; |
|
240
|
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
my $navi_cache = $this->cache->{navi}->{current} = {}; |
|
242
|
0
|
|
|
|
|
|
$navi_cache->{subject} = $3; |
|
243
|
0
|
0
|
|
|
|
|
if ($3 =~ /(\d+)\D+(\d+)/) { |
|
244
|
0
|
|
|
|
|
|
$navi_cache->{start} = $1; |
|
245
|
0
|
|
|
|
|
|
$navi_cache->{end} = $2; |
|
246
|
|
|
|
|
|
|
} |
|
247
|
0
|
|
|
|
|
|
return $this->cache->{navi}; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item _parse_navi_link |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# call from subclass |
|
253
|
|
|
|
|
|
|
my %datas = $this->_parse_navi_link('current', 'href="..."', 'next page'); |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
standard navigation link parser. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub _parse_navi_link { |
|
260
|
0
|
|
|
0
|
|
|
my ($this, $genre, $attr, $value) = @_; |
|
261
|
0
|
|
|
|
|
|
my $link = $this->html_anchor_to_uri($attr); |
|
262
|
0
|
|
|
|
|
|
my $data = $this->cache->{navi}->{$genre} = { |
|
263
|
|
|
|
|
|
|
link => $link, |
|
264
|
|
|
|
|
|
|
$this->analyze_uri($link), |
|
265
|
|
|
|
|
|
|
}; |
|
266
|
0
|
|
|
|
|
|
$data->{subject} = $this->rewrite($value); |
|
267
|
0
|
0
|
|
|
|
|
if ($value =~ /(\d+)/) { |
|
268
|
0
|
|
|
|
|
|
$data->{count} = $1; |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1; |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
__END__ |