Newer Older
88 lines | 1.708kb
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';
9

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

            
12
sub filter {
13
    my $self = shift;
14
    
15
    if (@_) {
16
        my $filter = ref $_[0] eq 'HASH' ? $_[0] : {@_};
17
        
18
        foreach my $column (keys %$filter) {
19
            my $fname = $filter->{$column};
20

            
21
            if  (exists $filter->{$column}
22
              && defined $fname
23
              && ref $fname ne 'CODE') 
24
            {
25
              croak qq{Filter "$fname" is not registered"}
26
                unless exists $self->filters->{$fname};
27
              
28
              $filter->{$column} = $self->filters->{$fname};
29
            }
30
        }
31
        
32
        $self->{filter} = {%{$self->filter}, %$filter};
33
        
34
        return $self;
35
    }
36
    
37
    return $self->{filter} ||= {};
38
}
cleanup
Yuki Kimoto authored on 2011-01-23
39

            
40
# DEPRECATED!
41
__PACKAGE__->attr('default_filter');
cleanup
yuki-kimoto authored on 2010-01-21
42

            
update document
yuki-kimoto authored on 2010-01-30
43
1;
44

            
packaging one directory
yuki-kimoto authored on 2009-11-16
45
=head1 NAME
46

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

            
49
=head1 SYNOPSIS
50
    
version 0.0901
yuki-kimoto authored on 2009-12-17
51
    my $query = DBIx::Custom::Query->new;
52
    
update document
yuki-kimoto authored on 2010-01-30
53
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
54

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
70
=head2 C<sql>
71

            
72
    my $sql = $query->sql;
73
    $query  = $query->sql('select * from books where author = ?;');
74

            
75
SQL statement.
76

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

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

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

            
update document
yuki-kimoto authored on 2010-01-30
84
=head1 METHODS
85

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

            
88
=cut