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   57176 use 5.010_001;
  1         2  
5              
6 1     1   4 use strictures 2;
  1         4  
  1         28  
7              
8 1     1   145 use Scalar::Util ();
  1         1  
  1         171  
9              
10             sub reftype {
11 29   100 29 0 125 return Scalar::Util::reftype($_[0]) // '';
12             }
13              
14             sub normalize_aoh {
15 13     13 0 4503 shift;
16 13         14 my ($input) = @_;
17              
18 13 100       32 return unless defined $input;
19              
20             # If it's an arrayref, verify all elements are hashrefs
21 11 100       16 if (reftype($input) eq 'ARRAY') {
    100          
    50          
22 4 100       11 return $input unless @$input;
23 3 100       7 return $input unless grep { reftype($_) ne 'HASH' } @$input;
  5         5  
24             }
25             elsif (reftype($input) eq 'HASH') {
26 1         5 return [$input];
27             }
28             elsif (!reftype($input)) {
29 6 100       37 if ($input =~ /^\d+$/) {
30 4         7 return [ map { {} } 1 .. $input ];
  9         26  
31             }
32             }
33              
34 3         9 return;
35             }
36              
37             1;
38             __END__