]>
iEval git - gruntmaster-data.git/blob - lib/Gruntmaster/Opener.pm
1 package Gruntmaster
::Opener
;
5 use parent qw
/Exporter/;
8 our @EXPORT = qw
/handle_line/;
9 our @EXPORT_OK = @EXPORT;
10 our $VERSION = '6000.001';
12 use Date
::Parse qw
/str2time/;
13 use Gruntmaster
::Data
;
15 sub _analyze_request
{
16 s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for @_; # From URI::Escape POD
17 my ($req, $parms) = @_;
18 return unless $parms =~ /contest=(\w+)/;
20 return $req =~ m
,/pb/(\w
+), ?
($1, $ct) : ();
24 my ($owner, $datetime, $request, $parms) = $_[0] =~
27 "\w+\s # request method
28 ([^" ?
]+) # URL (without query string)
30 ([^" ]+)\s # query string
31 [^"]+"\s # HTTP version
32 2 # response code starts with 2
34 my ($pb, $ct) = _analyze_request $request, $parms or return;
35 my $time = str2time $datetime;
36 open_problem $ct, $pb, $owner, $time;
46 Gruntmaster::Opener - Populate opens table from NCSA access logs
50 use Gruntmaster::Opener;
52 open my $fh, '<', '/var/log/apache2/access.log';
53 handle_line $_ while <$fh>;
57 Gruntmaster::Opener is the backend of the L<gruntmaster-opener> script
58 that reads NCSA-style access logs, finds lines that represent
59 successful requests to problems during contests, extracts data from
60 them and inserts it into the database.
64 The only function in this module. Exported by default. Takes a single
65 parameter, a line from a logfile in NCSA common/combined format.
67 If the request described in the given line:
73 Is successful (response code is 2xx)
77 Targets a problem (C</pb/something>)
81 Has a query parameter named C<contest>
85 Happened during the contest named in the C<contest> query parameter
86 (this restriction is enforced by the B<open_problem> function).
90 an entry is added to the C<opens> table, using the B<open_problem>
91 function from L<Gruntmaster::Data>.
99 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
101 =head1 COPYRIGHT AND LICENSE
103 Copyright (C) 2014-2016 by Marius Gavrilescu
105 This library is free software; you can redistribute it and/or modify
106 it under the same terms as Perl itself, either Perl version 5.20.1 or,
107 at your option, any later version of Perl 5 you may have available.
This page took 0.05264 seconds and 5 git commands to generate.