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

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
3
use Object::Simple -base;
update document
yuki-kimoto authored on 2010-01-30
4

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

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