Newer Older
112 lines | 2.383kb
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

            
add table tag
Yuki Kimoto authored on 2011-02-09
11
__PACKAGE__->attr([qw/columns sql sth filters tables/]);
cleanup
Yuki Kimoto authored on 2011-02-09
12

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

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

            
62
# DEPRECATED!
63
__PACKAGE__->attr('default_filter');
cleanup
yuki-kimoto authored on 2010-01-21
64

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

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

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

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

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

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

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

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

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

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

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

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

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

            
99
SQL statement.
100

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

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

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

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

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

            
112
=cut