packaging one directory
|
1 |
package DBIx::Custom::Query; |
2 | ||
update document
|
3 |
use strict; |
4 |
use warnings; |
|
5 | ||
update document
|
6 |
use base 'Object::Simple'; |
7 | ||
cleanup
|
8 |
use Carp 'croak'; |
cleanup
|
9 |
use DBIx::Custom::Util '_subname'; |
cleanup
|
10 | |
- update_param_tag is DEPREC...
|
11 |
__PACKAGE__->attr( |
12 |
[qw/sth filters/], |
|
13 |
sql => '', |
|
14 |
tables => sub { [] }, |
|
15 |
columns => sub { [] } |
|
16 |
); |
|
cleanup
|
17 | |
18 |
sub filter { |
|
19 |
my $self = shift; |
|
20 |
|
|
21 |
if (@_) { |
|
all filter can receive array...
|
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
|
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
|
52 |
croak qq{Filter "$fname" is not registered" } . _subname |
cleanup
|
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
|
66 | |
67 |
# DEPRECATED! |
|
68 |
__PACKAGE__->attr('default_filter'); |
|
cleanup
|
69 | |
update document
|
70 |
1; |
71 | ||
packaging one directory
|
72 |
=head1 NAME |
73 | ||
removed DESTROY method(not b...
|
74 |
DBIx::Custom::Query - Query |
packaging one directory
|
75 | |
76 |
=head1 SYNOPSIS |
|
77 |
|
|
version 0.0901
|
78 |
my $query = DBIx::Custom::Query->new; |
79 |
|
|
update document
|
80 |
=head1 ATTRIBUTES |
packaging one directory
|
81 | |
removed DESTROY method(not b...
|
82 |
=head2 C<columns> |
removed reconnect method
|
83 | |
cleanup
|
84 |
my $columns = $query->columns; |
cleanup
|
85 |
$query = $query->columns(['auhtor', 'title']); |
removed reconnect method
|
86 | |
removed DESTROY method(not b...
|
87 |
Column names. |
packaging one directory
|
88 | |
removed DESTROY method(not b...
|
89 |
=head2 C<filter> |
update document
|
90 | |
cleanup
|
91 |
my $filter = $query->filter; |
cleanup
|
92 |
$query = $query->filter(author => 'to_something', |
93 |
title => 'to_something'); |
|
packaging one directory
|
94 | |
all filter can receive array...
|
95 |
$query = $query->filter([qw/author title/] => 'to_something'); |
96 | ||
cleanup
|
97 |
Filters when parameter binding is executed. |
packaging one directory
|
98 | |
cleanup
|
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...
|
106 |
=head2 C<sth> |
update document
|
107 | |
cleanup
|
108 |
my $sth = $query->sth; |
109 |
$query = $query->sth($sth); |
|
packaging one directory
|
110 | |
cleanup
|
111 |
Statement handle of L<DBI> |
removed DESTROY method(not b...
|
112 | |
update document
|
113 |
=head1 METHODS |
114 | ||
cleanup
|
115 |
L<DBIx::Custom::Query> inherits all methods from L<Object::Simple>. |
catch up with Object::Simple...
|
116 | |
117 |
=cut |