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