line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OptionHash; |
2
|
|
|
|
|
|
|
# ABSTRACT: Checking of option hashes |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
1490
|
use 5.0.4; |
|
4
|
|
|
|
|
32
|
|
6
|
4
|
|
|
4
|
|
17
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
64
|
|
7
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
94
|
|
8
|
4
|
|
|
4
|
|
18
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
357
|
|
9
|
4
|
|
|
4
|
|
21
|
use base qw< Exporter >; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
1387
|
|
10
|
|
|
|
|
|
|
our @EXPORT = (qw< ohash_check ohash_define >); |
11
|
|
|
|
|
|
|
our $VERSION = '0.2.2'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $ohash_def = bless {keys => {'keys' => 1}}, __PACKAGE__; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub ohash_define{ |
17
|
4
|
|
|
4
|
1
|
592
|
my %x = @_; |
18
|
4
|
|
|
|
|
15
|
ohash_check($ohash_def, \%x); |
19
|
4
|
|
|
|
|
9
|
my %def = ( keys => { map{ $_ => 1} @{$x{keys}}} ); |
|
11
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
10
|
|
20
|
4
|
|
|
|
|
16
|
return bless \%def, __PACKAGE__; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub ohash_check($%){ |
25
|
13
|
|
|
13
|
1
|
1430
|
my($oh, $h) = @_; |
26
|
13
|
100
|
50
|
|
|
107
|
ref $oh eq 'OptionHash' or croak 'Not an OptionHash (you passed '.(ref $oh || 'a plain value').') - expecting ohash_check( $ohash_def, $hashref) '; |
27
|
12
|
100
|
|
|
|
94
|
ref $h eq 'HASH' or croak 'Not a hashref - expecting ohash_check( $ohash_def, $hashref) '; |
28
|
11
|
50
|
|
|
|
31
|
my $keys = $oh->{keys} or die; |
29
|
11
|
|
|
|
|
16
|
for( keys(%{$h}) ){ |
|
11
|
|
|
|
|
27
|
|
30
|
13
|
100
|
|
|
|
28
|
if( ! exists $keys->{$_} ){ |
31
|
3
|
|
|
|
|
380
|
croak "Invalid key $_ in OptionHash"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
;1 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |