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'; |
9 | ||
add table tag
|
10 |
__PACKAGE__->attr([qw/columns sql sth filters tables/]); |
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 |
{ |
|
46 |
croak qq{Filter "$fname" is not registered"} |
|
improved error messages
|
47 |
. qq{ (DBIx::Custom::Query::filter) } |
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 |