File Coverage

blib/lib/DBIx/Class/Sims/Util.pm
Criterion Covered Total %
statement 21 21 100.0
branch 13 14 92.8
condition 2 2 100.0
subroutine 5 5 100.0
pod 0 2 0.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             # vim: set sw=2 ft=perl:
2             package DBIx::Class::Sims::Util;
3              
4 1     1   77690 use 5.010_001;
  1         10  
5              
6 1     1   4 use strictures 2;
  1         7  
  1         35  
7              
8 1     1   186 use Scalar::Util ();
  1         2  
  1         242  
9              
10             sub reftype {
11 29   100 29 0 174 return Scalar::Util::reftype($_[0]) // '';
12             }
13              
14             sub normalize_aoh {
15 13     13 0 7161 shift;
16 13         27 my ($input) = @_;
17              
18 13 100       42 return unless defined $input;
19              
20             # If it's an arrayref, verify all elements are hashrefs
21 11 100       36 if (reftype($input) eq 'ARRAY') {
    100          
    50          
22 4 100       19 return $input unless @$input;
23 3 100       10 return $input unless grep { reftype($_) ne 'HASH' } @$input;
  5         11  
24             }
25             elsif (reftype($input) eq 'HASH') {
26 1         6 return [$input];
27             }
28             elsif (!reftype($input)) {
29 6 100       56 if ($input =~ /^\d+$/) {
30 4         13 return [ map { {} } 1 .. $input ];
  9         40  
31             }
32             }
33              
34 3         12 return;
35             }
36              
37             1;
38             __END__