blib/lib/OptionHash.pm

filter: Statementstmt 100% 32 / 32 Branchbran 62.5% 5 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 88.4% 46 / 52 SCAR 19.6
CC
7
Cov
88%
ohash_check
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 7.1
↑ Summary
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
BranchTrueFalseTotal
ref $oh eq "OptionHash" or croak('Not an OptionHash (you passed ' . (ref $oh || "a plain value") . ') - expecting ohash_check( $ohash_def, $hashref) ') 0 5 5
Condition0%0/2
ref $oh || 'a plain value'
l!l
00
MC/DC0%0/1
ref $oh || 'a plain value'
ref $oh
Truth table0%0/2
A
A= ref $oh
Aresult
11
00
27 5 ▶ ref $h eq 'HASH' or croak 'Not a hashref - expecting ohash_check( $ohash_def, $hashref) ';
Branch: 1 branch
BranchTrueFalseTotal
ref $h eq "HASH" or croak("Not a hashref - expecting ohash_check( \$ohash_def, \$hashref) ") 0 5 5
28 5 ▶ my $keys = $oh->{keys} or die;
Branch: 1 branch
BranchTrueFalseTotal
my $keys = $oh->{"keys"} or die 0 5 5
29 5 for( keys(%{$h}) ){
30 9 ▶ if( ! exists $keys->{$_} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $keys->{$_}) 1 8 9
31 1 croak "Invalid key $_ in OptionHash";
32 }
33 }
34 }
35  
36  
37 3 ;1
38  
39 __END__
↑ Summary