Newer Older
35 lines | 0.588kb
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;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
11
    
cleanup
Yuki Kimoto authored on 2011-03-21
12
    my $hash = {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
13
    
cleanup
Yuki Kimoto authored on 2011-03-21
14
    for (my $i = 0; $i < @$array; $i += 2) {
15
        my $key = $array->[$i];
16
        my $f = $array->[$i + 1];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
17
        
cleanup
Yuki Kimoto authored on 2011-03-21
18
        if (ref $key eq 'ARRAY') {
19
            foreach my $k (@$key) {
20
                $hash->{$k} = $f;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
21
            }
22
        }
23
        else {
cleanup
Yuki Kimoto authored on 2011-03-21
24
            $hash->{$key} = $f;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
25
        }
26
    }
cleanup
Yuki Kimoto authored on 2011-03-21
27
    return $hash;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
28
}
29

            
30
1;
31

            
32
=head1 NAME
33

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