Newer Older
101 lines | 2.468kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::Query;
2
use Object::Simple;
3

            
4
sub sql             : Attr {}
5
sub key_infos       : Attr {}
6
sub bind_filter     : Attr {}
7
sub fetch_filter     : Attr {}
8
sub sth             : Attr {}
9

            
10
sub no_bind_filters      : Attr { type => 'array', trigger => sub {
11
    my $self = shift;
12
    my $no_bind_filters = $self->no_bind_filters || [];
13
    my %no_bind_filters_map = map {$_ => 1} @{$no_bind_filters};
14
    $self->_no_bind_filters_map(\%no_bind_filters_map);
15
}}
16
sub _no_bind_filters_map : Attr {default => sub { {} }}
17

            
18
sub no_fetch_filters     : Attr { type => 'array', default => sub { [] } }
19

            
20
Object::Simple->build_class;
21

            
22
=head1 NAME
23

            
24
DBIx::Custom::Query - Query object for DBIx::Custom
25

            
26
=head1 VERSION
27

            
28
Version 0.0101
29

            
30
=head1 SYNOPSIS
31

            
32
    # Create query
33
    my $dbi = DBIx::Custom->new;
34
    my $query = $dbi->create_query($template);
35
    
36
    # Set query attributes
37
    $query->bind_filter($dbi->filters->{default_bind_filter});
38
    $query->no_bind_filters('title', 'author');
39
    
40
    $query->fetch_filter($dbi->filters->{default_fetch_filter});
41
    $query->no_fetch_filters('title', 'author');
42
    
43
    # Execute query
44
    $dbi->execute($query, $params);
45

            
46
=head1 OBJECT ACCESSORS
47

            
48
=head2 sth
49

            
50
    # Set and get statement handle
51
    $self = $query->sth($sql);
52
    $sth  = $query->sth;
53

            
54
=head2 sql
55

            
56
    # Set and get SQL
57
    $self = $query->sql($sql);
58
    $sql  = $query->sql;
59

            
60
=head2 bind_filter
61

            
62
    # Set and get bind filter
63
    $self        = $query->bind_filter($bind_filter);
64
    $bind_filter = $query->bind_filter;
65

            
66
=head2 no_bind_filters
67

            
68
    # Set and get keys of no filtering
69
    $self            = $query->no_bind_filters($no_filters);
70
    $no_bind_filters = $query->no_bind_filters;
71

            
72
=head2 fetch_filter
73

            
74
    # Set and get fetch filter
75
    $self        = $query->fetch_filter($fetch_filter);
76
    $fetch_filter = $query->fetch_filter;
77

            
78
=head2 no_fetch_filters
79

            
80
    # Set and get keys of no filtering
81
    $self            = $query->no_fetch_filters($no_filters);
82
    $no_fetch_filters = $query->no_fetch_filters;
83

            
84
=head2 key_infos
85

            
86
    # Set and get key informations
87
    $self      = $query->key_infos($key_infos);
88
    $key_infos = $query->key_infos;
89

            
90
=head1 AUTHOR
91

            
92
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
93

            
94
Github L<http://github.com/yuki-kimoto>
95

            
96
=head1 COPYRIGHT & LICENSE
97

            
98
Copyright 2009 Yuki Kimoto, all rights reserved.
99

            
100
This program is free software; you can redistribute it and/or modify it
101
under the same terms as Perl itself.