Newer Older
111 lines | 2.373kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::Query;
updatedd pod
Yuki Kimoto authored on 2011-06-12
2
use Object::Simple -base;
update document
yuki-kimoto authored on 2010-01-30
3

            
cleanup
Yuki Kimoto authored on 2011-02-09
4
use Carp 'croak';
cleanup
Yuki Kimoto authored on 2011-04-25
5
use DBIx::Custom::Util '_subname';
cleanup
Yuki Kimoto authored on 2011-02-09
6

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
7
has [qw/sth filters/],
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
8
    sql => '',
9
    tables => sub { [] },
updatedd pod
Yuki Kimoto authored on 2011-06-12
10
    columns => sub { [] };
cleanup
Yuki Kimoto authored on 2011-02-09
11

            
12
sub filter {
13
    my $self = shift;
14
    
15
    if (@_) {
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
16
        my $filter = {};
17
        
18
        if (ref $_[0] eq 'HASH') {
19
            $filter = $_[0];
20
        }
21
        else {
22
            my $ef = @_ > 1 ? [@_] : $_[0];
23
            
24
            for (my $i = 0; $i < @$ef; $i += 2) {
25
                my $column = $ef->[$i];
26
                my $f = $ef->[$i + 1];
27
                
28
                if (ref $column eq 'ARRAY') {
29
                    foreach my $c (@$column) {
30
                        $filter->{$c} = $f;
31
                    }
32
                }
33
                else {
34
                    $filter->{$column} = $f;
35
                }
36
            }
37
        }
cleanup
Yuki Kimoto authored on 2011-02-09
38
        
39
        foreach my $column (keys %$filter) {
40
            my $fname = $filter->{$column};
41

            
42
            if  (exists $filter->{$column}
43
              && defined $fname
44
              && ref $fname ne 'CODE') 
45
            {
cleanup
Yuki Kimoto authored on 2011-04-25
46
              croak qq{Filter "$fname" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-02-09
47
                unless exists $self->filters->{$fname};
48
              
49
              $filter->{$column} = $self->filters->{$fname};
50
            }
51
        }
52
        
53
        $self->{filter} = {%{$self->filter}, %$filter};
54
        
55
        return $self;
56
    }
57
    
58
    return $self->{filter} ||= {};
59
}
cleanup
Yuki Kimoto authored on 2011-01-23
60

            
61
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
62
has 'default_filter';
cleanup
yuki-kimoto authored on 2010-01-21
63

            
update document
yuki-kimoto authored on 2010-01-30
64
1;
65

            
packaging one directory
yuki-kimoto authored on 2009-11-16
66
=head1 NAME
67

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
68
DBIx::Custom::Query - Query
packaging one directory
yuki-kimoto authored on 2009-11-16
69

            
70
=head1 SYNOPSIS
71
    
version 0.0901
yuki-kimoto authored on 2009-12-17
72
    my $query = DBIx::Custom::Query->new;
73
    
update document
yuki-kimoto authored on 2010-01-30
74
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
75

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
76
=head2 C<columns>
removed reconnect method
yuki-kimoto authored on 2010-05-28
77

            
cleanup
yuki-kimoto authored on 2010-08-03
78
    my $columns = $query->columns;
cleanup
yuki-kimoto authored on 2010-08-05
79
    $query      = $query->columns(['auhtor', 'title']);
removed reconnect method
yuki-kimoto authored on 2010-05-28
80

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
81
Column names.
packaging one directory
yuki-kimoto authored on 2009-11-16
82

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
83
=head2 C<filter>
update document
yuki-kimoto authored on 2009-11-19
84

            
cleanup
yuki-kimoto authored on 2010-08-03
85
    my $filter = $query->filter;
cleanup
Yuki Kimoto authored on 2011-02-09
86
    $query     = $query->filter(author => 'to_something',
87
                                 title  => 'to_something');
packaging one directory
yuki-kimoto authored on 2009-11-16
88

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
89
    $query     = $query->filter([qw/author title/] => 'to_something');
90

            
cleanup
yuki-kimoto authored on 2010-08-05
91
Filters when parameter binding is executed.
packaging one directory
yuki-kimoto authored on 2009-11-16
92

            
cleanup
yuki-kimoto authored on 2010-10-17
93
=head2 C<sql>
94

            
95
    my $sql = $query->sql;
96
    $query  = $query->sql('select * from books where author = ?;');
97

            
98
SQL statement.
99

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
100
=head2 C<sth>
update document
yuki-kimoto authored on 2009-11-19
101

            
cleanup
yuki-kimoto authored on 2010-08-03
102
    my $sth = $query->sth;
103
    $query  = $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
104

            
cleanup
yuki-kimoto authored on 2010-08-05
105
Statement handle of L<DBI>
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
106

            
update document
yuki-kimoto authored on 2010-01-30
107
=head1 METHODS
108

            
cleanup
yuki-kimoto authored on 2010-08-05
109
L<DBIx::Custom::Query> inherits all methods from L<Object::Simple>.
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-22
110

            
111
=cut