| 1 | package Log::Munger::App::Command::dump_rule_file; | ||||||||||||||||||||||||||||
| 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::RuleFileParser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use YAML::XS qw(Dump); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | return ( | ||||||||||||||||||||||||||||
| 11 | 1 | [ 'f=s', 'Rule file to read.' ], | |||||||||||||||||||||||||||
| 12 | [ 'var|v=s', 'Dump only the resolved value of this one var (a compiled regexp), not the whole file.' ], | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub abstract { "Dump a rule file as loaded, with includes merged and vars resolved" } | ||||||||||||||||||||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | "Loads a rule file the way the engine does, merging its includes and resolving its templated | |||||||||||||||||||||||||||
| 20 | vars, then dumps the result as YAML. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | With --var it prints only that one var's resolved value, which is how to see the regexp a | ||||||||||||||||||||||||||||
| 23 | primitive actually compiles to. | ||||||||||||||||||||||||||||
| 24 | "; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub validate { return 1 } | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=5 SCAR=19.4
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 1 | my ( $self, $opts, $args ) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | if ( !defined( $opts->{'f'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | die('No rules file specified via -f'); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | my $parser = Log::Munger::RuleFileParser->new; | |||||||||||||||||||||||||||
| 37 | 1 | my $rules = $parser->load( 'file' => $opts->{'f'} ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if ( defined( $opts->{'var'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | if ( ref( $rules->{'vars'} ) ne 'HASH' || !exists( $rules->{'vars'}{ $opts->{'var'} } ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $rules->{"vars"} ne "HASH" or not exists $rules->{"vars"}{$opts->{"var"}}
MC/DC0%0/2
ref $rules->{"vars"} ne "HASH" or not exists $rules->{"vars"}{$opts->{"var"}}
ref $rules->{"vars"} ne "HASH"
not exists $rules->{"vars"}{$opts->{"var"}}
Truth table33%1/3
A or not(B)
A= ref $rules->{"vars"} ne "HASH"B= not exists $rules->{"vars"}{$opts->{"var"}}
| |||||||||||||||||||||||||||||
| 41 | 0 | die( 'no such var "' . $opts->{'var'} . '" in "' . $opts->{'f'} . '"' ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 1 | print $rules->{'vars'}{ $opts->{'var'} } . "\n"; | |||||||||||||||||||||||||||
| 44 | 1 | return; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | print Dump($rules); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||
| 50 | } ## end sub execute | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 16 | 1; | |||||||||||||||||||||||||||