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