Newer Older
36 lines | 0.631kb
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

            
cleanup
Yuki Kimoto authored on 2011-03-21
6
sub array_to_hash {
7
    my $array = shift;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
8
    
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
9
    return $array if ref $array eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-03-21
10
    return unless $array;
11
    return $array if ref $array eq 'HASH';
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
12
    
cleanup
Yuki Kimoto authored on 2011-03-21
13
    my $hash = {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
14
    
cleanup
Yuki Kimoto authored on 2011-03-21
15
    for (my $i = 0; $i < @$array; $i += 2) {
16
        my $key = $array->[$i];
17
        my $f = $array->[$i + 1];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
18
        
cleanup
Yuki Kimoto authored on 2011-03-21
19
        if (ref $key eq 'ARRAY') {
20
            foreach my $k (@$key) {
21
                $hash->{$k} = $f;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
22
            }
23
        }
24
        else {
cleanup
Yuki Kimoto authored on 2011-03-21
25
            $hash->{$key} = $f;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
26
        }
27
    }
cleanup
Yuki Kimoto authored on 2011-03-21
28
    return $hash;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
29
}
30

            
31
1;
32

            
33
=head1 NAME
34

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