Newer Older
117 lines | 2.438kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::Query;
2

            
update document
yuki-kimoto authored on 2009-11-17
3
use strict;
4
use warnings;
5

            
update document
yuki-kimoto authored on 2010-01-30
6
use base 'Object::Simple';
7

            
cleanup
Yuki Kimoto authored on 2011-02-09
8
use Carp 'croak';
cleanup
Yuki Kimoto authored on 2011-04-25
9
use DBIx::Custom::Util '_subname';
cleanup
Yuki Kimoto authored on 2011-02-09
10

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
11
__PACKAGE__->attr(
12
    [qw/sth filters/],
13
    sql => '',
14
    tables => sub { [] },
15
    columns => sub { [] }
16
);
cleanup
Yuki Kimoto authored on 2011-02-09
17

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

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

            
67
# DEPRECATED!
68
__PACKAGE__->attr('default_filter');
cleanup
yuki-kimoto authored on 2010-01-21
69

            
update document
yuki-kimoto authored on 2010-01-30
70
1;
71

            
packaging one directory
yuki-kimoto authored on 2009-11-16
72
=head1 NAME
73

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

            
76
=head1 SYNOPSIS
77
    
version 0.0901
yuki-kimoto authored on 2009-12-17
78
    my $query = DBIx::Custom::Query->new;
79
    
update document
yuki-kimoto authored on 2010-01-30
80
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
81

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
99
=head2 C<sql>
100

            
101
    my $sql = $query->sql;
102
    $query  = $query->sql('select * from books where author = ?;');
103

            
104
SQL statement.
105

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

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

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

            
update document
yuki-kimoto authored on 2010-01-30
113
=head1 METHODS
114

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

            
117
=cut