lib/Log/Munger/RulesUsable.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 32 / 32 CC 6 SCAR 14.7
CC
6
Cov
100%
usable
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.3
« lib/Log/Munger/App/Command/munge.pm ↑ Summary lib/Log/Munger/WhichRuleFile.pm »
1 package Log::Munger::RulesUsable;
2  
3 28 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Log::Munger::RulesUsable - Checks that a rules hash is fit to run.
10  
11 =head1 VERSION
12  
13 Version 0.0.1
14  
15 =cut
16  
17 28 our $VERSION = '0.0.1';
18  
19 =head1 SYNOPSIS
20  
21 use Log::Munger::RulesUsable;
22  
23 eval { Log::Munger::RulesUsable->usable( 'rules' => $rules_hash ); };
24 if ($@) {
25 die( 'unusable rules... ' . $@ );
26 }
27  
28 =head1 METHODS
29  
30 =head2 usable
31  
32 Checks that a rules hash is structurally sound enough to run against.
33  
34 This says nothing about whether the rules do what they were meant to do. It only
35 confirms that the hash is a hash, that it has a C<rules> key, and that the key
36 holds an array with something in it. Anything past that, such as whether the
37 patterns compile or whether the tests pass, is L<Log::Munger::RulesTest>'s job.
38  
39 The split exists because the two are used at different times. Something starting
40 up wants a cheap look at a file it is about to load, not the full test suite.
41  
42 - rules :: The rules hash ref to check. Required.
43 Default :: undef
44  
45 Returns 1 if the hash is usable. Otherwise dies with a message naming the specific
46 thing that was wrong, so the caller has something worth printing.
47  
48 Log::Munger::RulesUsable->usable( 'rules' => $rules_hash );
49  
50 =cut
51  
52 129 ▶sub usable {
Subroutine usable: called CC=6 SCAR=17.9
Pod documented
53 129 my ( $blank, %opts ) = @_;
54  
55 129 ▶ if ( !defined( $opts{'rules'} ) ) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $opts{'rules'}) { } 1 128 129
elsif (ref $opts{'rules'} ne 'HASH') { } 1 127 128
elsif (not defined $opts{'rules'}{'rules'}) { } 1 126 127
elsif (ref $opts{'rules'}{'rules'} ne 'ARRAY') { } 1 125 126
elsif (not defined $opts{'rules'}{'rules'}[0]) { } 1 124 125
56 1 die('$opts{rules} is undef');
57 } elsif ( ref( $opts{'rules'} ) ne 'HASH' ) {
58 1 die( '$opts{rules} has a ref of "' . ref( $opts{'rules'} ) . '" and not "HASH"' );
59 } elsif ( !defined( $opts{'rules'}{'rules'} ) ) {
60 1 die('$opts{rules}{rules} is undef meaning the rules hash contains no rules');
61 } elsif ( ref( $opts{'rules'}{'rules'} ) ne 'ARRAY' ) {
62 1 die( '$opts{rules}{rules} has a ref of "' . ref( $opts{'rules'}{'rules'} ) . '" and not "ARRAY"' );
63 } elsif ( !defined( $opts{'rules'}{'rules'}[0] ) ) {
64 1 die('$opts{rules}{rules}[0] is undef meaning the rules hash contains no rules');
65 }
66  
67 124 return 1;
68 } ## end sub usable
« lib/Log/Munger/App/Command/munge.pm ↑ Summary lib/Log/Munger/WhichRuleFile.pm »