File Coverage

blib/lib/DBR/Misc/General.pm
Criterion Covered Total %
statement 14 15 93.3
branch 5 8 62.5
condition n/a
subroutine 4 4 100.0
pod n/a
total 23 27 85.1


line stmt bran cond sub pod time code
1             package DBR::Misc::General;
2 18     18   107 use strict;
  18         40  
  18         849  
3 18     18   113 use base 'Exporter';
  18         41  
  18         2142  
4             our @EXPORT = qw(_expandstr _expandstrs);
5 18     18   113 use Scalar::Util 'blessed';
  18         39  
  18         6562  
6              
7             # Non-oo stuff goes here
8              
9              
10             # _expandstr... I'm probably going to hell for this
11             # The point here is to stringify things as fast as possible, as it affects
12             # how quickly I can identify whether two where clauses are the same, or different
13              
14             my ($v,$r);
15             sub _expandstr{
16 1470030     1470030   2179855 $v = shift;
17 1470030         2241011 $r = ref($v);
18 580000         995819 return $r?
19             # yes its a ref
20             blessed($v) ?
21             $v->stringify # it's blessed
22             :
23             # not blessed
24 230000         464894 $r eq 'ARRAY'? '['. join("\0|",map { _expandstr($_) } @{$v} ) . ']' : # Arrayref
  0            
25 1470030 0       6774781 $r eq 'HASH' ? '{'. join("\0|",map { $_ => _expandstr( $_->{$_} ) } sort keys %$v) . '}' : # Hashref
    50          
    100          
    100          
26             $v # Unknown type of ref, let it go
27             : $v # not a ref, just use the value
28             }
29              
30             1;