| 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
| |||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||