Newer Older
35 lines | 0.664kb
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1
package DBIx::Custom::Util;
2

            
3
use strict;
4
use warnings;
5

            
6
sub array_filter_to_hash {
7
    my $array_filter = shift;
8
    
9
    return unless $array_filter;
10
    return $array_filter if ref $array_filter eq 'HASH';
11
    
12
    my $filter = {};
13
    
14
    for (my $i = 0; $i < @$array_filter; $i += 2) {
15
        my $column = $array_filter->[$i];
16
        my $f = $array_filter->[$i + 1];
17
        
18
        if (ref $column eq 'ARRAY') {
19
            foreach my $c (@$column) {
20
                $filter->{$c} = $f;
21
            }
22
        }
23
        else {
24
            $filter->{$column} = $f;
25
        }
26
    }
27
    return $filter;
28
}
29

            
30
1;
31

            
32
=head1 NAME
33

            
34
DBIx::Custom::Util - Utility class
35