packaging one directory
|
1 |
package DBIx::Custom::Query; |
updatedd pod
|
2 |
use Object::Simple -base; |
update document
|
3 | |
cleanup
|
4 |
use Carp 'croak'; |
cleanup
|
5 |
use DBIx::Custom::Util '_subname'; |
cleanup
|
6 | |
updatedd pod
|
7 |
has [qw/sth filters/], |
- update_param_tag is DEPREC...
|
8 |
sql => '', |
9 |
tables => sub { [] }, |
|
updatedd pod
|
10 |
columns => sub { [] }; |
cleanup
|
11 | |
12 |
sub filter { |
|
13 |
my $self = shift; |
|
14 |
|
|
15 |
if (@_) { |
|
all filter can receive array...
|
16 |
my $filter = {}; |
17 |
|
|
18 |
if (ref $_[0] eq 'HASH') { |
|
19 |
$filter = $_[0]; |
|
20 |
} |
|
21 |
else { |
|
22 |
my $ef = @_ > 1 ? [@_] : $_[0]; |
|
23 |
|
|
24 |
for (my $i = 0; $i < @$ef; $i += 2) { |
|
25 |
my $column = $ef->[$i]; |
|
26 |
my $f = $ef->[$i + 1]; |
|
27 |
|
|
28 |
if (ref $column eq 'ARRAY') { |
|
29 |
foreach my $c (@$column) { |
|
30 |
$filter->{$c} = $f; |
|
31 |
} |
|
32 |
} |
|
33 |
else { |
|
34 |
$filter->{$column} = $f; |
|
35 |
} |
|
36 |
} |
|
37 |
} |
|
cleanup
|
38 |
|
39 |
foreach my $column (keys %$filter) { |
|
40 |
my $fname = $filter->{$column}; |
|
41 | ||
42 |
if (exists $filter->{$column} |
|
43 |
&& defined $fname |
|
44 |
&& ref $fname ne 'CODE') |
|
45 |
{ |
|
cleanup
|
46 |
croak qq{Filter "$fname" is not registered" } . _subname |
cleanup
|
47 |
unless exists $self->filters->{$fname}; |
48 |
|
|
49 |
$filter->{$column} = $self->filters->{$fname}; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
$self->{filter} = {%{$self->filter}, %$filter}; |
|
54 |
|
|
55 |
return $self; |
|
56 |
} |
|
57 |
|
|
58 |
return $self->{filter} ||= {}; |
|
59 |
} |
|
cleanup
|
60 | |
61 |
# DEPRECATED! |
|
cleanup
|
62 |
has 'default_filter'; |
cleanup
|
63 | |
update document
|
64 |
1; |
65 | ||
packaging one directory
|
66 |
=head1 NAME |
67 | ||
removed DESTROY method(not b...
|
68 |
DBIx::Custom::Query - Query |
packaging one directory
|
69 | |
70 |
=head1 SYNOPSIS |
|
71 |
|
|
version 0.0901
|
72 |
my $query = DBIx::Custom::Query->new; |
73 |
|
|
update document
|
74 |
=head1 ATTRIBUTES |
packaging one directory
|
75 | |
removed DESTROY method(not b...
|
76 |
=head2 C<columns> |
removed reconnect method
|
77 | |
cleanup
|
78 |
my $columns = $query->columns; |
cleanup
|
79 |
$query = $query->columns(['auhtor', 'title']); |
removed reconnect method
|
80 | |
removed DESTROY method(not b...
|
81 |
Column names. |
packaging one directory
|
82 | |
removed DESTROY method(not b...
|
83 |
=head2 C<filter> |
update document
|
84 | |
cleanup
|
85 |
my $filter = $query->filter; |
cleanup
|
86 |
$query = $query->filter(author => 'to_something', |
87 |
title => 'to_something'); |
|
packaging one directory
|
88 | |
all filter can receive array...
|
89 |
$query = $query->filter([qw/author title/] => 'to_something'); |
90 | ||
cleanup
|
91 |
Filters when parameter binding is executed. |
packaging one directory
|
92 | |
cleanup
|
93 |
=head2 C<sql> |
94 | ||
95 |
my $sql = $query->sql; |
|
96 |
$query = $query->sql('select * from books where author = ?;'); |
|
97 | ||
98 |
SQL statement. |
|
99 | ||
removed DESTROY method(not b...
|
100 |
=head2 C<sth> |
update document
|
101 | |
cleanup
|
102 |
my $sth = $query->sth; |
103 |
$query = $query->sth($sth); |
|
packaging one directory
|
104 | |
cleanup
|
105 |
Statement handle of L<DBI> |
removed DESTROY method(not b...
|
106 | |
update document
|
107 |
=head1 METHODS |
108 | ||
cleanup
|
109 |
L<DBIx::Custom::Query> inherits all methods from L<Object::Simple>. |
catch up with Object::Simple...
|
110 | |
111 |
=cut |