| 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
Condition33%1/3
defined $opts->{'s'} || defined $opts->{'f'}
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'}
| |||||||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||||||
| 38 | 0 | die('-s and -f can not be used together'); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | if ( defined( $opts->{'s'} ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||