Bot.pm

filter: Statementstmt 77.7% 147 / 189 Branchbran 55.0% 44 / 80 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 30 / 35 Podpod 88.4% 23 / 26 totaltotal 72.8% 244 / 335 CC 46 SCAR 21.0
CC
46
Cov
70%
check_allowed
42.0
scrape
30.0
scrape_page
12.0
CRAP 8.2
↑ Summary Event.pm »
1 package WWW::Wikevent::Bot;
2 #
3 # Copyright 2007 Mark Jaroski
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of either:
7 #
8 # a) the GNU General Public License as published by the Free Software
9 # Foundation; either version 3, or (at your option) any later version,
10 # or
11 # b) the "Artistic License" which comes with this Kit.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
16 # GNU General Public License or the Artistic License for more details.
17 #
18 # You should have received a copy of the Artistic License with this Kit,
19 # in the file named "Artistic".
20 #
21 # You should also have received a copy of the GNU General Public License
22 # along with this program in the file named "Copying". If not, write to
23 # the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
24 # Boston, MA 02111-1307, USA or visit their web page on the internet at
25 # http://www.gnu.org/copyleft/gpl.html.
26  
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use WWW::Mediawiki::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use WWW::Wikevent::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Date::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 our %EXPORT_TAGS = (
38 options => [qw(OPT_YES OPT_NO OPT_DEFAULT OPT_KEEP)],
39 );
40 1 our @EXPORT_OK = map { @{$EXPORT_TAGS{$_}} } keys %EXPORT_TAGS;
41  
42 1 our $VERSION = 0.2.0;
43  
44 =head1 NAME
45  
46 WWW::Wikevent::Bot
47  
48 =cut
49  
50 =head1 SYNOPSIS
51  
52 use WWW::Wikevent::Bot;
53 use HTML::TreeBuilder;
54 use utf8;
55  
56 my $bot = WWW::Wikevent::Bot->new();
57 $bot->name( 'HideoutBot' );
58 $bot->url( 'http://www.hideoutchicago.com/schedule.html' );
59 $bot->sample( 'sample.html' );
60 $bot->encoding( 'utf8' );
61  
62 $bot->parser( sub {
63 my ( $bot, $html ) = @_;
64
65 # Use HTML::TreeBuilder and HTML::Element, or if you prefer
66 # HTML::TokeParser to parse the HTML down to whatever elements
67 # contains events, then ...
68 foreach my $container ( @event_containers ) {
69 my $event = $bot->add_event();
70  
71 # build up the event using methods of L<HTML::Wikevent::Event>
72 }
73  
74 # Figure out the next page to scrape (not needed if you are parsing
75 # by month) and set
76  
77 $bot->url( $next_page_to_scrape );
78 });
79
80 $bot->scrape();
81 $bot->upload();
82
83 =cut
84  
85 =head1 DESCRIPTION
86  
87 WWW::Wikevent::Bot is a package which will help you write scraper scripts
88 for gathering events from venue and artist websites and for inclusion in
89 the Free content events compendium, Wikevent.
90  
91 The module takes care of the tedium of interaction with the website, and
92 leaves to you the fun work of writing the scraper subroutine for the venue
93 or artist you are interested in.
94  
95 =cut
96  
97 =head1 CONSTANTS
98  
99 item $SEEN_FILE
100  
101 =cut
102  
103 1 my $SEEN_FILE = '.processed_events';
104  
105 1 my $Mvs = WWW::Mediawiki::Client->new();
106 1 my $Ua = LWP::UserAgent->new();
107  
108 1 my @Events;
109  
110  
111 =head1 CONSTRUCTORS
112  
113 =cut
114  
115 =head2 new
116  
117 Creates a new bot object.
118  
119 =cut
120  
121 4 ▶sub new {
Subroutine new: called CC=5 SCAR=21.6
Pod documented
122 4 my $pkg = shift;
123 4 my %init = @_;
124 4 my $self = bless {};
125 4 foreach my $key ( keys %init ) {
126 0 ▶ if ( $key eq 'name' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq 'name') { } 0 0 0
elsif ($key eq 'parser') { } 0 0 0
elsif ($key eq 'url') { } 0 0 0
127 0 $self->name( $init{$key} );
128 } elsif ( $key eq 'parser' ) {
129 0 $self->parser( $init{$key} );
130 } elsif ( $key eq 'url' ) {
131 0 $self->url( $init{$key} );
132 }
133 }
134 4 $self->{'events'} = [];
135 4 $self->{'months'} = 3;
136 4 $self->{'last_url'} = '';
137 4 $self->load_remembered_events();
138 4 return $self;
139 }
140  
141 =head1 ACCESSORS
142  
143 =cut
144  
145 =head2 name
146
147 $bot->name( $bot_name );
148  
149 The name of your bot.
150  
151 This setting will be used to control where your bot will submit information
152 about itself and the list of events it scrapes on each run.
153  
154 =cut
155  
156 3 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod documented
157 3 my ( $self, $name ) = @_;
158 3 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 2 1 3
159 2 $self->{'name'} = $name;
160 2 $self->user_dir( "User:$self->{'name'}" );
161 2 $self->user_page( "User:$self->{'name'}.wiki" );
162 2 $self->shows_page( "User:$self->{'name'}/Shows.wiki" );
163 }
164 3 return $self->{'name'};
165 }
166  
167 =head2 events
168  
169 my @events = $bot->events()
170  
171 or
172  
173 my $event_ref = $bot->events()
174  
175 The list of events which this bot has scraped (so far).
176  
177 =cut
178  
179 13 ▶sub events {
Subroutine events: called CC=2 SCAR=6.9
Pod documented
180 13 my $self = shift;
181 13 ▶ return wantarray ? @{$self->{'events'}} : $self->{'events'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 8 13
182 }
183  
184 =head2 sample
185  
186 $bot->sample( 'somepage.html' );
187  
188 A local file containing a sample page to scrape while you are building and
189 debugging your parser subroutine.
190  
191 =cut
192  
193 4 ▶sub sample {
Subroutine sample: called CC=2 SCAR=6.9
Pod documented
194 4 my ( $self, $sample ) = @_;
195 4 ▶ $self->{'sample'} = $sample if $sample;
Branch: 1 branch
BranchTrueFalseTotal
if $sample 2 2 4
196 4 return $self->{'sample'};
197 }
198  
199 =head2 charset
200
201 $bot->charset( 'utf8' );
202  
203 The charset of the target site/page.
204  
205 Sometimes the charset is detected incorrectly, or even set incorrectly in
206 venue and artist webpages. This lets you override.
207  
208 =cut
209  
210 3 ▶sub charset {
Subroutine charset: called CC=2 SCAR=6.9
Pod documented
211 3 my ( $self, $charset ) = @_;
212 3 ▶ $self->{'charset'} = $charset if $charset;
Branch: 1 branch
BranchTrueFalseTotal
if $charset 1 2 3
213 3 return $self->{'charset'};
214 }
215  
216 =head2 encoding
217  
218 An alias for charset, if you prefer.
219  
220 =cut
221  
222 3 ▶sub encoding {
Subroutine encoding: called CC=2 SCAR=6.9
Pod documented
223 3 my ( $self, $charset ) = @_;
224 3 ▶ $self->{'charset'} = $charset if $charset;
Branch: 1 branch
BranchTrueFalseTotal
if $charset 1 2 3
225 3 return $self->{'charset'};
226 }
227  
228 =head2 url
229  
230 $bot->url( 'http://venue.com/schedule.html' );
231  
232 The next URL to scrape.
233  
234 Initially you should set this to the first page which your scraper bot
235 should look at. Afterwords if there are more pages to scrape you'll set it
236 again in your parser subroutine.
237  
238 If the site you're scraping has calendar pages with elements of the date in
239 the URL you can put Date::Format placeholders in the your URL string, as
240 in:
241  
242 $bot->url( 'http://venue.com/calendar.html?year=%Ymonth=%L' );
243  
244 .. and your bot will scrape C<months> months ahead from the current month,
245 whatever that is. You can of course override this behaviour by specifying
246 a new URL to parse in the parser subroutine, but then you'll have to do all
247 of the date calculation yourself.
248  
249 =cut
250  
251 36 ▶sub url {
Subroutine url: called CC=2 SCAR=6.9
Pod documented
252 36 my ( $self, $url ) = @_;
253 36 ▶ $self->{'url'} = $url if $url;
Branch: 1 branch
BranchTrueFalseTotal
if $url 2 34 36
254 36 return $self->{'url'};
255 }
256  
257 =head2 months
258  
259 $bot->months( $int );
260 my $int = $bot->months();
261  
262 The number of months to scrape if C<url> is a Date::Format specification.
263  
264 Defaults to 3.
265  
266 =cut
267  
268 39 ▶sub months {
Subroutine months: called CC=2 SCAR=6.9
Pod documented
269 39 my ( $self, $months ) = @_;
270 39 ▶ $self->{'months'} = $months if $months;
Branch: 1 branch
BranchTrueFalseTotal
if $months 2 37 39
271 39 return $self->{'months'};
272 }
273  
274 9 ▶sub parser {
Subroutine parser: called CC=2 SCAR=6.9
Pod undocumented
275 9 my ( $self, $parser ) = @_;
276 9 ▶ $self->{'parser'} = $parser if $parser;
Branch: 1 branch
BranchTrueFalseTotal
if $parser 3 6 9
277 9 return $self->{'parser'};
278 }
279  
280 =head2 user_dir
281  
282 my $dir = $bot->user_dir( $dir );
283  
284 The directory to which your events will be dumped.
285  
286 Normally this is set as a side-effect of setting the C<name> accessor,
287 however it can be optionally set to something else I<after> setting
288 C<name>.
289  
290 =cut
291  
292 7 ▶sub user_dir {
Subroutine user_dir: called CC=2 SCAR=6.9
Pod documented
293 7 my ( $self, $user_dir ) = @_;
294 7 ▶ $self->{'user_dir'} = $user_dir if $user_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $user_dir 3 4 7
295 7 return $self->{'user_dir'};
296 }
297  
298 =head2 user_page
299  
300 my $page = $bot->user_page( $page );
301  
302 The page on which information about your bot is to be found.
303  
304 Normally this is set as a side-effect of setting the C<name> accessor,
305 however it can be optionally set to something else I<after> setting
306 C<name>.
307  
308 =cut
309  
310 5 ▶sub user_page {
Subroutine user_page: called CC=2 SCAR=6.9
Pod documented
311 5 my ( $self, $user_page ) = @_;
312 5 ▶ $self->{'user_page'} = $user_page if $user_page;
Branch: 1 branch
BranchTrueFalseTotal
if $user_page 3 2 5
313 5 return $self->{'user_page'};
314 }
315  
316 =head2 shows_page
317  
318 my $page = $bot->shows_page( $page );
319  
320 The page to which events scraped by your bot will be uploaded.
321  
322 Normally this is set as a side-effect of setting the C<name> accessor,
323 however it can be optionally set to something else I<after> setting
324 C<name>.
325  
326 =cut
327  
328 6 ▶sub shows_page {
Subroutine shows_page: called CC=2 SCAR=6.9
Pod documented
329 6 my ( $self, $shows_page ) = @_;
330 6 ▶ $self->{'shows_page'} = $shows_page if $shows_page;
Branch: 1 branch
BranchTrueFalseTotal
if $shows_page 3 3 6
331 6 return $self->{'shows_page'};
332 }
333  
334 =head1 METHODS
335  
336 =cut
337  
338 =head2 add_event
339  
340 my $e = $bot->add_event();
341  
342 Create a new event and return it.
343  
344 This is a convenience method which both creates a new event, adds it to
345 C<events> list (see above) and returns a refernce to which you may
346 manipulate as necessary.
347  
348 =cut
349  
350 13 ▶sub add_event {
Subroutine add_event: called CC=1 SCAR=0.0
Pod documented
351 13 my $self = shift;
352 13 my $event = WWW::Wikevent::Event->new();
353 13 push @{$self->{'events'}}, $event;
354 13 return $event;
355 }
356  
357 =head2 parse
358  
359 my @events = $bot->parse( $html );
360  
361 or
362  
363 my $events_ref = $bot->parse( $html );
364  
365 Run the user supplised C<parser> subroutine against the argument HTML and
366 return any events found. This is used internally by C<scrape>.
367  
368 =cut
369  
370 4 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
371 4 my ( $self, $html ) = @_;
372 4 $self->parser->( $self, $html );
373 4 ▶ return wantarray ? @{$self->events()} : $self->events();
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
374 }
375  
376 =head2 check_allowed
377  
378 $bot->check_allowed();
379  
380 Check the user page of this bot to see if it is currently allowed to run.
381 This will be indicated by the text:
382  
383 run = true
384  
385 at the top of the page. If that text is present return true, other wise
386 die with an error. This method is called internally by C<upload> so you
387 don't have to call it, but you do have to make sure that the above text
388 appears on the bot's user page.
389  
390 =cut
391  
392 0 ▶sub check_allowed {
Subroutine check_allowed: not called CC=6 SCAR=37.4
Pod documented
393 0 my $self = shift();
394 0 $Mvs->do_login();
395 # check to see if run = true
396 0 $Mvs->do_update( $self->{'user_page'} );
397 0 open UP, $self->{'user_page'};
398 0 my $go = undef;
399 0 ▶ while ( <UP> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline UP)) 0 0 0
400 0 ▶ next if m{^\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/ 0 0 0
401 0 ▶ last if m{^\s*==[^=]*==\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*==[^=]*==\s*$/ 0 0 0
402 0 ▶ if ( m{^\s*run\s*=\s*(\w+)\s*$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*run\s*=\s*(\w+)\s*$/) 0 0 0
403 0 $go = $1;
404 }
405 }
406 0 ▶ die "Not allowed to run, according to user page."
Branch: 1 branch
BranchTrueFalseTotal
unless $go 0 0 0
407 unless $go;
408 0 close UP;
409 }
410  
411 0 ▶sub create_account {
Subroutine create_account: not called CC=1 SCAR=0.0
Pod undocumented
412 }
413  
414 =head2 scrape_sample
415  
416 $bot->scrape_sample();
417  
418 Runs the C<parser> against the supplied C<sample> HTML page.
419  
420 =cut
421  
422 1 ▶sub scrape_sample {
Subroutine scrape_sample: called CC=4 SCAR=15.5
Pod documented
423 1 my $self = shift;
424 1 my $file = $self->sample();
425 1 my $in;
426 1 ▶ if ( $self->charset() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->charset) { } 0 1 1
427 0 my $c = $self->charset();
428 0 ▶ open( $in, "<:encoding($c)", $file )
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<:encoding($c)", $file or die "Could not open sample file '${file}'. $!\n" 0 0 0
429 or die "Could not open sample file '$file'. $!\n";
430 } else {
431 1 ▶ open( $in, "<", $file )
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $file or die "Could not open sample file '${file}'. $!\n" 1 0 1
432 or die "Could not open sample file '$file'. $!\n";
433 }
434 1 local $/ = undef;
435 1 my $html = <$in>;
436 1 close $in;
437 1 $self->events( $self->parse( $html ) );
438 }
439  
440 2 ▶sub find_month_urls {
Subroutine find_month_urls: called CC=4 SCAR=13.9
Pod undocumented
441 2 my $self = shift;
442 2 my @calendar_urls;
443 # from perlfunc:
444 # my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
445 # thus: 0 1 2 3 4 5 6 7 8
446 2 my @lt = localtime(time);
447 2 ▶ for ( my $i = 0; $i < $self->months(); $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->months) 33 2 35
448 33 my $url = strftime( $self->url(), @lt );
449 33 $lt[4]++;
450 33 ▶ if ( $lt[4] > 11 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lt[4] > 11) 4 29 33
451 4 $lt[4] = 0;
452 4 $lt[5]++;
453 }
454 33 push @calendar_urls, $url;
455 }
456 2 ▶ return wantarray ? @calendar_urls : \@calendar_urls;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
457 }
458  
459 =head2 scrape
460  
461 $bot->scrape();
462  
463 Starts scraping at the supplied C<url> and continues as long as C<url>
464 changes.
465
466 =cut
467  
468 0 ▶sub scrape {
Subroutine scrape: not called CC=5 SCAR=34.0
Pod documented
469 0 my $self = shift;
470 0 ▶ if ( $self->url() =~ m{%[A-z]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->url =~ /%[A-z]/) { } 0 0 0
471 0 foreach my $url ( $self->find_month_urls() ) {
472 0 $self->scrape_page( $url );
473 }
474 } else {
475 0 ▶ while ( $self->url() and ( $self->url() ne $self->{last_url} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->url and $self->url ne $self->{"last_url"}) 0 0 0
Condition0%0/3
$self->url and $self->url ne $self->{"last_url"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->url and $self->url ne $self->{"last_url"}
$self->url $self->url ne $self->{"last_url"}
Truth table0%0/3
A and B
A= $self->urlB= $self->url ne $self->{"last_url"}
ABresult
0X0
100
111
476 0 $self->{last_url} = $self->url();
477 0 $self->scrape_page( $self->url() );
478 }
479 }
480 }
481  
482 =head2 scrape_page
483  
484 $bot->scrape_page( $url );
485  
486 Scrapes a single page of HTML found at the given URL. This method is
487 called internally by C<scrape>.
488  
489 =cut
490  
491 0 ▶sub scrape_page {
Subroutine scrape_page: not called CC=3 SCAR=24.8
Pod documented
492 0 my ( $self, $url ) = @_;
493 0 my $html;
494 0 print "fetching $url\n"; #FIXME
495 0 my $res = $Ua->get( $url );
496 0 ▶ die "couldn't fetch $url." unless $res->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
497 0 ▶ if ( $self->charset() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->charset) { } 0 0 0
498 0 $html = $res->decoded_content( charset => $self->charset() );
499 } else {
500 0 $html = $res->decoded_content();
501 }
502 0 $self->parse( $html );
503 }
504  
505 =head2 dump
506  
507 $bot->dump();
508  
509 Dumps the contents of C<events> as text to standard out.
510  
511 =cut
512  
513 1 ▶sub dump {
Subroutine dump: called CC=2 SCAR=6.9
Pod documented
514 1 my $self = shift;
515 1 foreach my $e ( $self->events() ) {
516 4 print $e;
517 }
518 1 return 1;
519 }
520  
521 =head2 remember
522
523 $bot->remember( $event );
524  
525 Records an md5sum of the given event, so as to not repeat it again when
526 running C<dump_to_file>.
527  
528 =cut
529  
530 5 ▶sub remember {
Subroutine remember: called CC=2 SCAR=7.0
Pod documented
531 5 my ( $self, $event ) = @_;
532 5 my $token = md5_hex( encode( "iso-8859-1", $event->to_string() ) );
533 5 $self->{known_events}->{$token} = 1;
534 5 ▶ open OUT, ">>$SEEN_FILE"
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">>$SEEN_FILE" or die "could not open file for seen events" 5 0 5
535 or die 'could not open file for seen events';
536 5 print OUT "$token\n";
537 5 close OUT;
538 }
539  
540 =head2 load_remembered_events
541  
542 $bot->load_remembered_events
543  
544 Loads in the md5sums of previously C<remember>ed events. This is called
545 internally by C<new> so it's unlikely that you will need to call it.
546  
547 =cut
548  
549 4 ▶sub load_remembered_events {
Subroutine load_remembered_events: called CC=5 SCAR=16.2
Pod documented
550 4 my ( $self, $event ) = @_;
551 4 ▶ unless ( open SEEN, $SEEN_FILE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open SEEN, $SEEN_FILE) 1 3 4
552 1 ▶ open SEEN, ">$SEEN_FILE"
Branch: 1 branch
BranchTrueFalseTotal
open SEEN, ">$SEEN_FILE" or die "could not open file for seen events" 1 0 1
553 or die 'could not open file for seen events';
554 1 print SEEN "\n";
555 1 close SEEN;
556 1 ▶ open SEEN, $SEEN_FILE
Branch: 1 branch
BranchTrueFalseTotal
open SEEN, $SEEN_FILE or die "could not open file for seen events" 1 0 1
557 or die 'could not open file for seen events';
558 }
559 4 ▶ while ( my $token = <SEEN> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = readline SEEN)) 9 4 13
560 9 chomp( $token );
561 9 $self->{known_events}->{$token} = 1;
562 }
563 4 close SEEN;
564 }
565  
566 =head2 is_new
567  
568 my $bool = $bot->is_new( $event );
569  
570 Checks to see if the md5sum of an event is in our list of C<remember>ed
571 events.
572  
573 =cut
574  
575 7 ▶sub is_new {
Subroutine is_new: called CC=2 SCAR=6.9
Pod documented
576 7 my ( $self, $event ) = @_;
577 7 my $token = md5_hex( encode( "iso-8859-1", $event->to_string() ) );
578 7 ▶ if ( $self->{known_events}->{$token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'known_events'}{$token}) { } 2 5 7
579 2 return 0;
580 } else {
581 5 return 1;
582 }
583 }
584  
585 =head2 dump_to_file
586
587 $bot->dump_to_file
588  
589 Prints out the events in their final form to the appropriate .wiki file for
590 upload to the bot's event page. This is called internally by C<upload> but
591 is also useful for the last stages of writing and debugging your bot.
592  
593 =cut
594  
595 1 ▶sub dump_to_file {
Subroutine dump_to_file: called CC=6 SCAR=18.6
Pod documented
596 1 my $self = shift;
597 1 ▶ if ( ! -e $self->user_dir() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->user_dir) 1 0 1
598 1 ▶ mkdir $self->user_dir()
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->user_dir or die 'could not make directory: ' . $self->user_dir . "\n" 1 0 1
599 or die "could not make directory: " . $self->user_dir() . "\n";
600 }
601 1 ▶ open my $out, ">:encoding(utf-8)", $self->shows_page()
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">:encoding(utf-8)", $self->shows_page or die 'could not open wiki file: ' . $self->shows_page . "\n" 1 0 1
602 or die "could not open wiki file: " . $self->shows_page() . "\n";
603 1 foreach my $e ( $self->events() ) {
604 4 ▶ if ( $self->is_new( $e ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_new($e)) 4 0 4
605 4 print $out $e;
606 4 $self->remember( $e );
607 }
608 }
609 1 close $out;
610 1 return 1;
611 }
612  
613 =head2 upload
614  
615 $bot->upload();
616  
617 This is the method which interacts with the Wikevent server, first checking
618 to see if the bot is allowed to proceed, then doing an update, printing out
619 the bot's C<events> and then proceeding to do the upload.
620  
621 =cut
622  
623 0 ▶sub upload {
Subroutine upload: not called CC=1 SCAR=6.9
Pod documented
624 0 my $self = shift;
625 0 $self->check_allowed();
626 0 $Mvs->do_update( $self->shows_page() );
627 0 $self->dump_to_file();
628 0 $Mvs->watch(0);
629 0 $Mvs->minor_edit(0);
630 0 $Mvs->commit_message( "scraping results" );
631 0 $Mvs->do_commit( $self->shows_page() );
632 }
633  
634 1 1;
635  
636 __END__
↑ Summary Event.pm »