blib/lib/WWW/phpBB.pm

filter: Statementstmt 4.9% 51 / 1028 Branchbran 0.0% 0 / 614 Conditioncond 0.0% 0 / 273 MC/DCmcdc 0.0% 0 / 170 Subroutinesub 23.5% 12 / 51 Podpod 21.6% 8 / 37 totaltotal 3.2% 71 / 2173 CC 447 SCAR 80.7
CC
447
Cov
3%
get_users_raw
10302.0
get_topics
3782.0
get_posts_from_page
3422.0
CRAP 3207.9
↑ Summary
1 package WWW::phpBB;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTML::TokeParser::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DBI();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use POSIX ":sys_wait_h";
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 require Exporter;
17  
18 1 our @ISA = qw(Exporter);
19 1 our %EXPORT_TAGS = ();
20 1 our @EXPORT_OK = ();
21 1 our @EXPORT = qw();
22 1 our $VERSION = '0.09';
23 1 my $children; # number of spawned processes
24  
25 # defaults
26 1 my %default = (
27 db_compression => 0,
28 max_rows => 60,
29 months => [qw(jan feb mar apr may jun jul aug sep oct nov dec)],
30 post_date_format => qr/(\w+)\s+(\d+),\s+(\d+)\s+(\d+):(\d+)\s+(\w\w)/i,
31 post_date_pos => [qw(month_name day_of_month year hour minutes am_pm)],
32 reg_date_format => qr/(\d+)\s+(\w+)\s+(\d+)/i,
33 reg_date_pos => [qw(day_of_month month_name year)],
34 forum_link_regex => qr/f=(\d+)/,
35 topic_link_regex_p => qr/viewtopic.*p=(\d+)/,
36 topic_link_regex_t => qr/viewtopic.*t=(\d+)/,
37 topic_link1 => "viewtopic.php",
38 topic_link2 => "t=%d&postorder=asc",
39 alternative_page_number_regex_forum => qr//,
40 alternative_page_number_regex_topic => qr//,
41 quote_string => "wrote",
42 max_tries => 50,
43 db_empty => [qw(users categories forums topics posts posts_text vote_desc vote_results groups user_group)],
44 bbcode_uid => '48d712e388',
45 db_insert => 1,
46 update_overwrite => 0,
47 verbose => 0,
48 profile_info => 1,
49 profile_string_occupation => "occupation",
50 profile_string_msn => "msn messenger",
51 max_children => 1,
52 smiles => {
53 icon_biggrin => ':D',
54 icon_smile => ':)',
55 icon_sad => ':(',
56 icon_surprised => ':o',
57 icon_eek => ':shock:',
58 icon_confused => ':?',
59 icon_cool => '8)',
60 icon_lol => ':lol:',
61 icon_mad => ':x',
62 icon_razz => ':P',
63 icon_redface => ':oops:',
64 icon_cry => ':cry:',
65 icon_evil => ':evil:',
66 icon_twisted => ':twisted:',
67 icon_rolleyes => ':roll:',
68 icon_wink => ':wink:',
69 icon_exclaim => ':!:',
70 icon_question => ':?:',
71 icon_idea => ':idea:',
72 icon_arrow => ':arrow:',
73 icon_neutral => ':|',
74 icon_mrgreen => ':mrgreen:',
75 },
76 );
77 # mysql tables as arrays of hashes
78 1 for (qw(categories forums topics users posts posts_text vote_desc vote_results groups user_group)) {
79 10 $default{$_} = [];
80 }
81  
82  
83 package WWW::phpBB;
84  
85 ##################
86 # main functions #
87 ##################
88  
89 1 our %ok_field; # for accessors
90  
91 1 for (qw(
92 base_url
93 db_host
94 db_user
95 db_passwd
96 db_database
97 db_prefix
98 forum_user
99 forum_passwd
100 db_compression
101 max_rows
102 months
103 post_date_format
104 post_date_pos
105 reg_date_format
106 reg_date_pos
107 forum_link_regex
108 topic_link_regex_p
109 topic_link_regex_t
110 topic_link1
111 topic_link2
112 alternative_page_number_regex_forum
113 alternative_page_number_regex_topic
114 quote_string
115 max_tries
116 db_empty
117 db_insert
118 max_children
119 verbose
120 profile_info
121 29 )) { $ok_field{$_}++ };
122  
123 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
124 0 my $self = shift;
125 0 my $attr = our $AUTOLOAD;
126 0 $attr =~ s/.*:://;
127 0 ▶ return unless $attr =~ /[^A-Z]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /[^A-Z]/ 0 0 0
128 0 ▶ croak "invalid attribute method: ->$attr( )" unless $ok_field{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $WWW::phpBB::ok_field{$attr} 0 0 0
129 0 ▶ $self->$attr = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
130 0 $self->$attr;
131 }
132  
133 0 ▶sub new {
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
134 0 my $self = {};
135 0 bless($self, shift);
136 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
137 0 my %args = @_;
138 0 @$self{keys %args} = values %args;
139 }
140  
141 # defaults
142 0 ▶ while (my ($key, $value) = each %default) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %default) 0 0 0
143 0 ▶ $self->{$key} = $value unless exists $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$key} 0 0 0
144 }
145  
146 # croak if the mandatory arguments are missing
147 0 for (qw(base_url db_host db_user db_passwd db_database db_prefix)) {
148 0 ▶ croak "you must specify a $_" unless exists $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$_} 0 0 0
149 }
150  
151 # init
152 0 $self->{mmech} = WWW::Mechanize->new(stack_depth => 1);
153 0 $self->{mmech}->agent_alias('Linux Mozilla');
154 #$self->{mmech}->add_header('Accept-Encoding' => 'gzip; deflate');
155 0 for (1..$self->{max_tries}) {
156 0 $self->{mmech}->get($self->{base_url});
157 0 ▶ last if $self->{mmech}->success && $self->{mmech}->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mmech"}->success and $self->{"mmech"}->status == 200 0 0 0
Condition0%0/3
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
$self->{"mmech"}->success $self->{"mmech"}->status == 200
Truth table0%0/3
A and B
A= $self->{"mmech"}->successB= $self->{"mmech"}->status == 200
ABresult
0X0
100
111
158 0 print "Error fetching the start page (try $_ out of $self->{max_tries})\n";
159 }
160 0 ▶ croak "gave up...\n" unless $self->{mmech}->success && $self->{mmech}->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"mmech"}->success and $self->{"mmech"}->status == 200 0 0 0
Condition0%0/3
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
$self->{"mmech"}->success $self->{"mmech"}->status == 200
Truth table0%0/3
A and B
A= $self->{"mmech"}->successB= $self->{"mmech"}->status == 200
ABresult
0X0
100
111
161  
162 $self->{dbh} = DBI->connect("DBI:mysql:database=$self->{db_database};host=$self->{db_host};mysql_compression=$self->{db_compression}",
163 0 $self->{db_user}, $self->{db_passwd}, {AutoCommit => 1, RaiseError => 1});
164 0 ▶ unless ($self->{update_overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"update_overwrite"}) 0 0 0
165 0 $self->{dbh}->do("CREATE TABLE IF NOT EXISTS $self->{db_prefix}" . "topics_trans "
166 . "(new mediumint(8) unsigned NOT NULL,"
167 . "orig mediumint(8) unsigned NOT NULL,"
168 . "PRIMARY KEY (new) )");
169 0 $self->{dbh}->do("CREATE TABLE IF NOT EXISTS $self->{db_prefix}" . "posts_trans "
170 . "LIKE $self->{db_prefix}" . "topics_trans");
171 }
172  
173 0 $self;
174 }
175  
176 0 ▶sub forum_login_raw {
Subroutine forum_login_raw: not called CC=10 SCAR=47.0
Pod undocumented
177 0 my $self = shift;
178 0 ▶ if (!exists $self->{forum_user} || !exists $self->{forum_passwd}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"forum_user"} and exists $self->{"forum_passwd"}) 0 0 0
Condition0%0/3
exists $self->{"forum_user"} and exists $self->{"forum_passwd"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"forum_user"} and exists $self->{"forum_passwd"}
exists $self->{"forum_user"} exists $self->{"forum_passwd"}
Truth table0%0/3
A and B
A= exists $self->{"forum_user"}B= exists $self->{"forum_passwd"}
ABresult
0X0
100
111
179 0 print "can't login without a forum_user and forum_passwd\n";
180 0 return;
181 }
182 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
183 0 print "logging in...";
184 }
185 0 for (1..$self->{max_tries}) {
186 #$self->{mmech}->form_number(1);
187 0 $self->{mmech}->field('username', $self->{forum_user});
188 0 $self->{mmech}->field('password', $self->{forum_passwd});
189 0 $self->{mmech}->click();
190 0 ▶ if ($self->{mmech}->success && $self->{mmech}->status == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mmech"}->success and $self->{"mmech"}->status == 200) 0 0 0
Condition0%0/3
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
$self->{"mmech"}->success $self->{"mmech"}->status == 200
Truth table0%0/3
A and B
A= $self->{"mmech"}->successB= $self->{"mmech"}->status == 200
ABresult
0X0
100
111
191 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
192 0 print "\n";
193 }
194 0 last;
195 }
196 0 print "Error logging in (try $_ out of $self->{max_tries})\n";
197 }
198 0 ▶ croak "gave up...\n" unless $self->{mmech}->success && $self->{mmech}->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"mmech"}->success and $self->{"mmech"}->status == 200 0 0 0
Condition0%0/3
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
$self->{"mmech"}->success $self->{"mmech"}->status == 200
Truth table0%0/3
A and B
A= $self->{"mmech"}->successB= $self->{"mmech"}->status == 200
ABresult
0X0
100
111
199 }
200  
201 # wrapper for forum_login_raw() that retries in case of errors
202 0 ▶sub forum_login {
Subroutine forum_login: not called CC=3 SCAR=24.8
Pod documented
203 0 my $self = shift;
204 0 for (1..$self->{max_tries}) {
205 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->forum_login_raw(@_); 1 } } and last 0 0 0
206 0 $self->forum_login_raw(@_);
207 0 1;
208 } and last;
209 0 print "failed (try $_ out of $self->{max_tries})\n";
210 0 sleep(1)
211 }
212 }
213  
214 0 ▶sub forum_logout_raw {
Subroutine forum_logout_raw: not called CC=10 SCAR=47.0
Pod undocumented
215 0 my $self = shift;
216 0 ▶ return unless exists $self->{forum_user} && exists $self->{forum_passwd};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"forum_user"} and exists $self->{"forum_passwd"} 0 0 0
Condition0%0/3
exists $self->{"forum_user"} and exists $self->{"forum_passwd"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"forum_user"} and exists $self->{"forum_passwd"}
exists $self->{"forum_user"} exists $self->{"forum_passwd"}
Truth table0%0/3
A and B
A= exists $self->{"forum_user"}B= exists $self->{"forum_passwd"}
ABresult
0X0
100
111
217 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
218 0 print "logging out...";
219 }
220 0 for (1..$self->{max_tries}) {
221 0 $self->{mmech}->follow_link(url_regex => qr/logout/);
222 0 ▶ if ($self->{mmech}->success && $self->{mmech}->status == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mmech"}->success and $self->{"mmech"}->status == 200) 0 0 0
Condition0%0/3
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
$self->{"mmech"}->success $self->{"mmech"}->status == 200
Truth table0%0/3
A and B
A= $self->{"mmech"}->successB= $self->{"mmech"}->status == 200
ABresult
0X0
100
111
223 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
224 0 print "\n";
225 }
226 last
227 0 }
228 0 print "Error logging out (try $_ out of $self->{max_tries})\n";
229 }
230 0 ▶ croak "gave up...\n" unless $self->{mmech}->success && $self->{mmech}->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"mmech"}->success and $self->{"mmech"}->status == 200 0 0 0
Condition0%0/3
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mmech"}->success and $self->{"mmech"}->status == 200
$self->{"mmech"}->success $self->{"mmech"}->status == 200
Truth table0%0/3
A and B
A= $self->{"mmech"}->successB= $self->{"mmech"}->status == 200
ABresult
0X0
100
111
231 # reset the base_uri
232 $self->{mmech}->get($self->{base_url})
233 0 }
234  
235 # wrapper for forum_logout_raw() that retries in case of errors
236 0 ▶sub forum_logout {
Subroutine forum_logout: not called CC=3 SCAR=24.8
Pod documented
237 0 my $self = shift;
238 0 for (1..$self->{max_tries}) {
239 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->forum_logout_raw(@_); 1 } } and last 0 0 0
240 0 $self->forum_logout_raw(@_);
241 0 1;
242 } and last;
243 0 print "failed (try $_ out of $self->{max_tries})\n";
244 0 sleep(1)
245 }
246 }
247  
248 0 ▶sub get_categories_and_forums {
Subroutine get_categories_and_forums: not called CC=28 SCAR=67.0
Pod undocumented
249 0 my $self = shift;
250 0 my $parse;
251 0 $parse = HTML::TokeParser::Simple->new( \$self->{mmech}->content );
252 0 $parse->unbroken_text( 1 );
253 0 my $token;
254 my $cat_order;
255 0 my $rows;
256 0 my $frows;
257  
258 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
259 0 ▶ next unless $token->get_attr('class') eq 'catLeft';
Branch: 1 branch
BranchTrueFalseTotal
unless $token->get_attr("class") eq "catLeft" 0 0 0
260 0 my %row;
261 my $cat_id;
262 # cat_id
263 0 ▶ $token = $parse->get_token until $token->is_start_tag('a') || $token == 0;
Branch: 1 branch
BranchTrueFalseTotal
($token->is_start_tag("a") or $token == 0) or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_start_tag("a") or $token == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$token->is_start_tag("a") or $token == 0
$token->is_start_tag("a") $token == 0
Truth table0%0/3
A or B
A= $token->is_start_tag("a")B= $token == 0
ABresult
1X1
011
000
264 0 $token->get_attr('href') =~ /c=(\d+)/;
265 0 $row{cat_id} = $cat_id = $1;
266 # cat_title
267 0 ▶ $token = $parse->get_token until $token->is_text && $token->as_is =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
268 0 $row{cat_title} = $token->as_is;
269 # cat_order
270 0 $cat_order += 10;
271 0 $row{cat_order} = $cat_order;
272 # store
273 0 push @{$self->{categories}}, \%row;
274  
275 # get the forums
276 0 my $forum_order;
277 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
278 0 ▶ last if $parse->peek =~ /catLeft/;
Branch: 1 branch
BranchTrueFalseTotal
if $parse->peek =~ /catLeft/ 0 0 0
279 0 ▶ next unless $token->is_start_tag('a') && $token->get_attr('class') eq 'forumlink';
Branch: 1 branch
BranchTrueFalseTotal
unless $token->is_start_tag("a") and $token->get_attr("class") eq "forumlink" 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("class") eq "forumlink"
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("class") eq "forumlink"
$token->is_start_tag("a") $token->get_attr("class") eq "forumlink"
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("class") eq "forumlink"
ABresult
0X0
100
111
280 0 my %row;
281 # auth
282 0 $row{auth_post} = 1;
283 0 $row{auth_reply} = 1;
284 0 $row{auth_edit} = 1;
285 0 $row{auth_delete} = 1;
286 0 $row{auth_vote} = 1;
287 0 $row{auth_pollcreate} = 1;
288 0 $row{auth_sticky} = $row{auth_announce} = $row{auth_attachments} = 3;
289 # forum_id
290 0 $token->get_attr('href') =~ $self->{forum_link_regex};
291 0 $row{forum_id} = $1;
292 # cat_id
293 0 $row{cat_id} = $cat_id;
294 # forum_name
295 0 ▶ $token = $parse->get_token until $token->is_text && $token->as_is =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
296 0 $row{forum_name} = $token->as_is;
297 # forum_desc
298 0 $token = $parse->get_token;
299 0 ▶ $token = $parse->get_token until $token->is_text && $token->as_is =~ /\S/
Branch: 1 branch
BranchTrueFalseTotal
($token->is_text and $token->as_is =~ /\S/ or $token->is_end_tag("td")) or do { $token = $parse->get_token } 0 0 0
Condition0%0/6
$token->is_text and $token->as_is =~ /\S/ or $token->is_end_tag("td")
l!l&&r!l&&!r
000
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/3
$token->is_text and $token->as_is =~ /\S/ or $token->is_end_tag("td")
$token->is_text $token->as_is =~ /\S/ $token->is_end_tag("td")
Truth table0%0/5
A and B or C
A= $token->is_textB= $token->as_is =~ /\S/C= $token->is_end_tag("td")
ABCresult
11X1
0X11
1011
0X00
1000
300 || $token->is_end_tag('td');
301 0 ▶ $row{forum_desc} = $token->as_is if $token->is_text;
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_text 0 0 0
302 0 $row{forum_desc} =~ s/ //g;
303 # forum_topics
304 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
305 0 ▶ $token = $parse->get_token until $token->is_text && $token->as_is =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
306 0 $row{forum_topics} = $token->as_is;
307 # forum_posts
308 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
309 0 ▶ $token = $parse->get_token until $token->is_text && $token->as_is =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
310 0 $row{forum_posts} = $token->as_is;
311 # forum_last_post_id
312 $token = $parse->get_token until $token->is_start_tag('a')
313 && $token->get_attr('href') =~ $self->{topic_link_regex_p}
314 0 ▶ || $token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
($token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/ or $token->is_end_tag("tr")) or do { $token = $parse->get_token } 0 0 0
Condition0%0/6
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/ or $token->is_end_tag("tr")
l!l&&r!l&&!r
000
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
!ll&&!rl&&r
000
MC/DC0%0/3
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/ or $token->is_end_tag("tr")
$token->is_start_tag("a") $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/ $token->is_end_tag("tr")
Truth table0%0/5
A and B or C
A= $token->is_start_tag("a")B= $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/C= $token->is_end_tag("tr")
ABCresult
11X1
0X11
1011
0X00
1000
315 0 ▶ $row{forum_last_post_id} = $1 if $token->is_start_tag('a');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("a") 0 0 0
316 # forum_order
317 0 $forum_order += 10;
318 0 $row{forum_order} = $forum_order;
319 # store
320 0 push @{$self->{forums}}, \%row;
321 }
322 }
323 0 ▶ if ($self->{db_insert}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"db_insert"}) 0 0 0
324 0 $self->insert_array($self->{categories}, "categories");
325 0 $self->insert_array($self->{forums}, "forums");
326 }
327 }
328  
329 # $_[0]=$forum_id, $_[1]=$page_number
330 0 ▶sub get_topics {
Subroutine get_topics: not called CC=61 SCAR=82.4
Pod undocumented
331 0 my $self = shift;
332 0 my ($forum_id, $page_number) = @_;
333 0 my $success;
334 my $rows;
335 # make a copy of the $mech object
336 0 my $mech = {%{$self->{mmech}}};
337 0 bless $mech, "WWW::Mechanize";
338 0 my $url = $self->compute_url("viewforum.php", "f=$forum_id");
339 0 for (1..$self->{max_tries}) {
340 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $mech->get($url); 1 } } or next 0 0 0
341 0 $mech->get($url);
342 0 1;
343 } or next;
344 0 ▶ last if $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
345 0 print "Failed to enter forum_id $forum_id (try $_ out of $self->{max_tries})\n";
346 }
347 0 ▶ return unless $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
348 # cycle through pages
349 0 my $pages = $self->number_of_pages($mech, 'forum');
350 # get just one page ?
351 0 ▶ if (defined $page_number) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $page_number) 0 0 0
352 0 ▶ if (-@$pages <= $page_number && $page_number < @$pages) {
Branch: 1 branch
BranchTrueFalseTotal
if (-@$pages <= $page_number and $page_number < @$pages) { } 0 0 0
Condition0%0/3
-@$pages <= $page_number and $page_number < @$pages
!ll&&!rl&&r
000
MC/DC0%0/2
-@$pages <= $page_number and $page_number < @$pages
-@$pages <= $page_number $page_number < @$pages
Truth table0%0/3
A and B
A= -@$pages <= $page_numberB= $page_number < @$pages
ABresult
0X0
100
111
353 0 $pages = [ $$pages[$page_number] ];
354 0 } else { return }
355 }
356 #print " pages: ", join(", ", @$pages);
357 0 for ( @$pages ) {
358 0 my $url = $mech->uri;
359 0 $url = $self->forum_url_for_page($url, $forum_id, $_);
360 #print $url, "\n";
361 0 for (1..$self->{max_tries}) {
362 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $mech->get($url); 1 } } or next 0 0 0
363 0 $mech->get($url);
364 0 1;
365 } or next;
366 0 ▶ last if $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
367 0 print "Failed to enter a page of forum_id $forum_id (try $_ out of $self->{max_tries})\n";
368 }
369 0 ▶ next unless $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
370 # extract topic info
371 0 my $parse;
372 0 $parse = HTML::TokeParser::Simple->new( \$mech->content );
373 0 $parse->unbroken_text( 1 );
374 0 my $token;
375 0 $token = $parse->get_token;
376 0 ▶ $token = $parse->get_token until (!defined $token || $token->get_attr('class') eq 'forumline');
Branch: 1 branch
BranchTrueFalseTotal
(not defined $token or $token->get_attr("class") eq "forumline") or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
not defined $token or $token->get_attr("class") eq "forumline"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $token or $token->get_attr("class") eq "forumline"
not defined $token $token->get_attr("class") eq "forumline"
Truth table0%0/3
not(A) or B
A= not defined $tokenB= $token->get_attr("class") eq "forumline"
ABresult
1X1
011
000
377 0 ▶ $token = $parse->get_token until $token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_end_tag("tr") or do { $token = $parse->get_token } 0 0 0
378 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
379 0 ▶ last if $token->is_end_tag('table');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("table") 0 0 0
380 0 ▶ next unless $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
unless $token->is_start_tag("tr") 0 0 0
381 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
382 0 ▶ last unless $token->get_attr('class') =~ /row/;
Branch: 1 branch
BranchTrueFalseTotal
unless $token->get_attr("class") =~ /row/ 0 0 0
383 0 my %row;
384 # forum_id
385 0 $row{forum_id} = $forum_id;
386 # topic_type
387 0 ▶ $token = $parse->get_token until $token->is_start_tag('img')
Branch: 1 branch
BranchTrueFalseTotal
($token->is_start_tag("img") or $token->is_end_tag("td")) or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_start_tag("img") or $token->is_end_tag("td")
l!l&&r!l&&!r
000
MC/DC0%0/2
$token->is_start_tag("img") or $token->is_end_tag("td")
$token->is_start_tag("img") $token->is_end_tag("td")
Truth table0%0/3
A or B
A= $token->is_start_tag("img")B= $token->is_end_tag("td")
ABresult
1X1
011
000
388 || $token->is_end_tag('td');
389 0 ▶ last if $token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("td") 0 0 0
390 0 ▶ $row{topic_type} = 1 if $token->get_attr('src') =~ /sticky/;
Branch: 1 branch
BranchTrueFalseTotal
if $token->get_attr("src") =~ /sticky/ 0 0 0
391 0 ▶ $row{topic_type} = 2 if $token->get_attr('src') =~ /announce/;
Branch: 1 branch
BranchTrueFalseTotal
if $token->get_attr("src") =~ /announce/ 0 0 0
392 # topic_id
393 $token = $parse->get_token until $token->is_start_tag('a')
394 0 ▶ && $token->get_attr('href') =~ $self->{topic_link_regex_t};
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_t"}/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_t"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_t"}/
$token->is_start_tag("a") $token->get_attr("href") =~ /$self->{"topic_link_regex_t"}/
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("href") =~ /$self->{"topic_link_regex_t"}/
ABresult
0X0
100
111
395 0 $row{topic_id} = $1;
396 # topic_title
397 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
398 && $token->as_is =~ /\S/;
399 0 $row{topic_title} = $token->as_is;
400 # topic_replies
401 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
402 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /^(\d+)$/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /^(\d+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /^(\d+)$/
$token->is_text $token->as_is =~ /^(\d+)$/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /^(\d+)$/
ABresult
0X0
100
111
403 && $token->as_is =~ /^(\d+)$/;
404 0 $row{topic_replies} = $1;
405 # topic_poster
406 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
407 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
408 0 ▶ last if $token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("td") 0 0 0
409 0 ▶ if ($token->is_start_tag('a')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag("a")) 0 0 0
410 0 ▶ $row{topic_poster} = $1
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)/ 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
$token->is_start_tag("a") $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
ABresult
0X0
100
111
411 if $token->is_start_tag('a')
412 && $token->get_attr('href') =~ /viewprofile.*u=(\d+)/;
413 0 last;
414 }
415 0 ▶ if ( ! exists $row{topic_poster}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $row{"topic_poster"} and $token->is_text and $token->as_is =~ /\S/) 0 0 0
Condition0%0/6
not exists $row{"topic_poster"} and $token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
not exists $row{"topic_poster"} and $token->is_text
!ll&&!rl&&r
000
MC/DC0%0/3
not exists $row{"topic_poster"} and $token->is_text and $token->as_is =~ /\S/
not exists $row{"topic_poster"} $token->is_text $token->as_is =~ /\S/
Truth table0%0/4
not(A) and B and C
A= not exists $row{"topic_poster"}B= $token->is_textC= $token->as_is =~ /\S/
ABCresult
0XX0
10X0
1100
1111
416 && $token->is_text
417 && $token->as_is =~ /\S/ ) {
418 0 my $username = $token->as_is;
419 0 for (@{$self->{users}}) {
420 0 ▶ if ($_->{username} eq $username) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"username"} eq $username) 0 0 0
421 0 $row{topic_poster} = $_->{user_id};
422 0 last;
423 }
424 }
425 }
426 }
427 0 ▶ $row{topic_poster} = -1 unless exists $row{topic_poster};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $row{"topic_poster"} 0 0 0
428 # topic_views
429 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
430 0 ▶ $token = $parse->get_token until (!defined $token || ($token->is_text && $token->as_is =~ /^(\d+)$/));
Branch: 1 branch
BranchTrueFalseTotal
(not defined $token or $token->is_text and $token->as_is =~ /^(\d+)$/) or do { $token = $parse->get_token } 0 0 0
Condition0%0/6
not defined $token or $token->is_text and $token->as_is =~ /^(\d+)$/
l!l&&r!l&&!r
000
$token->is_text and $token->as_is =~ /^(\d+)$/
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $token or $token->is_text and $token->as_is =~ /^(\d+)$/
not defined $token $token->is_text $token->as_is =~ /^(\d+)$/
Truth table0%0/4
not(A) or B and C
A= not defined $tokenB= $token->is_textC= $token->as_is =~ /^(\d+)$/
ABCresult
1XX1
0111
00X0
0100
431 0 $row{topic_views} = $1;
432 # topic_last_post_id
433 $token = $parse->get_token until $token->is_start_tag('a')
434 0 ▶ && $token->get_attr('href') =~ $self->{topic_link_regex_p};
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
$token->is_start_tag("a") $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
ABresult
0X0
100
111
435 0 $row{topic_last_post_id} = $1;
436  
437 # manage the same topic appearing on more pages (like announcements)
438 0 my $unique = 1;
439 0 for (@{$self->{topics}}) {
440 0 ▶ if ( $_->{topic_id} == $row{topic_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"topic_id"} == $row{"topic_id"}) 0 0 0
441 0 $unique = 0;
442 0 last;
443 }
444 }
445 # check also the db to see if it's the shadow of a moved topic
446 0 ▶ if ($unique && ! defined $page_number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unique and not defined $page_number) 0 0 0
Condition0%0/3
$unique and not defined $page_number
!ll&&!rl&&r
000
MC/DC0%0/2
$unique and not defined $page_number
$unique not defined $page_number
Truth table0%0/3
A and not(B)
A= $uniqueB= not defined $page_number
ABresult
0X0
100
111
447 0 my $sth = $self->{dbh}->prepare("SELECT topic_id FROM $self->{db_prefix}"
448 . "topics WHERE topic_id=$row{topic_id}" );
449 0 $sth->execute;
450 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
451 0 $unique = 0;
452 }
453 }
454  
455 0 ▶ push @{$self->{topics}}, \%row if $unique;
Branch: 1 branch
BranchTrueFalseTotal
if $unique 0 0 0
456 }
457 }
458 }
459  
460 # $_[0]=$page_number
461 0 ▶sub get_users_raw {
Subroutine get_users_raw: not called CC=101 SCAR=92.4
Pod undocumented
462 0 my $self = shift;
463 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
464 0 print "getting users...\n";
465 }
466 0 my ($page_number) = @_;
467 0 my $success;
468 my $rows;
469  
470 0 $self->get_new_admin();
471 # make a copy of the $mech object
472 0 my $mech = {%{$self->{mmech}}};
473 0 bless $mech, "WWW::Mechanize";
474 0 my $url = $self->compute_url("memberlist.php", "");
475 0 for (1..$self->{max_tries}) {
476 0 $mech->get($url);
477 0 ▶ last if $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
478 0 print "Failed to enter memberlist (try $_ out of $self->{max_tries})\n";
479 }
480 0 ▶ return unless $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
481 # cycle through pages
482 0 my $pages = $self->number_of_pages($mech);
483 # get just one page ?
484 0 ▶ if (defined $page_number) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $page_number) 0 0 0
485 0 ▶ if (-@$pages <= $page_number && $page_number < @$pages) {
Branch: 1 branch
BranchTrueFalseTotal
if (-@$pages <= $page_number and $page_number < @$pages) { } 0 0 0
Condition0%0/3
-@$pages <= $page_number and $page_number < @$pages
!ll&&!rl&&r
000
MC/DC0%0/2
-@$pages <= $page_number and $page_number < @$pages
-@$pages <= $page_number $page_number < @$pages
Truth table0%0/3
A and B
A= -@$pages <= $page_numberB= $page_number < @$pages
ABresult
0X0
100
111
486 0 $pages = [ $$pages[$page_number] ];
487 0 } else { return }
488 }
489 0 for ( @$pages ) {
490 0 my $url = $mech->uri;
491 0 $url =~ s/&$//;
492 0 $url = $self->memberlist_url_for_page($url, $_);
493  
494 0 for (1..$self->{max_tries}) {
495 0 $mech->get($url);
496 0 ▶ last if $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
497 0 print "Failed to enter a page of the memberlist (try $_ out of $self->{max_tries})\n";
498 }
499 0 ▶ next unless $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
500 # extract memberlist info
501 0 my $parse;
502 0 $parse = HTML::TokeParser::Simple->new( \$mech->content );
503 0 $parse->unbroken_text( 1 );
504 0 my $token;
505 0 $token = $parse->get_token;
506 0 ▶ $token = $parse->get_token until $token->is_start_tag('table')
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("table") and $token->get_attr("class") eq "forumline" or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_start_tag("table") and $token->get_attr("class") eq "forumline"
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("table") and $token->get_attr("class") eq "forumline"
$token->is_start_tag("table") $token->get_attr("class") eq "forumline"
Truth table0%0/3
A and B
A= $token->is_start_tag("table")B= $token->get_attr("class") eq "forumline"
ABresult
0X0
100
111
507 && $token->get_attr('class') eq 'forumline';
508 0 ▶ $token = $parse->get_token until $token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_end_tag("tr") or do { $token = $parse->get_token } 0 0 0
509 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
510 #print "|>", $parse->peek(7), "<|\n";
511 0 ▶ next unless $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
unless $token->is_start_tag("tr") 0 0 0
512 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
513 0 my %row;
514 # various default fields
515 0 $row{user_sig_bbcode_uid} = $self->{bbcode_uid};
516 0 $row{user_style} = 1;
517 0 $row{user_lang} = 'english';
518 0 $row{user_viewemail} = 0;
519 0 $row{user_attachsig} = 1;
520 0 $row{user_allowhtml} = 0;
521 0 $row{user_notify} = 0;
522 0 $row{user_notify_pm} = 1;
523 0 $row{user_popup_pm} = 1;
524 # user_id
525 0 ▶ $token = $parse->get_token until !defined $token || ($token->is_start_tag('a') && $token->get_attr('href') =~ /viewprofile.*u=(\d+)(\D|$)/);
Branch: 1 branch
BranchTrueFalseTotal
(not defined $token or $token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)(\D|$)/) or do { $token = $parse->get_token } 0 0 0
Condition0%0/6
not defined $token or $token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)(\D|$)/
l!l&&r!l&&!r
000
$token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)(\D|$)/
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $token or $token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)(\D|$)/
not defined $token $token->is_start_tag("a") $token->get_attr("href") =~ /viewprofile.*u=(\d+)(\D|$)/
Truth table0%0/4
not(A) or B and C
A= not defined $tokenB= $token->is_start_tag("a")C= $token->get_attr("href") =~ /viewprofile.*u=(\d+)(\D|$)/
ABCresult
1XX1
0111
00X0
0100
526 0 ▶ last if !defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
527 0 $row{user_id} = $1;
528 # username
529 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
530 && $token->as_is =~ /\S/;
531 0 $row{username} = $token->as_is;
532 0 ▶ die "the destination forum's admin has the same username as one user from the scraped forum ($row{username})! aborting...\n" if $row{username} eq $self->{new_admin_username};
Branch: 1 branch
BranchTrueFalseTotal
if $row{"username"} eq $self->{"new_admin_username"} 0 0 0
533 #print $row{username}, "\n";
534 # user_email
535 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
536 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
537 0 ▶ last if $token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("td") 0 0 0
538 0 ▶ if ($token->is_start_tag('a') && $token->as_is =~ /mailto:([^"]+)\"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag("a") and $token->as_is =~ /mailto:([^"]+)\"/) 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->as_is =~ /mailto:([^"]+)\"/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->as_is =~ /mailto:([^"]+)\"/
$token->is_start_tag("a") $token->as_is =~ /mailto:([^"]+)\"/
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->as_is =~ /mailto:([^"]+)\"/
ABresult
0X0
100
111
539 0 $row{user_email} = $1;
540 }
541 }
542 # user_from
543 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
544 0 my $td_count = 0;
545 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
546 0 ▶ $td_count++ if $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("td") 0 0 0
547 0 ▶ $td_count-- if $token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("td") 0 0 0
548 0 ▶ last if $td_count < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $td_count < 0 0 0 0
549 0 ▶ if ($token->is_text
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_text and not $token->as_is =~ /^(&nbsp;)+$/ and $token->as_is =~ /\S/) 0 0 0
Condition0%0/6
$token->is_text and not $token->as_is =~ /^(&nbsp;)+$/ and $token->as_is =~ /\S/
!ll&&!rl&&r
000
$token->is_text and not $token->as_is =~ /^(&nbsp;)+$/
!ll&&!rl&&r
000
MC/DC0%0/3
$token->is_text and not $token->as_is =~ /^(&nbsp;)+$/ and $token->as_is =~ /\S/
$token->is_text not $token->as_is =~ /^(&nbsp;)+$/ $token->as_is =~ /\S/
Truth table0%0/4
A and not(B) and C
A= $token->is_textB= not $token->as_is =~ /^(&nbsp;)+$/C= $token->as_is =~ /\S/
ABCresult
0XX0
10X0
1100
1111
550 && $token->as_is !~ /^(&nbsp;)+$/
551 && $token->as_is =~ /\S/) {
552 0 $row{user_from} = $token->as_is;
553 }
554 }
555 # user_regdate
556 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
557 && $token->as_is =~ /\S/;
558 #print $token->as_is(), "\n";
559 $row{user_regdate} = $self->parse_date($token->as_is, $self->{reg_date_format},
560 0 $self->{reg_date_pos});
561 # user_posts
562 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /^(\d+)$/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /^(\d+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /^(\d+)$/
$token->is_text $token->as_is =~ /^(\d+)$/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /^(\d+)$/
ABresult
0X0
100
111
563 && $token->as_is =~ /^(\d+)$/;
564 0 $row{user_posts} = $1;
565 # user_website
566 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
567 0 ▶ last if $token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("tr") 0 0 0
568 0 ▶ if ($token->is_start_tag('a')
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag("a") and $token->get_attr("target") eq "_userwww") 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("target") eq "_userwww"
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("target") eq "_userwww"
$token->is_start_tag("a") $token->get_attr("target") eq "_userwww"
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("target") eq "_userwww"
ABresult
0X0
100
111
569 && $token->get_attr('target') eq "_userwww") {
570 0 $row{user_website} = $token->get_attr('href');
571 }
572 }
573 #while( my ($k, $v) = each %row ) {
574 #print "$k : $v\n";
575 #}
576 #print "\n";
577  
578 0 ▶ if($self->{profile_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"profile_info"}) 0 0 0
579 # get profile info
580 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
581 0 print "getting the profile info for '$row{username}'\n";
582 }
583 # make a copy of the $mech object in order to get the profile page
584 0 my $p_mech = {%{$mech}};
585 0 bless $p_mech, "WWW::Mechanize";
586 0 my $urlp = $self->compute_url("profile.php", "mode=viewprofile&u=$row{user_id}");
587 0 for (1..$self->{max_tries}) {
588 0 $p_mech->get($urlp);
589 0 ▶ last if $p_mech->success && $p_mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $p_mech->success and $p_mech->status == 200 0 0 0
Condition0%0/3
$p_mech->success and $p_mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$p_mech->success and $p_mech->status == 200
$p_mech->success $p_mech->status == 200
Truth table0%0/3
A and B
A= $p_mech->successB= $p_mech->status == 200
ABresult
0X0
100
111
590 0 print "Failed to enter profile (try $_ out of $self->{max_tries})\n";
591 }
592 0 ▶ next unless $p_mech->success && $p_mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $p_mech->success and $p_mech->status == 200 0 0 0
Condition0%0/3
$p_mech->success and $p_mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$p_mech->success and $p_mech->status == 200
$p_mech->success $p_mech->status == 200
Truth table0%0/3
A and B
A= $p_mech->successB= $p_mech->status == 200
ABresult
0X0
100
111
593 0 my $p_parse;
594 0 $p_parse = HTML::TokeParser::Simple->new( \$p_mech->content );
595 0 $p_parse->unbroken_text( 1 );
596 0 my $p_token;
597 0 $p_token = $p_parse->get_token;
598 0 ▶ $p_token = $p_parse->get_token until $p_token->get_attr('class')
Branch: 1 branch
BranchTrueFalseTotal
$p_token->get_attr("class") eq "forumline" or do { $p_token = $p_parse->get_token } 0 0 0
599 eq 'forumline';
600 0 ▶ $p_token = $p_parse->get_token until $p_token->get_attr('class')
Branch: 1 branch
BranchTrueFalseTotal
$p_token->get_attr("class") =~ /row/ and $p_token->is_start_tag("td") or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/3
$p_token->get_attr("class") =~ /row/ and $p_token->is_start_tag("td")
!ll&&!rl&&r
000
MC/DC0%0/2
$p_token->get_attr("class") =~ /row/ and $p_token->is_start_tag("td")
$p_token->get_attr("class") =~ /row/ $p_token->is_start_tag("td")
Truth table0%0/3
A and B
A= $p_token->get_attr("class") =~ /row/B= $p_token->is_start_tag("td")
ABresult
0X0
100
111
601 =~ /row/ && $p_token->is_start_tag('td');
602 # user_avatar
603 0 ▶ while ($p_token = $p_parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p_token = $p_parse->get_token) 0 0 0
604 0 ▶ last if $p_token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $p_token->is_end_tag("td") 0 0 0
605 0 ▶ if ($p_token->is_tag('img')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p_token->is_tag("img")) 0 0 0
606 0 $row{user_avatar} = $p_token->get_attr('src');
607 0 (my $b_url = $p_mech->uri) =~ s%^(.*/).*$%$1%;
608 0 ▶ $row{user_avatar} = $b_url . $row{user_avatar} if $row{user_avatar} !~ m%^http://%;
Branch: 1 branch
BranchTrueFalseTotal
unless $row{"user_avatar"} =~ m[^http://] 0 0 0
609 0 $row{user_avatar_type} = 2;
610 0 last;
611 }
612 }
613 #print "$row{username} - $row{user_avatar}\n";
614 # user_occ
615 #for (1..5) {
616 #$p_token = $p_parse->get_token;
617 #$p_token = $p_parse->get_token until $p_token->is_start_tag('tr');
618 #}
619 #$p_token = $p_parse->get_token until $p_token->is_end_tag('td');
620 #$p_token = $p_parse->get_token until $p_token->is_text
621 #&& $p_token->as_is !~ /^\s+$|^(&nbsp;)+$/
622 #|| $p_token->is_end_tag('tr');
623 0 ▶ $p_token = $p_parse->get_token until $p_token->is_text && $p_token->as_is =~ /^$self->{profile_string_occupation}:/i;
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_text and $p_token->as_is =~ /^$self->{"profile_string_occupation"}:/i or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/3
$p_token->is_text and $p_token->as_is =~ /^$self->{"profile_string_occupation"}:/i
!ll&&!rl&&r
000
MC/DC0%0/2
$p_token->is_text and $p_token->as_is =~ /^$self->{"profile_string_occupation"}:/i
$p_token->is_text $p_token->as_is =~ /^$self->{"profile_string_occupation"}:/i
Truth table0%0/3
A and B
A= $p_token->is_textB= $p_token->as_is =~ /^$self->{"profile_string_occupation"}:/i
ABresult
0X0
100
111
624 0 ▶ $p_token = $p_parse->get_token until $p_token->is_start_tag('span');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_start_tag("span") or do { $p_token = $p_parse->get_token } 0 0 0
625 0 ▶ $p_token = $p_parse->get_token until $p_token->is_text;
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_text or do { $p_token = $p_parse->get_token } 0 0 0
626 0 ▶ $row{user_occ} = $p_token->as_is if $p_token->as_is !~ /^\s+$|^(&nbsp;)+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/ 0 0 0
627 # user_interests
628 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("tr") or do { $p_token = $p_parse->get_token } 0 0 0
629 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("td") or do { $p_token = $p_parse->get_token } 0 0 0
630 0 ▶ $p_token = $p_parse->get_token until $p_token->is_text
Branch: 1 branch
BranchTrueFalseTotal
($p_token->is_text and not $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/ or $p_token->is_end_tag("tr")) or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/6
$p_token->is_text and not $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/ or $p_token->is_end_tag("tr")
l!l&&r!l&&!r
000
$p_token->is_text and not $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/
!ll&&!rl&&r
000
MC/DC0%0/3
$p_token->is_text and not $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/ or $p_token->is_end_tag("tr")
$p_token->is_text not $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/ $p_token->is_end_tag("tr")
Truth table0%0/5
A and not(B) or C
A= $p_token->is_textB= not $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/C= $p_token->is_end_tag("tr")
ABCresult
11X1
0X11
1011
0X00
1000
631 && $p_token->as_is !~ /^\s+$|^(&nbsp;)+$/
632 || $p_token->is_end_tag('tr');
633 0 ▶ $row{user_interests} = $p_token->as_is if $p_token->is_text;
Branch: 1 branch
BranchTrueFalseTotal
if $p_token->is_text 0 0 0
634 # user_msnm
635 #$p_token = $p_parse->get_token until $p_token->is_start_tag('table');
636 #for (1..3) {
637 #$p_token = $p_parse->get_token;
638 #$p_token = $p_parse->get_token until $p_token->is_start_tag('tr');
639 #}
640 #$p_token = $p_parse->get_token until $p_token->is_end_tag('td');
641 #$p_token = $p_parse->get_token until $p_token->is_text
642 #&& $p_token->as_is !~ /^\s+$|^(&nbsp;)+$/
643 #|| $p_token->is_end_tag('tr');
644 0 ▶ $p_token = $p_parse->get_token until $p_token->is_text && $p_token->as_is =~ /^$self->{profile_string_msn}:/i;
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_text and $p_token->as_is =~ /^$self->{"profile_string_msn"}:/i or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/3
$p_token->is_text and $p_token->as_is =~ /^$self->{"profile_string_msn"}:/i
!ll&&!rl&&r
000
MC/DC0%0/2
$p_token->is_text and $p_token->as_is =~ /^$self->{"profile_string_msn"}:/i
$p_token->is_text $p_token->as_is =~ /^$self->{"profile_string_msn"}:/i
Truth table0%0/3
A and B
A= $p_token->is_textB= $p_token->as_is =~ /^$self->{"profile_string_msn"}:/i
ABresult
0X0
100
111
645 0 ▶ $p_token = $p_parse->get_token until $p_token->is_start_tag('span');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_start_tag("span") or do { $p_token = $p_parse->get_token } 0 0 0
646 0 ▶ $p_token = $p_parse->get_token until $p_token->is_text;
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_text or do { $p_token = $p_parse->get_token } 0 0 0
647 0 ▶ $row{user_msnm} = $p_token->as_is if $p_token->as_is !~ /^\s+$|^(&nbsp;)+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $p_token->as_is =~ /^\s+$|^(&nbsp;)+$/ 0 0 0
648 # user_yim
649 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("tr") or do { $p_token = $p_parse->get_token } 0 0 0
650 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("td") or do { $p_token = $p_parse->get_token } 0 0 0
651 0 ▶ $p_token = $p_parse->get_token until $p_token->is_start_tag('a')
Branch: 1 branch
BranchTrueFalseTotal
($p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /target=(.+?)(&|$)/ or $p_token->is_end_tag("tr")) or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/6
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /target=(.+?)(&|$)/ or $p_token->is_end_tag("tr")
l!l&&r!l&&!r
000
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /target=(.+?)(&|$)/
!ll&&!rl&&r
000
MC/DC0%0/3
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /target=(.+?)(&|$)/ or $p_token->is_end_tag("tr")
$p_token->is_start_tag("a") $p_token->get_attr("href") =~ /target=(.+?)(&|$)/ $p_token->is_end_tag("tr")
Truth table0%0/5
A and B or C
A= $p_token->is_start_tag("a")B= $p_token->get_attr("href") =~ /target=(.+?)(&|$)/C= $p_token->is_end_tag("tr")
ABCresult
11X1
0X11
1011
0X00
1000
652 && $p_token->get_attr('href') =~ /target=(.+?)(&|$)/
653 || $p_token->is_end_tag('tr');
654 0 ▶ $row{user_yim} = $1 if $p_token->is_start_tag('a');
Branch: 1 branch
BranchTrueFalseTotal
if $p_token->is_start_tag("a") 0 0 0
655 # user_aim
656 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("tr") or do { $p_token = $p_parse->get_token } 0 0 0
657 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("td") or do { $p_token = $p_parse->get_token } 0 0 0
658 0 ▶ $p_token = $p_parse->get_token until $p_token->is_start_tag('a')
Branch: 1 branch
BranchTrueFalseTotal
($p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /screenname=(.+?)(&|$)/ or $p_token->is_end_tag("tr")) or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/6
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /screenname=(.+?)(&|$)/ or $p_token->is_end_tag("tr")
l!l&&r!l&&!r
000
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /screenname=(.+?)(&|$)/
!ll&&!rl&&r
000
MC/DC0%0/3
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /screenname=(.+?)(&|$)/ or $p_token->is_end_tag("tr")
$p_token->is_start_tag("a") $p_token->get_attr("href") =~ /screenname=(.+?)(&|$)/ $p_token->is_end_tag("tr")
Truth table0%0/5
A and B or C
A= $p_token->is_start_tag("a")B= $p_token->get_attr("href") =~ /screenname=(.+?)(&|$)/C= $p_token->is_end_tag("tr")
ABCresult
11X1
0X11
1011
0X00
1000
659 && $p_token->get_attr('href') =~ /screenname=(.+?)(&|$)/
660 || $p_token->is_end_tag('tr');
661 0 ▶ $row{user_aim} = $1 if $p_token->is_start_tag('a');
Branch: 1 branch
BranchTrueFalseTotal
if $p_token->is_start_tag("a") 0 0 0
662 # user_icq
663 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("tr") or do { $p_token = $p_parse->get_token } 0 0 0
664 0 ▶ $p_token = $p_parse->get_token until $p_token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$p_token->is_end_tag("td") or do { $p_token = $p_parse->get_token } 0 0 0
665 0 ▶ $p_token = $p_parse->get_token until $p_token->is_start_tag('a')
Branch: 1 branch
BranchTrueFalseTotal
($p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /icq\.com.*=(\d+?)(&|$)/ or $p_token->is_end_tag("tr")) or do { $p_token = $p_parse->get_token } 0 0 0
Condition0%0/6
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /icq\.com.*=(\d+?)(&|$)/ or $p_token->is_end_tag("tr")
l!l&&r!l&&!r
000
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /icq\.com.*=(\d+?)(&|$)/
!ll&&!rl&&r
000
MC/DC0%0/3
$p_token->is_start_tag("a") and $p_token->get_attr("href") =~ /icq\.com.*=(\d+?)(&|$)/ or $p_token->is_end_tag("tr")
$p_token->is_start_tag("a") $p_token->get_attr("href") =~ /icq\.com.*=(\d+?)(&|$)/ $p_token->is_end_tag("tr")
Truth table0%0/5
A and B or C
A= $p_token->is_start_tag("a")B= $p_token->get_attr("href") =~ /icq\.com.*=(\d+?)(&|$)/C= $p_token->is_end_tag("tr")
ABCresult
11X1
0X11
1011
0X00
1000
666 && $p_token->get_attr('href') =~ /icq\.com.*=(\d+?)(&|$)/
667 || $p_token->is_end_tag('tr');
668 0 ▶ $row{user_icq} = $1 if $p_token->is_start_tag('a');
Branch: 1 branch
BranchTrueFalseTotal
if $p_token->is_start_tag("a") 0 0 0
669 }
670 #while( my ($k, $v) = each %row ) {
671 #print "$k : $v\n";
672 #}
673 #print "\n";
674  
675 0 push @{$self->{users}}, \%row;
676 0 ▶ if ($self->{db_insert} && ++$rows >= $self->{max_rows}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"db_insert"} and ++$rows >= $self->{"max_rows"}) 0 0 0
Condition0%0/3
$self->{"db_insert"} and ++$rows >= $self->{"max_rows"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"db_insert"} and ++$rows >= $self->{"max_rows"}
$self->{"db_insert"} ++$rows >= $self->{"max_rows"}
Truth table0%0/3
A and B
A= $self->{"db_insert"}B= ++$rows >= $self->{"max_rows"}
ABresult
0X0
100
111
677 0 $self->insert_array($self->{users}, "users");
678 0 @{$self->{users}} = ();
679 }
680  
681 }
682 }
683 0 ▶ if ($self->{db_insert}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"db_insert"}) 0 0 0
684 0 $self->insert_array($self->{users}, "users");
685 0 @{$self->{users}} = ();
686 }
687 0 $self->create_groups;
688 }
689  
690 # wrapper for get_users_raw() that retries in case of errors
691 0 ▶sub get_users {
Subroutine get_users: not called CC=3 SCAR=24.8
Pod documented
692 0 my $self = shift;
693 0 for (1..$self->{max_tries}) {
694 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->get_users_raw(@_); 1 } } and last 0 0 0
695 0 $self->get_users_raw(@_);
696 0 1;
697 } and last;
698 0 print "failed (try $_ out of $self->{max_tries})\n";
699 0 sleep(1)
700 }
701 }
702  
703 # $_[0]=$topic_id, $_[1]=$page_number
704 0 ▶sub get_posts {
Subroutine get_posts: not called CC=25 SCAR=64.8
Pod undocumented
705 0 my $self = shift;
706 0 my ($topic_id, $page_number) = @_;
707 0 my $success;
708 0 my ($url, $url1, $url2);
709 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
710 0 print "getting the posts from topic #$topic_id\n";
711 }
712 # make a copy of the $mech object
713 0 my $mech = {%{$self->{mmech}}};
714 0 bless $mech, "WWW::Mechanize";
715 0 $url1 = $self->{topic_link1};
716 0 ▶ $url1 = sprintf($url1, $topic_id) if $url1 =~ m/%d/;
Branch: 1 branch
BranchTrueFalseTotal
if $url1 =~ /%d/ 0 0 0
717 0 $url2 = $self->{topic_link2};
718 0 ▶ $url2 = sprintf($url2, $topic_id) if $url2 =~ m/%d/;
Branch: 1 branch
BranchTrueFalseTotal
if $url2 =~ /%d/ 0 0 0
719 0 $url = $self->compute_url($url1, $url2);
720 0 for (1..$self->{max_tries}) {
721 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $mech->get($url); 1 } } or next 0 0 0
722 0 $mech->get($url);
723 0 1;
724 } or next;
725 0 ▶ last if $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
726 0 print "Failed to enter topic_id $topic_id (try $_ out of $self->{max_tries})\n";
727 }
728 0 ▶ return unless $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
729 # cycle through pages
730 0 my $pages = $self->number_of_pages($mech, 'topic');
731 # get just one page ?
732 0 ▶ if (defined $page_number) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $page_number) 0 0 0
733 0 ▶ if (-@$pages <= $page_number && $page_number < @$pages) {
Branch: 1 branch
BranchTrueFalseTotal
if (-@$pages <= $page_number and $page_number < @$pages) { } 0 0 0
Condition0%0/3
-@$pages <= $page_number and $page_number < @$pages
!ll&&!rl&&r
000
MC/DC0%0/2
-@$pages <= $page_number and $page_number < @$pages
-@$pages <= $page_number $page_number < @$pages
Truth table0%0/3
A and B
A= -@$pages <= $page_numberB= $page_number < @$pages
ABresult
0X0
100
111
734 0 $pages = [ $$pages[$page_number] ];
735 0 } else { return }
736 }
737 0 for ( @$pages ) {
738 0 my $url = $mech->uri;
739 0 $url = $self->topic_url_for_page($url, $topic_id, $_);
740 0 for (1..$self->{max_tries}) {
741 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $mech->get($url); 1 } } or next 0 0 0
742 0 $mech->get($url);
743 0 1;
744 } or next;
745 0 ▶ last if $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
746 0 print "Failed to enter a page of topic_id $topic_id (try $_ out of $self->{max_tries})\n";
747 }
748 0 ▶ next unless $mech->success && $mech->status == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->success and $mech->status == 200 0 0 0
Condition0%0/3
$mech->success and $mech->status == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$mech->success and $mech->status == 200
$mech->success $mech->status == 200
Truth table0%0/3
A and B
A= $mech->successB= $mech->status == 200
ABresult
0X0
100
111
749 0 $self->get_posts_from_page($mech, $topic_id, $_);
750 }
751 # get last_post_id only if scraping the full topic or just the last page
752 0 ▶ unless (defined $page_number && $page_number != -1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $page_number and $page_number != -1) 0 0 0
Condition0%0/3
defined $page_number and $page_number != -1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $page_number and $page_number != -1
defined $page_number $page_number != -1
Truth table0%0/3
A and B
A= defined $page_numberB= $page_number != -1
ABresult
0X0
100
111
753 0 for (@{$self->{topics}}) {
754 0 ▶ if ($_->{topic_id} == $topic_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"topic_id"} == $topic_id) 0 0 0
755 0 $_->{topic_last_post_id} = $self->{posts}[-1]{post_id};
756 0 last;
757 }
758 }
759 }
760 0 ▶ if ($self->{db_insert}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"db_insert"}) 0 0 0
761 0 $self->insert_array($self->{posts}, "posts");
762 0 $self->insert_array($self->{posts_text}, "posts_text");
763 0 $self->insert_array($self->{vote_desc}, "vote_desc");
764 0 $self->insert_array($self->{vote_results}, "vote_results");
765 0 @{$self->{posts}} = ();
766 0 @{$self->{posts_text}} = ();
767 0 @{$self->{vote_desc}} = ();
768 0 @{$self->{vote_results}} = ();
769 }
770 }
771  
772 0 ▶sub get_posts_from_page {
Subroutine get_posts_from_page: not called CC=58 SCAR=81.4
Pod undocumented
773 0 my $self = shift;
774 0 my ($mech, $topic_id, $start_from) = @_;
775 0 my $parse;
776 0 $parse = HTML::TokeParser::Simple->new( \$mech->content );
777 0 $parse->unbroken_text( 1 );
778 0 my $token;
779 my $rows;
780 0 my %v_row;
781  
782 0 $token = $parse->get_token;
783 0 ▶ $token = $parse->get_token until $token->get_attr('class') eq 'forumline';
Branch: 1 branch
BranchTrueFalseTotal
$token->get_attr("class") eq "forumline" or do { $token = $parse->get_token } 0 0 0
784 0 for (1..2) {
785 0 $token = $parse->get_token;
786 0 ▶ $token = $parse->get_token until $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("tr") or do { $token = $parse->get_token } 0 0 0
787 }
788 0 my $counter;
789 0 while (1) {
790 0 $token = $parse->get_token;
791 0 ▶ $counter++ if $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("tr") 0 0 0
792 0 ▶ $counter-- if $token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("tr") 0 0 0
793 0 ▶ last if $counter < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $counter < 0 0 0 0
794 # get the poll only on the first page
795 0 ▶ if ($token->is_start_tag('table') && $start_from == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag("table") and $start_from == 0) 0 0 0
Condition0%0/3
$token->is_start_tag("table") and $start_from == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("table") and $start_from == 0
$token->is_start_tag("table") $start_from == 0
Truth table0%0/3
A and B
A= $token->is_start_tag("table")B= $start_from == 0
ABresult
0X0
100
111
796 #################
797 ## it's a poll ##
798 #################
799 0 for (@{$self->{topics}}) {
800 0 ▶ if ($_->{topic_id} == $topic_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"topic_id"} == $topic_id) 0 0 0
801 # topic_vote
802 0 $_->{topic_vote} = 1;
803 0 last;
804 }
805 }
806 # topic_id
807 0 $v_row{topic_id} = $topic_id;
808 # vote_id
809 0 $v_row{vote_id} = ++$self->{vote_id};
810 # vote_text
811 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
812 && $token->as_is =~ /\S/;
813 0 $v_row{vote_text} = $token->as_is;
814 # @{$self->{vote_results}}
815 0 my $vote_option_id;
816 0 ▶ $token = $parse->get_token until $token->is_start_tag('table');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("table") or do { $token = $parse->get_token } 0 0 0
817 0 my $counter2;
818 0 while (1) {
819 0 my %vr_row;
820 0 $token = $parse->get_token;
821 0 ▶ $counter2++ if $token->is_start_tag('table');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("table") 0 0 0
822 0 ▶ $counter2-- if $token->is_end_tag('table');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("table") 0 0 0
823 0 ▶ last if $counter2 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $counter2 < 0 0 0 0
824 0 ▶ next unless $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
unless $token->is_start_tag("td") 0 0 0
825 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ and not $token->as_is =~ /&nbsp;/ and not $token->as_is =~ /^\s+$/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/9
$token->is_text and $token->as_is =~ /\S/ and not $token->as_is =~ /&nbsp;/ and not $token->as_is =~ /^\s+$/
!ll&&!rl&&r
000
$token->is_text and $token->as_is =~ /\S/ and not $token->as_is =~ /&nbsp;/
!ll&&!rl&&r
000
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/4
$token->is_text and $token->as_is =~ /\S/ and not $token->as_is =~ /&nbsp;/ and not $token->as_is =~ /^\s+$/
$token->is_text $token->as_is =~ /\S/ not $token->as_is =~ /&nbsp;/ not $token->as_is =~ /^\s+$/
Truth table0%0/5
A and B and not(C) and not(D)
A= $token->is_textB= $token->as_is =~ /\S/C= not $token->as_is =~ /&nbsp;/D= not $token->as_is =~ /^\s+$/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
826 && $token->as_is =~ /\S/
827 && $token->as_is !~ /&nbsp;/
828 && $token->as_is !~ /^\s+$/;
829 0 $vr_row{vote_id} = $self->{vote_id};
830 0 $vr_row{vote_option_text} = $token->as_is;
831 0 $vr_row{vote_option_id} = ++$vote_option_id;
832 0 push @{$self->{vote_results}}, \%vr_row;
833 0 my $counter3;
834 0 while (1) {
835 0 $token = $parse->get_token;
836 0 ▶ if ($token->is_start_tag('tr')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag("tr")) 0 0 0
837 0 $counter++;
838 0 $counter3++;
839 }
840 0 ▶ if ($token->is_end_tag('tr')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_end_tag("tr")) 0 0 0
841 0 $counter--;
842 0 $counter3--;
843 }
844 0 ▶ last if $counter3 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $counter3 < 0 0 0 0
845 }
846 # print "|>", $parse->peek(7), "<|\n";
847 }
848 0 push @{$self->{vote_desc}}, \%v_row;
849 }
850 }
851  
852 0 ▶ while ( $token = $parse->get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
853 0 ▶ last if $token->get_attr('class') eq 'catBottom';
Branch: 1 branch
BranchTrueFalseTotal
if $token->get_attr("class") eq "catBottom" 0 0 0
854 # post_username
855 0 ▶ next unless $token->get_attr('class') eq 'name';
Branch: 1 branch
BranchTrueFalseTotal
unless $token->get_attr("class") eq "name" 0 0 0
856 0 ▶ $token = $parse->get_token until $token->is_text;
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text or do { $token = $parse->get_token } 0 0 0
857 0 my $post_username = $token->as_is;
858 # post_id
859 $token = $parse->get_token until $token->is_start_tag('a')
860 0 ▶ && $token->get_attr('href') =~ $self->{topic_link_regex_p};
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
$token->is_start_tag("a") $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("href") =~ /$self->{"topic_link_regex_p"}/
ABresult
0X0
100
111
861 0 my %row;
862 0 $row{post_id} = $1;
863 # topic_id
864 0 $row{topic_id} = $topic_id;
865 # forum_id
866 0 for (@{$self->{topics}}) {
867 0 ▶ if ($_->{topic_id} == $topic_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"topic_id"} == $topic_id) 0 0 0
868 0 $row{forum_id} = $_->{forum_id};
869 0 last;
870 }
871 }
872 # post_time
873 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S/
$token->is_text $token->as_is =~ /\S/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S/
ABresult
0X0
100
111
874 && $token->as_is =~ /\S/;
875 $row{post_time} = $self->parse_date($token->as_is, $self->{post_date_format},
876 0 $self->{post_date_pos});
877 0 ▶ if (@{$self->{posts}} && $row{post_time} <= $self->{posts}[-1]->{post_time}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"posts"};} and $row{"post_time"} <= $self->{"posts"}[-1]{"post_time"}) 0 0 0
Condition0%0/3
@{$self->{"posts"};} and $row{"post_time"} <= $self->{"posts"}[-1]{"post_time"}
!ll&&!rl&&r
000
MC/DC0%0/2
@{$self->{"posts"};} and $row{"post_time"} <= $self->{"posts"}[-1]{"post_time"}
@{$self->{"posts"};} $row{"post_time"} <= $self->{"posts"}[-1]{"post_time"}
Truth table0%0/3
A and B
A= @{$self->{"posts"};}B= $row{"post_time"} <= $self->{"posts"}[-1]{"post_time"}
ABresult
0X0
100
111
878 0 $row{post_time} = $self->{posts}[-1]->{post_time} + 1
879 }
880  
881 ## fill some @{$self->{topics}} and @{$self->{vote_desc}} fields ##
882 # just for the first page
883 0 ▶ if ($start_from == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_from == 0) 0 0 0
884 0 for (@{$self->{topics}}) {
885 0 ▶ if ($_->{topic_id} == $topic_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"topic_id"} == $topic_id) 0 0 0
886 # topic_first_post_id
887 $_->{topic_first_post_id} = $row{post_id}
888 0 ▶ unless $_->{topic_first_post_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"topic_first_post_id"} 0 0 0
889 # vote_start and topic_time
890 $v_row{vote_start} = $_->{topic_time} = $row{post_time}
891 0 ▶ unless $_->{topic_time};
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"topic_time"} 0 0 0
892 0 last;
893 }
894 }
895 }
896  
897 # @{$self->{posts_text}}
898 0 my %t_row;
899 # post_subject
900 0 $token = $parse->get_token;
901 0 ▶ $token = $parse->get_token until $token->is_text
Branch: 1 branch
BranchTrueFalseTotal
$token->is_text and $token->as_is =~ /\S: (.*)$/ or do { $token = $parse->get_token } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /\S: (.*)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /\S: (.*)$/
$token->is_text $token->as_is =~ /\S: (.*)$/
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /\S: (.*)$/
ABresult
0X0
100
111
902 && $token->as_is =~ /\S: (.*)$/;
903 0 $t_row{post_subject} = $1;
904 # post_id
905 0 $t_row{post_id} = $row{post_id};
906 # bbcode_uid
907 0 $t_row{bbcode_uid} = $self->{bbcode_uid};
908 # post_text
909 0 ▶ $token = $parse->get_token until $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("tr") or do { $token = $parse->get_token } 0 0 0
910 0 $token = $parse->get_token;
911 0 ▶ $token = $parse->get_token until $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("tr") or do { $token = $parse->get_token } 0 0 0
912 0 my $text;
913 my $tr_count; # keep a track of <tr> tags
914 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
915 0 ▶ $tr_count++ if $token->is_start_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("tr") 0 0 0
916 0 ▶ $tr_count-- if $token->is_end_tag('tr');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("tr") 0 0 0
917 0 ▶ last if $tr_count < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $tr_count < 0 0 0 0
918 0 $text .= $token->as_is;
919 }
920 ## bbcode
921 0 $text = ${ $self->html_to_bbcode(\$text, 1) };
922 # take care of HTML entities
923 0 $text = decode_entities($text);
924 0 $text = encode_entities($text);
925  
926 0 $t_row{post_text} = $text;
927 # poster_id
928 0 ▶ $token = $parse->get_token until $token->is_start_tag('table');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("table") or do { $token = $parse->get_token } 0 0 0
929 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
930 0 ▶ last if $token->is_end_tag('table');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("table") 0 0 0
931 0 ▶ if ($token->is_start_tag('a') && $token->get_attr('href')
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)/) 0 0 0
Condition0%0/3
$token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("a") and $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
$token->is_start_tag("a") $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
Truth table0%0/3
A and B
A= $token->is_start_tag("a")B= $token->get_attr("href") =~ /viewprofile.*u=(\d+)/
ABresult
0X0
100
111
932 =~ /viewprofile.*u=(\d+)/) {
933 0 $row{poster_id} = $1;
934 0 last;
935 }
936 }
937 # anonymous?
938 0 ▶ unless ( exists $row{poster_id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $row{"poster_id"}) 0 0 0
939 0 $row{poster_id} = -1;
940 0 $row{post_username} = $post_username;
941 }
942  
943 0 push @{$self->{posts}}, \%row;
944 0 push @{$self->{posts_text}}, \%t_row;
945 0 ▶ if ($self->{db_insert} && ++$rows == $self->{max_rows}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"db_insert"} and ++$rows == $self->{"max_rows"}) 0 0 0
Condition0%0/3
$self->{"db_insert"} and ++$rows == $self->{"max_rows"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"db_insert"} and ++$rows == $self->{"max_rows"}
$self->{"db_insert"} ++$rows == $self->{"max_rows"}
Truth table0%0/3
A and B
A= $self->{"db_insert"}B= ++$rows == $self->{"max_rows"}
ABresult
0X0
100
111
946 0 $rows = 0;
947 # keep the last post
948 0 my $lastpost = pop @{$self->{posts}};
949 0 $self->insert_array($self->{posts}, "posts");
950 0 @{$self->{posts}} = ();
951 # put it back
952 0 push @{$self->{posts}}, $lastpost;
953  
954 0 $self->insert_array($self->{posts_text}, "posts_text");
955 0 @{$self->{posts_text}} = ();
956 }
957 }
958 }
959  
960 0 ▶sub update_users_raw {
Subroutine update_users_raw: not called CC=9 SCAR=45.0
Pod undocumented
961 0 my $self = shift;
962 0 $self->{db_insert} = 0;
963 0 my $page = -1;
964 0 my @new;
965 # max user_id
966 0 my $sth = $self->{dbh}->prepare("SELECT MAX(user_regdate) AS regdate FROM $self->{db_prefix}" . "users");
967 0 $sth->execute;
968 0 $sth->bind_columns(\my ($max_regdate));
969 0 $sth->fetch;
970 0 MLOOP: while (1) {
971 0 @{$self->{users}} = ();
972 0 $self->get_users($page);
973 0 ▶ last unless @{$self->{users}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"users"};} 0 0 0
974 0 for (reverse @{$self->{users}}) {
975 0 ▶ if ($_->{user_regdate} < $max_regdate) { # get out
Branch: 2 branches
BranchTrueFalseTotal
if ($_->{'user_regdate'} < $max_regdate) { } 0 0 0
elsif ($_->{'user_regdate'} == $max_regdate) { } 0 0 0
976 0 last MLOOP;
977 } elsif ($_->{user_regdate} == $max_regdate) {
978 0 $sth = $self->{dbh}->prepare("SELECT user_id, username FROM $self->{db_prefix}"
979 . "users WHERE user_regdate=$max_regdate");
980 0 $sth->execute;
981 0 $sth->bind_columns(\my ($user_id, $username));
982 0 ▶ while ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
983 0 ▶ if ($_->{user_id} == $user_id && $user_id != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"user_id"} == $user_id and $user_id != 1) 0 0 0
Condition0%0/3
$_->{"user_id"} == $user_id and $user_id != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"user_id"} == $user_id and $user_id != 1
$_->{"user_id"} == $user_id $user_id != 1
Truth table0%0/3
A and B
A= $_->{"user_id"} == $user_idB= $user_id != 1
ABresult
0X0
100
111
984 0 ▶ if ($_->{username} ne $username) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"username"} ne $username) 0 0 0
985 # this user was deleted
986 0 $self->{dbh}->do("DELETE FROM $self->{db_prefix}" . "users WHERE user_id=$user_id");
987 $self->{dbh}->do("UPDATE $self->{db_prefix}"
988 . "posts SET poster_id=-1, post_username="
989 . $self->{dbh}->quote($_->{username})
990 0 . " WHERE poster_id=$user_id");
991 0 push @new, $_;
992 }
993 0 last;
994 }
995 }
996 } else { # insert
997 0 push @new, $_;
998 }
999 }
1000 0 $page--;
1001 }
1002 0 $self->insert_array(\@new, 'users');
1003 0 $self->create_groups;
1004 }
1005  
1006 # wrapper for update_users_raw() that retries in case of errors
1007 0 ▶sub update_users {
Subroutine update_users: not called CC=3 SCAR=24.8
Pod documented
1008 0 my $self = shift;
1009 0 for (1..$self->{max_tries}) {
1010 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->update_users_raw(@_); 1 } } and last 0 0 0
1011 0 $self->update_users_raw(@_);
1012 0 1;
1013 } and last;
1014 0 print "failed (try $_ out of $self->{max_tries})\n";
1015 0 sleep(1)
1016 }
1017 }
1018  
1019 0 ▶sub update_topics {
Subroutine update_topics: not called CC=6 SCAR=37.4
Pod undocumented
1020 0 my $self = shift;
1021 0 my ($forum_id) = @_;
1022 0 my @modified_topics;
1023 0 my $page = 0;
1024 0 PAGE: while (1) {
1025 0 @{$self->{topics}} = ();
1026 0 $self->get_topics($forum_id, $page);
1027 0 ▶ last unless @{$self->{topics}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"topics"};} 0 0 0
1028 0 for (@{$self->{topics}}) {
1029 my $sth = $self->{dbh}->prepare("SELECT post_time FROM $self->{db_prefix}"
1030 0 . "posts WHERE post_id=" . $_->{topic_last_post_id});
1031 0 $sth->execute;
1032 0 $sth->bind_columns(\my $post_time);
1033 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) { } 0 0 0
1034 # we have the last_post_id, but it can be a new post with the id of a deleted one
1035 0 ▶ if ($post_time >= $self->{last_timestamp}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($post_time >= $self->{'last_timestamp'}) { } 0 0 0
elsif ($_->{'topic_type'} == 0) { } 0 0 0
1036 0 push @modified_topics, $_;
1037 } elsif ($_->{topic_type} == 0) {
1038 # normal topic - it won't appear on more pages
1039 0 last PAGE;
1040 }
1041 } else {
1042 # new topic
1043 0 push @modified_topics, $_;
1044 }
1045 }
1046 0 $page++;
1047 }
1048 0 @{$self->{topics}} = @modified_topics;
1049 }
1050  
1051 0 ▶sub update_topics_insert {
Subroutine update_topics_insert: not called CC=4 SCAR=30.0
Pod undocumented
1052 0 my $self = shift;
1053 0 my ($t) = @_;
1054 0 ▶ unless ($self->{update_overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"update_overwrite"}) 0 0 0
1055 my $sth = $self->{dbh}->prepare("SELECT topic_title FROM $self->{db_prefix}"
1056 0 . "topics WHERE topic_id=" . $t->{topic_id});
1057 0 $sth->execute;
1058 0 $sth->bind_columns(\my $topic_title);
1059 0 ▶ if ($sth->fetch && $topic_title ne $t->{topic_title}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch and $topic_title ne $t->{"topic_title"}) 0 0 0
Condition0%0/3
$sth->fetch and $topic_title ne $t->{"topic_title"}
!ll&&!rl&&r
000
MC/DC0%0/2
$sth->fetch and $topic_title ne $t->{"topic_title"}
$sth->fetch $topic_title ne $t->{"topic_title"}
Truth table0%0/3
A and B
A= $sth->fetchB= $topic_title ne $t->{"topic_title"}
ABresult
0X0
100
111
1060 # it was probably deleted, create a new one
1061 0 my $topic_id;
1062 0 my $sth = $self->{dbh}->prepare("SELECT MAX(topic_id) FROM $self->{db_prefix}" . "topics");
1063 0 $sth->execute;
1064 0 $sth->bind_columns(\$topic_id);
1065 0 $sth->fetch;
1066 0 $topic_id++;
1067 $self->{dbh}->do("REPLACE $self->{db_prefix}" . "topics_trans "
1068 0 . "SET new=$topic_id, orig=" . $t->{topic_id});
1069 0 $t->{topic_id} = $topic_id;
1070 }
1071 }
1072 0 $self->insert_array([$t], 'topics');
1073 }
1074  
1075 0 ▶sub update_posts {
Subroutine update_posts: not called CC=18 SCAR=58.3
Pod undocumented
1076 0 my $self = shift;
1077 0 my ($topic_id) = @_;
1078 0 my @new_posts;
1079 my @new_posts_text;
1080 0 my $page = -1;
1081 0 my $last_post_id; # that was used for a post
1082 0 my $sth = $self->{dbh}->prepare("SELECT MAX(post_id) FROM $self->{db_prefix}" . "posts");
1083 0 $sth->execute;
1084 0 $sth->bind_columns(\$last_post_id);
1085 0 $sth->fetch;
1086  
1087 0 PAGE: while (1) {
1088 0 @{$self->{posts}} = ();
1089 0 @{$self->{posts_text}} = ();
1090 0 $self->get_posts($topic_id, $page);
1091 0 ▶ last unless @{$self->{posts}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"posts"};} 0 0 0
1092 ##$self->print_AoH($self->{posts});
1093 0 POST: for (reverse 0..$#{$self->{posts}}) {
1094 0 my $sth;
1095 0 ▶ last PAGE if $self->{posts}[$_]{post_time} < $self->{last_timestamp};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"posts"}[$_]{"post_time"} < $self->{"last_timestamp"} 0 0 0
1096 # don't get the posts that appeared betwen scraping the topic
1097 # and scraping the posts, because it will mess up
1098 # our last_timestamp at the next update
1099 0 for my $t (@{$self->{topics}}) {
1100 0 ▶ if ($t->{topic_id} == $topic_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"topic_id"} == $topic_id) 0 0 0
1101 0 ▶ next POST if $self->{posts}[$_]{post_id} > $t->{topic_last_post_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"posts"}[$_]{"post_id"} > $t->{"topic_last_post_id"} 0 0 0
1102 0 last;
1103 }
1104 }
1105  
1106 0 my ($in_table, $in_orig, $in_new);
1107 0 my $new_id;
1108  
1109 $sth = $self->{dbh}->prepare("SELECT post_id FROM $self->{db_prefix}"
1110 0 . "posts WHERE post_id=" . $self->{posts}[$_]{post_id});
1111 0 $sth->execute;
1112 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
1113 # we have that id
1114 0 $in_table = 1;
1115 }
1116 0 ▶ unless ($self->{update_overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"update_overwrite"}) 0 0 0
1117 $sth = $self->{dbh}->prepare("SELECT new FROM $self->{db_prefix}"
1118 0 . "posts_trans WHERE new=" . $self->{posts}[$_]{post_id});
1119 0 $sth->execute;
1120 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
1121 # it's in the translation table, as a new id
1122 0 $in_new = 1;
1123 }
1124 $sth = $self->{dbh}->prepare("SELECT new FROM $self->{db_prefix}"
1125 0 . "posts_trans WHERE orig=" . $self->{posts}[$_]{post_id});
1126 0 $sth->execute;
1127 0 $sth->bind_columns(\$new_id);
1128 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
1129 0 $in_orig = 1;
1130 }
1131 }
1132  
1133 0 ▶ if ($in_table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_table) 0 0 0
1134 # could be already scraped, check post_text
1135 0 my $against_id = $self->{posts}[$_]{post_id};
1136 0 ▶ if ($in_orig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_orig) 0 0 0
1137 # could be deleted, check against new_id
1138 0 $against_id = $new_id;
1139 }
1140 0 ▶ unless ($in_new && ! $in_orig) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_new and not $in_orig) 0 0 0
Condition0%0/3
$in_new and not $in_orig
!ll&&!rl&&r
000
MC/DC0%0/2
$in_new and not $in_orig
$in_new not $in_orig
Truth table0%0/3
A and not(B)
A= $in_newB= not $in_orig
ABresult
0X0
100
111
1141 # compare text
1142 0 $sth = $self->{dbh}->prepare("SELECT post_text FROM $self->{db_prefix}"
1143 . "posts_text WHERE post_id=$against_id");
1144 0 $sth->execute;
1145 0 $sth->bind_columns(\my $post_text);
1146 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
1147 # already scraped
1148 0 ▶ last PAGE if $post_text eq $self->{posts_text}[$_]{post_text};
Branch: 1 branch
BranchTrueFalseTotal
if $post_text eq $self->{"posts_text"}[$_]{"post_text"} 0 0 0
1149 }
1150 }
1151 0 ▶ unless ($self->{update_overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"update_overwrite"}) 0 0 0
1152 # set and record a new post_id
1153 0 $last_post_id++;
1154 $self->{dbh}->do("REPLACE $self->{db_prefix}" . "posts_trans "
1155 0 . "SET new=$last_post_id, orig=" . $self->{posts}[$_]{post_id});
1156 0 $self->{posts_text}[$_]{post_id} = $self->{posts}[$_]{post_id} = $last_post_id;
1157 }
1158 }
1159  
1160 0 push @new_posts, $self->{posts}[$_];
1161 0 push @new_posts_text, $self->{posts_text}[$_];
1162 }
1163 0 $page--;
1164 }
1165 ##$self->print_AoH(\@new_posts);
1166 0 @{$self->{posts}} = @new_posts;
1167 0 @{$self->{posts_text}} = @new_posts_text;
1168 }
1169  
1170 0 ▶sub update_posts_insert {
Subroutine update_posts_insert: not called CC=4 SCAR=30.0
Pod undocumented
1171 0 my $self = shift;
1172 0 my $sth;
1173  
1174 0 for (@{$self->{posts}}) {
1175 0 ▶ unless ($self->{update_overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"update_overwrite"}) 0 0 0
1176 # coordinate topic_id
1177 0 my $new_topic_id;
1178 $sth = $self->{dbh}->prepare("SELECT new FROM $self->{db_prefix}"
1179 0 . "topics_trans WHERE orig=" . $_->{topic_id});
1180 0 $sth->execute;
1181 0 $sth->bind_columns(\$new_topic_id);
1182 0 ▶ if ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
1183 0 $_->{topic_id} = $new_topic_id;
1184 }
1185 }
1186  
1187 }
1188  
1189 0 $self->insert_array($self->{posts}, 'posts');
1190 0 $self->insert_array($self->{posts_text}, 'posts_text');
1191 }
1192  
1193 ####################
1194 # helper functions #
1195 ####################
1196  
1197 0 ▶sub empty_tables {
Subroutine empty_tables: not called CC=6 SCAR=37.4
Pod documented
1198 0 my $self = shift;
1199 0 for (@{$self->{db_empty}}) {
1200 0 ▶ if ($_ eq 'users') {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ eq 'users') { } 0 0 0
elsif ($_ eq 'groups') { } 0 0 0
elsif ($_ eq 'user_group') { } 0 0 0
1201 0 my $sth = $self->{dbh}->prepare("SELECT * FROM $self->{db_prefix}" . "users WHERE user_id=1");
1202 0 $sth->execute;
1203 0 ▶ $self->{dbh}->do("UPDATE $self->{db_prefix}" . "users SET user_id=1 WHERE user_id=2")
Branch: 1 branch
BranchTrueFalseTotal
unless $sth->fetch 0 0 0
1204 unless $sth->fetch;
1205 0 $self->{dbh}->do("DELETE FROM $self->{db_prefix}" . "users WHERE user_id!=1 AND user_id!=-1");
1206 } elsif($_ eq 'groups') {
1207 0 $self->{dbh}->do("DELETE FROM $self->{db_prefix}" . "groups WHERE group_id>2");
1208 } elsif($_ eq 'user_group') {
1209 0 $self->{dbh}->do("DELETE FROM $self->{db_prefix}" . "user_group WHERE group_id>2");
1210 } else {
1211 0 $self->{dbh}->do("DELETE FROM " . $self->{db_prefix} . $_);
1212 }
1213 }
1214 }
1215  
1216 # $_[0]=$array_ref, $_[1]=$table
1217 0 ▶sub insert_array {
Subroutine insert_array: not called CC=5 SCAR=34.0
Pod undocumented
1218 0 my $self = shift;
1219 0 my ($aref, $table) = @_;
1220 0 for my $row (@$aref) {
1221 0 my $query;
1222 0 my @cols = keys %$row;
1223 0 ▶ for (my $i = 0; $i < @cols; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @cols) 0 0 0
1224 0 ▶ $query .= ',' if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 0 0
1225 0 $query .= "$cols[$i]=" . $self->{dbh}->quote($$row{$cols[$i]});
1226 }
1227 0 $query = "INSERT $self->{db_prefix}$table SET " . $query . " ON DUPLICATE KEY UPDATE " . $query;
1228 0 eval {
1229 0 $self->{dbh}->do($query);
1230 };
1231 0 ▶ croak ("$query\n$@\n") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1232 ##print "$query\n";
1233 }
1234 }
1235  
1236 # $_[0]=$mech
1237 # returns an array ref with page numbers
1238 0 ▶sub number_of_pages {
Subroutine number_of_pages: not called CC=13 SCAR=52.0
Pod undocumented
1239 0 my $self = shift;
1240 0 my ($mech, $type) = @_;
1241 0 my %page;
1242 0 $page{0} = 1;
1243 0 my $success;
1244 0 (my $url_ident = $mech->uri) =~ s%.*/(.*?)\?.*%$1%;
1245 0 $success = $mech->find_all_links(url_regex => qr/^${url_ident}.*start=\d+/);
1246 0 ▶ if (@$success) {
Branch: 3 branches
BranchTrueFalseTotal
if (@$success) { } 0 0 0
elsif ($self->{'alternative_page_number_regex_forum'} ne qr// and $type eq 'forum') { } 0 0 0
elsif ($self->{'alternative_page_number_regex_topic'} ne qr// and $type eq 'topic') { } 0 0 0
1247 0 for(@$success) {
1248 0 $_->url =~ /start=(\d+)(\D|$)/;
1249 0 $page{$1} = 1;
1250 #print $_->url . " : '$1'\n"
1251 }
1252 ▶ } elsif($self->{alternative_page_number_regex_forum} ne qr// && $type eq 'forum') {
Condition0%0/3
$self->{"alternative_page_number_regex_forum"} ne qr// and $type eq "forum"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"alternative_page_number_regex_forum"} ne qr// and $type eq "forum"
$self->{"alternative_page_number_regex_forum"} ne qr// $type eq "forum"
Truth table0%0/3
A and B
A= $self->{"alternative_page_number_regex_forum"} ne qr//B= $type eq "forum"
ABresult
0X0
100
111
1253 0 $success = $mech->find_all_links(url_regex => $self->{alternative_page_number_regex_forum});
1254 0 ▶ if (@$success) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$success) 0 0 0
1255 0 for(@$success) {
1256 0 $_->url =~ $self->{alternative_page_number_regex_forum};
1257 0 $page{$1} = 1;
1258 }
1259 }
1260 ▶ } elsif($self->{alternative_page_number_regex_topic} ne qr// && $type eq 'topic') {
Condition0%0/3
$self->{"alternative_page_number_regex_topic"} ne qr// and $type eq "topic"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"alternative_page_number_regex_topic"} ne qr// and $type eq "topic"
$self->{"alternative_page_number_regex_topic"} ne qr// $type eq "topic"
Truth table0%0/3
A and B
A= $self->{"alternative_page_number_regex_topic"} ne qr//B= $type eq "topic"
ABresult
0X0
100
111
1261 0 $success = $mech->find_all_links(url_regex => $self->{alternative_page_number_regex_topic});
1262 0 ▶ if (@$success) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$success) 0 0 0
1263 0 for(@$success) {
1264 0 $_->url =~ $self->{alternative_page_number_regex_topic};
1265 0 $page{$1} = 1;
1266 }
1267 }
1268 }
1269 # fill in missing pages
1270 0 my @page_keys = sort {$a <=> $b} keys %page;
1271 0 ▶ if (scalar(@page_keys) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @page_keys > 1) 0 0 0
1272 0 my $per_page = $page_keys[1] - $page_keys[0];
1273 0 ▶ for(my $p=$page_keys[0]; $p<=$page_keys[-1]; $p+=$per_page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p <= $page_keys[-1]) 0 0 0
1274 0 $page{$p} = 1;
1275 }
1276 }
1277 # return array ref
1278 0 [sort {$a <=> $b} keys %page];
1279 }
1280  
1281 0 ▶sub forum_url_for_page {
Subroutine forum_url_for_page: not called CC=1 SCAR=6.9
Pod undocumented
1282 0 my $self = shift;
1283 0 my ($url, $forum_id, $page) = @_;
1284  
1285 0 $url =~ s/&start=\d+//;
1286 0 $url .= "&start=$page";
1287 0 return $url;
1288 }
1289  
1290 0 ▶sub topic_url_for_page {
Subroutine topic_url_for_page: not called CC=1 SCAR=6.9
Pod undocumented
1291 0 my $self = shift;
1292 0 my ($url, $topic_id, $page) = @_;
1293  
1294 0 $url =~ s/&start=\d+//;
1295 0 $url .= "&start=$page";
1296 0 return $url;
1297 }
1298  
1299 0 ▶sub memberlist_url_for_page {
Subroutine memberlist_url_for_page: not called CC=1 SCAR=6.9
Pod undocumented
1300 0 my $self = shift;
1301 0 my ($url, $page) = @_;
1302  
1303 0 $url =~ s/&start=\d+//;
1304 0 $url .= "&start=$page";
1305 0 return $url;
1306 }
1307  
1308 # $_[0]=string_ref, $_[1]=$prepare_html
1309 0 ▶sub html_to_bbcode {
Subroutine html_to_bbcode: not called CC=40 SCAR=74.0
Pod undocumented
1310 0 my $self = shift;
1311 0 my ($html, $prepare_html) = @_;
1312 0 ▶ if ($prepare_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prepare_html) 0 0 0
1313 ## discard excess whitespace
1314 0 $$html =~ s/\s{2,}/ /g; # trim spaces
1315 0 $$html =~ s/(>|^)\s+(<|$)/$1$2/smg; # delete whitespace between tags
1316 0 $$html =~ s/\n//g; # no need for that
1317 ## replace <br /> with \n
1318 0 $$html =~ s(<br />)(\n)isg;
1319 }
1320 0 my $text;
1321 my @close_tag; # push and pop them as they come along (LIFO)
1322 0 my $parse;
1323 0 $parse = HTML::TokeParser::Simple->new( $_[0] );
1324 0 $parse->unbroken_text( 1 );
1325 0 my $token;
1326 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
1327 0 ▶ if ($token->is_start_tag('span')) {
Branch: 13 branches
BranchTrueFalseTotal
if ($token->is_start_tag('span')) { } 0 0 0
elsif ($token->is_end_tag('span')) { } 0 0 0
elsif ($token->is_start_tag('table')) { } 0 0 0
elsif ($token->is_start_tag('ul')) { } 0 0 0
elsif ($token->is_end_tag('ul')) { } 0 0 0
elsif ($token->is_start_tag('ol') and $token->get_attr('type') eq '1') { } 0 0 0
elsif ($token->is_start_tag('ol') and $token->get_attr('type') eq 'a') { } 0 0 0
elsif ($token->is_end_tag('ol')) { } 0 0 0
elsif ($token->is_start_tag('li')) { } 0 0 0
elsif ($token->is_tag('img')) { } 0 0 0
elsif ($token->is_start_tag('a')) { } 0 0 0
elsif ($token->is_end_tag('a')) { } 0 0 0
elsif ($token->is_text) { } 0 0 0
1328 0 ▶ if ($token->get_attr('style') eq 'font-weight: bold') {
Branch: 5 branches
BranchTrueFalseTotal
if ($token->get_attr('style') eq 'font-weight: bold') { } 0 0 0
elsif ($token->get_attr('style') eq 'font-style: italic') { } 0 0 0
elsif ($token->get_attr('style') eq 'text-decoration: underline') { } 0 0 0
elsif ($token->get_attr('style') =~ /color: (.*)$/) { } 0 0 0
elsif ($token->get_attr('style') =~ /font-size: (\d*)px/) { } 0 0 0
1329 0 $text .= "[b:$self->{bbcode_uid}]";
1330 0 push @close_tag, "[/b:$self->{bbcode_uid}]";
1331 } elsif ($token->get_attr('style') eq 'font-style: italic') {
1332 0 $text .= "[i:$self->{bbcode_uid}]";
1333 0 push @close_tag, "[/i:$self->{bbcode_uid}]";
1334 } elsif ($token->get_attr('style') eq 'text-decoration: underline') {
1335 0 $text .= "[u:$self->{bbcode_uid}]";
1336 0 push @close_tag, "[/u:$self->{bbcode_uid}]";
1337 } elsif ($token->get_attr('style') =~ 'color: (.*)$') {
1338 0 $text .= "[color=$1:$self->{bbcode_uid}]";
1339 0 push @close_tag, "[/color:$self->{bbcode_uid}]";
1340 } elsif ($token->get_attr('style') =~ 'font-size: (\d*)px') {
1341 0 $text .= "[size=$1:$self->{bbcode_uid}]";
1342 0 push @close_tag, "[/size:$self->{bbcode_uid}]";
1343 } else { # some other <span> we don't care about
1344 0 push @close_tag, "";
1345 }
1346 } elsif ($token->is_end_tag('span')) {
1347 0 $text .= pop @close_tag;
1348 } elsif ($token->is_start_tag('table')) { # quote or code
1349 #print "|>", $parse->peek(7), "<|\n";
1350 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
1351 #$token = $parse->get_token until $token->is_text && $token->as_is =~ /^(.*?) ?$self->{quote_string}:$/s;
1352 0 my $author = '';
1353 0 ▶ while($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
1354 0 ▶ if($token->is_text && $token->as_is =~ /^(.*?) ?$self->{quote_string}:$/s) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->is_text and $token->as_is =~ /^(.*?) ?$self->{'quote_string'}:$/s) { } 0 0 0
elsif ($token->is_end_tag('td')) { } 0 0 0
Condition0%0/3
$token->is_text and $token->as_is =~ /^(.*?) ?$self->{"quote_string"}:$/s
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_text and $token->as_is =~ /^(.*?) ?$self->{"quote_string"}:$/s
$token->is_text $token->as_is =~ /^(.*?) ?$self->{"quote_string"}:$/s
Truth table0%0/3
A and B
A= $token->is_textB= $token->as_is =~ /^(.*?) ?$self->{"quote_string"}:$/s
ABresult
0X0
100
111
1355 #print $token->as_is, "\n";
1356 0 $author = $1;
1357 0 last;
1358 } elsif($token->is_end_tag('td')) {
1359 0 last;
1360 }
1361 }
1362 #print $author, "\n";
1363 0 ▶ $token = $parse->get_token until $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
$token->is_start_tag("td") or do { $token = $parse->get_token } 0 0 0
1364 #print "test\n";
1365 0 ▶ if ($token->get_attr('class') eq 'quote') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->get_attr('class') eq 'quote') { } 0 0 0
elsif ($token->get_attr('class') eq 'code') { } 0 0 0
1366 0 ▶ if ($author eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($author eq '') { } 0 0 0
1367 0 $text .= "[quote:$self->{bbcode_uid}]";
1368 } else {
1369 0 $text .= "[quote:$self->{bbcode_uid}=\"$author\"]";
1370 }
1371 0 push @close_tag, "[/quote:$self->{bbcode_uid}]";
1372 } elsif ($token->get_attr('class') eq 'code') {
1373 0 $text .= "[code:$self->{bbcode_uid}]";
1374 0 push @close_tag, "[/code:$self->{bbcode_uid}]";
1375 }
1376 0 my $counter;
1377 my $in_table;
1378 0 ▶ while ($token = $parse->get_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $parse->get_token) 0 0 0
1379 0 ▶ $counter++ if $token->is_start_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_start_tag("td") 0 0 0
1380 0 ▶ $counter-- if $token->is_end_tag('td');
Branch: 1 branch
BranchTrueFalseTotal
if $token->is_end_tag("td") 0 0 0
1381 0 ▶ last if $counter < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $counter < 0 0 0 0
1382 0 $in_table .= $token->as_is;
1383 }
1384 # catch the bbcode inside
1385 0 $text .= ${ $self->html_to_bbcode(\$in_table) };
1386 0 $text .= pop @close_tag;
1387 } elsif ($token->is_start_tag('ul')) {
1388 0 $text .= "[list:$self->{bbcode_uid}]";
1389 0 push @close_tag, "[/list:u:$self->{bbcode_uid}]";
1390 } elsif ($token->is_end_tag('ul')) {
1391 0 $text .= pop @close_tag;
1392 ▶ } elsif ($token->is_start_tag('ol')
Condition0%0/3
$token->is_start_tag("ol") and $token->get_attr("type") eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("ol") and $token->get_attr("type") eq 1
$token->is_start_tag("ol") $token->get_attr("type") eq 1
Truth table0%0/3
A and B
A= $token->is_start_tag("ol")B= $token->get_attr("type") eq 1
ABresult
0X0
100
111
1393 && $token->get_attr('type') eq '1') {
1394 0 $text .= "[list=1:$self->{bbcode_uid}]";
1395 0 push @close_tag, "[/list:o:$self->{bbcode_uid}]";
1396 ▶ } elsif ($token->is_start_tag('ol')
Condition0%0/3
$token->is_start_tag("ol") and $token->get_attr("type") eq "a"
!ll&&!rl&&r
000
MC/DC0%0/2
$token->is_start_tag("ol") and $token->get_attr("type") eq "a"
$token->is_start_tag("ol") $token->get_attr("type") eq "a"
Truth table0%0/3
A and B
A= $token->is_start_tag("ol")B= $token->get_attr("type") eq "a"
ABresult
0X0
100
111
1397 && $token->get_attr('type') eq 'a') {
1398 0 $text .= "[list=a:$self->{bbcode_uid}]";
1399 0 push @close_tag, "[/list:o:$self->{bbcode_uid}]";
1400 } elsif ($token->is_end_tag('ol')) {
1401 0 $text .= pop @close_tag;
1402 } elsif ($token->is_start_tag('li')) {
1403 0 $text .= "[*:$self->{bbcode_uid}]";
1404 } elsif ($token->is_tag('img')) {
1405 # check for smiles
1406 0 my $is_smile;
1407 0 my $src = $token->get_attr('src');
1408 0 for (keys %{$self->{smiles}}) {
1409 0 ▶ if ( $src =~ /\/$_\.gif/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src =~ m[/$_\.gif]) 0 0 0
1410 0 $text .= $self->{smiles}{$_};
1411 0 $is_smile = 1;
1412 0 last;
1413 }
1414 }
1415 0 ▶ unless ($is_smile) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_smile) 0 0 0
1416 # a simple image
1417 0 $text .= "[img:$self->{bbcode_uid}]"
1418 . $token->get_attr('src')
1419 . "[/img:$self->{bbcode_uid}]";
1420 }
1421 } elsif ($token->is_start_tag('a')) {
1422 0 ▶ if ($token->get_attr('href') =~ /mailto:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->get_attr("href") =~ /mailto:/) 0 0 0
1423 0 push @close_tag, "";
1424 0 next;
1425 }
1426 0 $text .= "[url="
1427 . $token->get_attr('href')
1428 . "]";
1429 0 push @close_tag, "[/url]";
1430 } elsif ($token->is_end_tag('a')) {
1431 0 $text .= pop @close_tag;
1432 } elsif ($token->is_text) {
1433 0 $text .= $token->as_is;
1434 }
1435 }
1436 0 \$text;
1437 }
1438  
1439 # $_[0]=$string, $_[1]=$date_format_regex, $_[2]=$date_pos_arrray-ref
1440 0 ▶sub parse_date {
Subroutine parse_date: not called CC=16 SCAR=56.1
Pod undocumented
1441 0 my $self = shift;
1442 0 my ($str, $date_format, $date_pos) = @_;
1443 0 my %date_vars;
1444 my %month_number;
1445 0 ▶ for( my $i=0; $i<@{$self->{months}}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$self->{"months"};}) 0 0 0
1446 0 $month_number{$self->{months}[$i]} = $i;
1447 }
1448  
1449 0 $_ = $str;
1450 0 ▶ return 0 unless /$date_format/i;
Branch: 1 branch
BranchTrueFalseTotal
unless /$date_format/i 0 0 0
1451 0 my @res = /$date_format/i;
1452 0 ▶ for (my $i = 0; $i < @res; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @res) 0 0 0
1453 0 $date_vars{$$date_pos[$i]} = $res[$i];
1454 }
1455  
1456 # strip leading zero
1457 0 for (qw(seconds minutes hour day_of_month)) {
1458 0 ▶ $date_vars{$_} =~ s/^0(\d)/$1/ if exists $date_vars{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $date_vars{$_} 0 0 0
1459 }
1460  
1461 # AM/PM
1462 0 ▶ if (exists $date_vars{am_pm}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $date_vars{"am_pm"}) 0 0 0
1463 $date_vars{hour} += 12 if $date_vars{am_pm} =~ /pm/i
1464 0 ▶ && $date_vars{hour} != 12;
Branch: 1 branch
BranchTrueFalseTotal
if $date_vars{"am_pm"} =~ /pm/i and $date_vars{"hour"} != 12 0 0 0
Condition0%0/3
$date_vars{"am_pm"} =~ /pm/i and $date_vars{"hour"} != 12
!ll&&!rl&&r
000
MC/DC0%0/2
$date_vars{"am_pm"} =~ /pm/i and $date_vars{"hour"} != 12
$date_vars{"am_pm"} =~ /pm/i $date_vars{"hour"} != 12
Truth table0%0/3
A and B
A= $date_vars{"am_pm"} =~ /pm/iB= $date_vars{"hour"} != 12
ABresult
0X0
100
111
1465 $date_vars{hour} -= 12 if $date_vars{am_pm} =~ /am/i
1466 0 ▶ && $date_vars{hour} == 12;
Branch: 1 branch
BranchTrueFalseTotal
if $date_vars{"am_pm"} =~ /am/i and $date_vars{"hour"} == 12 0 0 0
Condition0%0/3
$date_vars{"am_pm"} =~ /am/i and $date_vars{"hour"} == 12
!ll&&!rl&&r
000
MC/DC0%0/2
$date_vars{"am_pm"} =~ /am/i and $date_vars{"hour"} == 12
$date_vars{"am_pm"} =~ /am/i $date_vars{"hour"} == 12
Truth table0%0/3
A and B
A= $date_vars{"am_pm"} =~ /am/iB= $date_vars{"hour"} == 12
ABresult
0X0
100
111
1467 }
1468 # month name
1469 $date_vars{mon} = $month_number{lc substr($date_vars{month_name}, 0, 3)}
1470 0 ▶ if exists $date_vars{month_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $date_vars{"month_name"} 0 0 0
1471 # month
1472 0 ▶ $date_vars{mon} = $date_vars{month} - 1 if exists $date_vars{month};
Branch: 1 branch
BranchTrueFalseTotal
if exists $date_vars{"month"} 0 0 0
1473 # get rid of warnings
1474 0 for (qw(seconds minutes day_of_month mon year)) {
1475 0 ▶ $date_vars{$_} = 0 unless exists $date_vars{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $date_vars{$_} 0 0 0
1476 }
1477 0 ▶ $date_vars{hour} = 12 unless exists $date_vars{hour};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $date_vars{"hour"} 0 0 0
1478 # return timestamp
1479 timelocal( $date_vars{seconds}, $date_vars{minutes}, $date_vars{hour},
1480 0 $date_vars{day_of_month}, $date_vars{mon}, $date_vars{year} );
1481 }
1482  
1483 # $_[0]=$array_ref
1484 0 ▶sub print_AoH {
Subroutine print_AoH: not called CC=3 SCAR=24.8
Pod undocumented
1485 0 my $self = shift;
1486 0 my $AoHr = $_[0];
1487 0 print scalar @$AoHr, " elements:\n";
1488 0 for my $row (@$AoHr) {
1489 0 print "==>";
1490 0 for (sort keys %$row) {
1491 0 print "\t$_ => \"$row->{$_}\"\n";
1492 }
1493 0 print "\n";
1494 }
1495 }
1496  
1497 0 ▶sub update_forum_first_last_post {
Subroutine update_forum_first_last_post: not called CC=2 SCAR=17.9
Pod undocumented
1498 0 my $self = shift;
1499 0 my ($forum_id) = @_;
1500 0 for (qw(ASC DESC)) {
1501 0 $self->{dbh}->do( "UPDATE $self->{db_prefix}" . "forums SET forum_last_post_id="
1502 . "(SELECT p.post_id FROM $self->{db_prefix}" . "posts p, "
1503 . "$self->{db_prefix}" . "topics t "
1504 . "WHERE p.topic_id = t.topic_id "
1505 . "AND t.forum_id =$forum_id "
1506 . "ORDER BY p.post_time $_, p.post_id $_ "
1507 . "LIMIT 1) WHERE forum_id=$forum_id");
1508 }
1509 }
1510  
1511 0 ▶sub get_last_timestamp {
Subroutine get_last_timestamp: not called CC=1 SCAR=6.9
Pod undocumented
1512 0 my $self = shift;
1513 0 my $sth = $self->{dbh}->prepare("SELECT MAX(post_time) FROM $self->{db_prefix}" . "posts");
1514 0 $sth->execute;
1515 0 $sth->bind_columns(\$self->{last_timestamp});
1516 0 $sth->fetch;
1517 }
1518  
1519 0 ▶sub get_new_admin {
Subroutine get_new_admin: not called CC=1 SCAR=6.9
Pod undocumented
1520 0 my $self = shift;
1521 0 my $sth = $self->{dbh}->prepare("SELECT user_id, username FROM $self->{db_prefix}" . "users ORDER BY user_id DESC LIMIT 1");
1522 0 $sth->execute;
1523 0 $sth->bind_columns(\$self->{new_admin_id}, \$self->{new_admin_username});
1524 0 $sth->fetch;
1525 }
1526  
1527 0 ▶sub create_groups {
Subroutine create_groups: not called CC=2 SCAR=17.9
Pod undocumented
1528 0 my $self = shift;
1529 0 my $sth = $self->{dbh}->prepare("SELECT user_id FROM $self->{db_prefix}users WHERE user_id NOT IN ( SELECT user_id FROM $self->{db_prefix}user_group )");
1530 0 $sth->execute;
1531 0 my @row;
1532 0 ▶ while(@row = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (@row = $sth->fetchrow_array) 0 0 0
1533 #print "$row[0]\n";
1534 0 my $gsth = $self->{dbh}->prepare("INSERT INTO $self->{db_prefix}groups SET group_description='Personal User'");
1535 0 $gsth->execute;
1536 0 my $group_id = $gsth->{mysql_insertid};
1537 0 my $ugsth = $self->{dbh}->prepare("INSERT INTO $self->{db_prefix}user_group SET group_id=?, user_id=?, user_pending=0");
1538 0 $ugsth->execute($group_id, $row[0]);
1539 }
1540 }
1541  
1542 0 ▶sub compute_url {
Subroutine compute_url: not called CC=2 SCAR=17.9
Pod undocumented
1543 0 my $self = shift;
1544 0 my ($url1, $url2) = @_;
1545 0 my $url;
1546 0 ($url = $self->{mmech}->uri) =~ s%^(.*)/.*?(\?)|$%$1/$url1$2%;
1547 0 ▶ if ($url =~ /\?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /\?/) { } 0 0 0
1548 0 $url .= "&";
1549 } else {
1550 0 $url .= "?";
1551 }
1552 0 $url .= $url2;
1553 }
1554  
1555 0 ▶sub reaper {
Subroutine reaper: not called CC=2 SCAR=17.9
Pod undocumented
1556 0 ▶ while (waitpid(-1, WNOHANG) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitpid(-1, 1) > 0) 0 0 0
1557 0 $children--;
1558 }
1559 0 $SIG{CHLD} = \&reaper;
1560 }
1561 1 $SIG{CHLD} = \&reaper;
1562  
1563 # takes a function reference as argument
1564 # remember to "wait for 1..$children;" after the loop
1565 0 ▶sub parallelize {
Subroutine parallelize: not called CC=6 SCAR=37.4
Pod undocumented
1566 0 my $self = shift;
1567 0 my ($func_ref) = @_;
1568 0 ▶ if($self->{max_children} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'max_children'} < 2) { } 0 0 0
1569 # avoid forking when parallelism is not requested (workaround for a windoze bug)
1570 0 &$func_ref;
1571 } else {
1572 0 ▶ if ($children < $self->{max_children}) { # fork a subprocess
Branch: 1 branch
BranchTrueFalseTotal
if ($children < $self->{"max_children"}) 0 0 0
1573 0 ▶ if (my $pid = fork) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) { } 0 0 0
1574 # parent
1575 0 $children++;
1576 0 ▶ if ($children == $self->{max_children}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children == $self->{"max_children"}) 0 0 0
1577 0 wait;
1578 0 $children--;
1579 }
1580 } else {
1581 # child
1582 0 ▶ croak "can't fork" if undef $pid;
Branch: 1 branch
BranchTrueFalseTotal
if undef $pid 0 0 0
1583 # the db link was destroyed by forking. create it again
1584 0 $self->{dbh}{InactiveDestroy} = 1;
1585 $self->{dbh} = DBI->connect("DBI:mysql:database=$self->{db_database};host=$self->{db_host};mysql_compression=$self->{db_compression}",
1586 0 $self->{db_user}, $self->{db_passwd}, {AutoCommit => 1, RaiseError => 1});
1587 # run function
1588 0 &$func_ref;
1589 0 exit;
1590 }
1591 }
1592 }
1593 }
1594  
1595 #########################
1596 # integrating functions #
1597 #########################
1598  
1599 0 ▶sub scrape_forum_common_raw {
Subroutine scrape_forum_common_raw: not called CC=8 SCAR=42.8
Pod undocumented
1600 0 my $self = shift;
1601 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
1602 0 print "getting categories and forums...";
1603 }
1604 0 $self->get_categories_and_forums();
1605 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
1606 0 print "\n";
1607 }
1608 0 for (@{$self->{forums}}) {
1609 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
1610 0 print "getting the topics from forum #", $_->{forum_id}, "\n";
1611 }
1612 0 $self->get_topics( $_->{forum_id} );
1613 0 for (@{$self->{topics}}) {
1614 $self->parallelize(
1615 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1616 0 $self->get_posts( $_->{topic_id} );
1617 0 $self->insert_array([$_], "topics");
1618 }
1619 0 );
1620 }
1621 0 @{$self->{topics}} = ();
1622 }
1623 #wait for 1..$children;
1624 0 ▶ 1 while waitpid(-1, WNOHANG)>0; # reaps childs
Branch: 1 branch
BranchTrueFalseTotal
waitpid(-1, 1) > 0 and do { '???' } 0 0 0
1625 0 $self->update_forum_first_last_post($_->{forum_id}) for @{$self->{forums}};
1626 }
1627  
1628 # wrapper for scrape_forum_common_raw() that retries in case of errors
1629 0 ▶sub scrape_forum_common {
Subroutine scrape_forum_common: not called CC=3 SCAR=24.8
Pod documented
1630 0 my $self = shift;
1631 0 for (1..$self->{max_tries}) {
1632 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->scrape_forum_common_raw(@_); 1 } } and last 0 0 0
1633 0 $self->scrape_forum_common_raw(@_);
1634 0 1;
1635 } and last;
1636 0 print "failed (try $_ out of $self->{max_tries})\n";
1637 0 sleep(1)
1638 }
1639 }
1640  
1641 0 ▶sub update_forum_common_raw {
Subroutine update_forum_common_raw: not called CC=6 SCAR=37.4
Pod undocumented
1642 0 my $self = shift;
1643 0 $self->{db_insert} = 0;
1644 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
1645 0 print "getting categories and forums...";
1646 }
1647 0 $self->get_categories_and_forums();
1648 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
1649 0 print "\n";
1650 }
1651 0 $self->insert_array($self->{categories}, 'categories');
1652 0 $self->insert_array($self->{forums}, 'forums');
1653 0 $self->get_last_timestamp();
1654 0 for (@{$self->{forums}}) {
1655 0 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 0 0
1656 0 print "updating topics from forum #", $_->{forum_id}, "\n";
1657 }
1658 0 $self->update_topics($_->{forum_id});
1659 0 for (@{$self->{topics}}) {
1660 0 $self->update_posts($_->{topic_id});
1661 0 $self->update_topics_insert($_);
1662 0 $self->update_posts_insert();
1663 }
1664 0 @{$self->{topics}} = ();
1665 0 $self->update_forum_first_last_post($_->{forum_id});
1666 }
1667 }
1668  
1669 # wrapper for update_forum_common_raw() that retries in case of errors
1670 0 ▶sub update_forum_common {
Subroutine update_forum_common: not called CC=3 SCAR=24.8
Pod documented
1671 0 my $self = shift;
1672 0 for (1..$self->{max_tries}) {
1673 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->update_forum_common_raw(@_); 1 } } and last 0 0 0
1674 0 $self->update_forum_common_raw(@_);
1675 0 1;
1676 } and last;
1677 0 print "failed (try $_ out of $self->{max_tries})\n";
1678 0 sleep(1)
1679 }
1680 }
1681  
1682  
1683 1 1;
1684 __END__
↑ Summary