| 1 | package OptionHash; | ||||||||||||||||||||
| 2 | # ABSTRACT: Checking of option hashes | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | ▶ | use 5.0.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | ▶ | use base qw< Exporter >; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | our @EXPORT = (qw< ohash_check ohash_define >); | |||||||||||||||||||
| 11 | 3 | our $VERSION = '0.2.0'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | my $ohash_def = bless {keys => {'keys' => 1}}, __PACKAGE__; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub ohash_define{ | ||||||||||||||||||||
| 17 | 2 | ▶ | my %x = @_; | ||||||||||||||||||
|
Subroutine
ohash_define: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 18 | 2 | ohash_check($ohash_def, \%x); | |||||||||||||||||||
| 19 | 2 | my %def = ( keys => { map{ $_ => 1} @{$x{keys}}} ); | |||||||||||||||||||
| 20 | 2 | return bless \%def, __PACKAGE__; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | sub ohash_check($%){ | ||||||||||||||||||||
| 25 | 5 | ▶ | my($oh, $h) = @_; | ||||||||||||||||||
|
Subroutine
ohash_check: called CC=7 SCAR=20.9
Pod
documented
| |||||||||||||||||||||
| 26 | 5 | ▶ | ref $oh eq 'OptionHash' or croak 'Not an OptionHash (you passed '.(ref $oh || 'a plain value').') - expecting ohash_check( $ohash_def, $hashref) '; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $oh || 'a plain value'
MC/DC0%0/1
ref $oh || 'a plain value'
ref $oh
Truth table0%0/2
A
A= ref $oh
| |||||||||||||||||||||
| 27 | 5 | ▶ | ref $h eq 'HASH' or croak 'Not a hashref - expecting ohash_check( $ohash_def, $hashref) '; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 5 | ▶ | my $keys = $oh->{keys} or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 5 | for( keys(%{$h}) ){ | |||||||||||||||||||
| 30 | 9 | ▶ | if( ! exists $keys->{$_} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 1 | croak "Invalid key $_ in OptionHash"; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 3 | ;1 | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | __END__ | ||||||||||||||||||||