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