blib/lib/App/RecordStream/Operation/fromapache.pm

filter: Statementstmt 27.7% 15 / 54 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod n/a totaltotal 22.4% 20 / 89 CC 13 SCAR 43.1
CC
13
Cov
19%
init
132.0
accept_line
12.0
usage
2.0
CRAP 74.8
↑ Summary blib/lib/App/RecordStream/Operation/toptable.pm »
1 package App::RecordStream::Operation::fromapache;
2  
3 our $VERSION = "4.0.23";
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base qw(App::RecordStream::Operation);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use App::RecordStream::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use App::RecordStream::OptionalRequire qw(Apache::Log::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 App::RecordStream::OptionalRequire::require_done();
13  
14 sub init {
15 0 ▶ my $this = shift;
Subroutine init: not called CC=11 SCAR=48.8
16 0 my $args = shift;
17  
18 0 my $fast;
19 my $strict;
20 0 my $verbose;
21 0 my $woothee;
22  
23 0 my $spec = {
24 "fast:s" => \$fast,
25 "strict:s" => \$strict,
26 "verbose" => \$verbose,
27 "woothee" => \$woothee,
28 };
29  
30 0 $this->parse_options($args, $spec);
31  
32 0 my %opts;
33  
34 0 ▶ if (defined $fast) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fast) 0 0 0
35 0 ▶ if ($fast eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fast eq '') { } 0 0 0
36 0 $opts{fast} = 1;
37 }
38 else {
39 0 $opts{fast} = eval $fast;
40 0 ▶ die "eval of option fast failed. $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
41 }
42 }
43  
44 0 ▶ if (defined $strict) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $strict) 0 0 0
45 0 ▶ if ($strict eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict eq '') { } 0 0 0
46 0 $opts{strict} = 1;
47 }
48 else {
49 0 $opts{strict} = eval $strict;
50 0 ▶ die "eval of option strict failed. $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
51 }
52 }
53
54 # default is --fast
55 0 ▶ unless ($opts{fast} or $opts{strict}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"fast"} or $opts{"strict"}) 0 0 0
Condition0%0/3
$opts{"fast"} or $opts{"strict"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"fast"} or $opts{"strict"}
$opts{"fast"} $opts{"strict"}
Truth table0%0/3
A or B
A= $opts{"fast"}B= $opts{"strict"}
ABresult
1X1
011
000
56 0 $opts{fast} = 1;
57 }
58  
59 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
60 0 $opts{verbose} = 1;
61 }
62  
63 0 ▶ if ($woothee) {
Branch: 1 branch
BranchTrueFalseTotal
if ($woothee) 0 0 0
64 0 App::RecordStream::OptionalRequire::optional_use("Woothee");
65 0 App::RecordStream::OptionalRequire::require_done();
66 0 $this->{'WOOTHEE'} = 1;
67 }
68  
69 0 $this->{'PARSER'} = Apache::Log::Parser->new(%opts);
70 }
71  
72 sub accept_line {
73 0 ▶ my $this = shift;
Subroutine accept_line: not called CC=3 SCAR=24.8
74 0 my $line = shift;
75  
76 0 my $parser = $this->{'PARSER'};
77  
78 0 ▶ if (my $hash = $parser->parse($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hash = $parser->parse($line)) 0 0 0
79 0 my $record = App::RecordStream::Record->new($hash);
80 0 ▶ $record->{woothee} = Woothee->parse($record->{agent}) if $this->{'WOOTHEE'};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"WOOTHEE"} 0 0 0
81 0 $this->push_record($record);
82 }
83  
84 0 return 1;
85 }
86  
87 sub usage {
88 0 ▶ my $this = shift;
Subroutine usage: not called CC=1 SCAR=6.9
89  
90 0 my $options = [
91 [ 'fast', q{'fast' parser works relatively fast. It can process only 'common', 'combined' and custom styles with compatibility with 'common', and cannot work with backslash-quoted double-quotes in fields. (This is the default)} ],
92 [ 'strict', q{'strict' parser works relatively slow. It can process any style format logs, with specification about separator, and checker for perfection. It can also process backslash-quoted double-quotes properly.} ],
93 [ 'verbose', q{Verbose output.} ],
94 [ 'woothee', q{Each agent field of records is parse by Woothee to produce woothee field.} ],
95 ];
96  
97 0 my $args_string = $this->options_string($options);
98  
99 0 return <<USAGE;
100 Usage: recs-fromapache <args>
101 __FORMAT_TEXT__
102 Each line of input (or lines of <files>) is parse by Apache::Log::Parser to produce an output record.
103 __FORMAT_TEXT__
104  
105 Arguments:
106 $args_string
107  
108 Examples:
109 Get records from typical apache log
110 recs-fromapache < /var/log/httpd-access.log
111 A more detailed how to use (See perldoc Apache::Log::Parser)
112 recs-fromapache --strict '[qw(combined common vhost_common)]' < /var/log/httpd-access.log
113 Get records except access of crawler
114 recs-fromapache --woothee < /var/log/httpd-access.log | recs-grep '\$r->{woothee}{category} ne "crawler"'
115 USAGE
116 }
117  
118 1;
↑ Summary blib/lib/App/RecordStream/Operation/toptable.pm »