lib/Log/Munger/App/Command/degrok.pm

filter: Statementstmt 61.2% 19 / 31 Branchbran 21.4% 3 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 7 / 9 Podpod 80.0% 4 / 5 totaltotal 50.7% 35 / 69 CC 10 SCAR 33.4
CC
10
Cov
47%
execute
49.8
abstract
2.0
description
2.0
CRAP 28.2
« lib/Log/Munger/LogProcessor.pm ↑ Summary lib/Log/Munger/App/Command/enrich.pm »
1 package Log::Munger::App::Command::degrok;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use Log::Munger::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Log::Munger::Degrok;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
9 return (
10 1 [ 's=s', 'A string to convert.' ],
11 [ 'f=s', 'A file to convert.' ],
12 [ 'r', 'With -f, emit a rules file skeleton instead of the rewritten file.' ],
13 [ 'i=s@', 'Rule file to treat as an include, for -r (repeatable).' ],
14 [ 'o=s', 'Overwrite policy for names already in an include: yes|no_silent|no_warn|no_die.' ],
15 );
16 }
17  
18 0 ▶sub abstract { "Rewrite grok templating into the Log::Munger form" }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
19  
20 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
21 0 'Grok references a named pattern as "%{TEMPLATE}" and captures one as "%{TEMPLATE:VAR}".
22 Log::Munger writes those as "[% TEMPLATE %]" and "(?<VAR>[% TEMPLATE %])" respectively. This
23 rewrites the first form into the second.
24  
25 Give it either -s for a string or -f for a file, not both. Adding -r to -f produces a rules
26 file skeleton rather than the rewritten file, which is what the grok2rules command does.
27 ';
28 }
29  
30 1 ▶sub validate { return 1 }
Subroutine validate: called CC=1 SCAR=0.0
Pod undocumented
31  
32 1 ▶sub execute {
Subroutine execute: called CC=10 SCAR=39.1
Pod documented
33 1 my ( $self, $opts, $args ) = @_;
34  
35 1 ▶ if ( !defined( $opts->{'s'} ) && !defined( $opts->{'f'} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $opts->{'s'} || defined $opts->{'f'}) { } 0 1 1
elsif (defined $opts->{'s'} and defined $opts->{'f'}) { } 0 1 1
Condition33%1/3
defined $opts->{'s'} || defined $opts->{'f'}
l!l&&r!l&&!r
100
MC/DC0%0/2
defined $opts->{'s'} || defined $opts->{'f'}
defined $opts->{'s'} defined $opts->{'f'}
Truth table33%1/3
A || B
A= defined $opts->{'s'}B= defined $opts->{'f'}
ABresult
1X1
011
000
36 0 die('Either -s or -f need specified');
37 ▶ } elsif ( defined( $opts->{'s'} ) && defined( $opts->{'f'} ) ) {
Condition33%1/3
defined $opts->{"s"} and defined $opts->{"f"}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $opts->{"s"} and defined $opts->{"f"}
defined $opts->{"s"} defined $opts->{"f"}
Truth table33%1/3
A and B
A= defined $opts->{"s"}B= defined $opts->{"f"}
ABresult
0X0
100
111
38 0 die('-s and -f can not be used together');
39 }
40  
41 1 ▶ if ( defined( $opts->{'s'} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts->{'s'}) { } 1 0 1
elsif (defined $opts->{'f'}) { } 0 0 0
42 1 print Log::Munger::Degrok->string( 'string' => $opts->{'s'} ) . "\n";
43 } elsif ( defined( $opts->{'f'} ) ) {
44 0 ▶ if ( !-f $opts->{'f'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $opts->{'f'}) { } 0 0 0
elsif (not -r $opts->{'f'}) { } 0 0 0
45 0 die( '"' . $opts->{'f'} . '" is not a file' );
46 } elsif ( !-r $opts->{'f'} ) {
47 0 die( '"' . $opts->{'f'} . '" is not readable' );
48 }
49  
50 0 my $results;
51 0 ▶ if ( $opts->{'r'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'r'}) { } 0 0 0
52 $results = Log::Munger::Degrok->grok2rules(
53 'file' => $opts->{'f'},
54 'includes' => $opts->{'i'},
55 0 'overwrite' => $opts->{'o'}
56 ) . "\n";
57 } else {
58 0 $results = Log::Munger::Degrok->file( 'file' => $opts->{'f'} ) . "\n";
59 }
60 0 print $results;
61 } ## end elsif ( defined( $opts->{'f'} ) )
62 } ## end sub execute
63  
64 16 1;
« lib/Log/Munger/LogProcessor.pm ↑ Summary lib/Log/Munger/App/Command/enrich.pm »