cleanup
|
1 |
package DBIx::Custom; |
2 | ||
DBIx::Custom is now stable
|
3 |
our $VERSION = '0.1617'; |
fixed DBIx::Custom::QueryBui...
|
4 | |
5 |
use 5.008001; |
|
cleanup
|
6 |
use strict; |
7 |
use warnings; |
|
8 | ||
remove run_transaction().
|
9 |
use base 'Object::Simple'; |
many change
|
10 | |
packaging one directory
|
11 |
use Carp 'croak'; |
12 |
use DBI; |
|
13 |
use DBIx::Custom::Result; |
|
cleanup
|
14 |
use DBIx::Custom::Query; |
cleanup
|
15 |
use DBIx::Custom::QueryBuilder; |
update document
|
16 |
use Encode qw/encode_utf8 decode_utf8/; |
packaging one directory
|
17 | |
catch up with Object::Simple...
|
18 |
__PACKAGE__->attr('dbh'); |
cleanup
|
19 |
__PACKAGE__->attr([qw/user password data_source/]); |
renamed default_query_filter...
|
20 |
__PACKAGE__->attr([qw/default_bind_filter default_fetch_filter/]); |
packaging one directory
|
21 | |
removed register_format()
|
22 |
__PACKAGE__->dual_attr('filters', default => sub { {} }, |
23 |
inherit => 'hash_copy'); |
|
24 |
__PACKAGE__->register_filter( |
|
update document
|
25 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
26 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
removed register_format()
|
27 |
); |
packaging one directory
|
28 | |
cleanup
|
29 |
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result'); |
renamed update tag to update...
|
30 |
__PACKAGE__->attr(query_builder => sub {DBIx::Custom::QueryBuilder->new}); |
added cache_method attribute
|
31 | |
add cache attribute
|
32 |
__PACKAGE__->attr(cache => 1); |
added cache_method attribute
|
33 |
__PACKAGE__->attr(cache_method => sub { |
34 |
sub { |
|
35 |
my $self = shift; |
|
36 |
|
|
37 |
$self->{_cached} ||= {}; |
|
38 |
|
|
39 |
if (@_ > 1) { |
|
40 |
$self->{_cached}{$_[0]} = $_[1] |
|
41 |
} |
|
42 |
else { |
|
43 |
return $self->{_cached}{$_[0]} |
|
44 |
} |
|
45 |
} |
|
46 |
}); |
|
removed register_format()
|
47 | |
added check_filter attribute
|
48 |
__PACKAGE__->attr(filter_check => 1); |
49 | ||
packaging one directory
|
50 |
sub connect { |
removed register_format()
|
51 |
my $proto = shift; |
52 |
|
|
53 |
# Create |
|
54 |
my $self = ref $proto ? $proto : $proto->new(@_); |
|
update document
|
55 |
|
56 |
# Information |
|
packaging one directory
|
57 |
my $data_source = $self->data_source; |
58 |
my $user = $self->user; |
|
59 |
my $password = $self->password; |
|
60 |
|
|
removed experimental registe...
|
61 |
|
update document
|
62 |
# Connect |
select, insert, update, upda...
|
63 |
my $dbh = eval {DBI->connect( |
packaging one directory
|
64 |
$data_source, |
65 |
$user, |
|
66 |
$password, |
|
67 |
{ |
|
68 |
RaiseError => 1, |
|
69 |
PrintError => 0, |
|
70 |
AutoCommit => 1, |
|
71 |
} |
|
72 |
)}; |
|
73 |
|
|
update document
|
74 |
# Connect error |
packaging one directory
|
75 |
croak $@ if $@; |
76 |
|
|
update document
|
77 |
# Database handle |
packaging one directory
|
78 |
$self->dbh($dbh); |
update document
|
79 |
|
packaging one directory
|
80 |
return $self; |
81 |
} |
|
82 | ||
removed DESTROY method(not b...
|
83 |
sub register_filter { |
84 |
my $invocant = shift; |
|
update document
|
85 |
|
changed argument of tag proc...
|
86 |
# Register filter |
removed DESTROY method(not b...
|
87 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
88 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
update document
|
89 |
|
removed DESTROY method(not b...
|
90 |
return $invocant; |
packaging one directory
|
91 |
} |
92 | ||
removed register_format()
|
93 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append filter/; |
cleanup insert
|
94 | |
packaging one directory
|
95 |
sub insert { |
select, insert, update, upda...
|
96 |
my ($self, %args) = @_; |
removed register_format()
|
97 | |
cleanup insert
|
98 |
# Check arguments |
select, insert, update, upda...
|
99 |
foreach my $name (keys %args) { |
add tests
|
100 |
croak qq{"$name" is invalid argument} |
cleanup insert
|
101 |
unless $VALID_INSERT_ARGS{$name}; |
102 |
} |
|
103 |
|
|
removed register_format()
|
104 |
# Arguments |
select, insert, update, upda...
|
105 |
my $table = $args{table} || ''; |
106 |
my $param = $args{param} || {}; |
|
107 |
my $append = $args{append} || ''; |
|
108 |
my $filter = $args{filter}; |
|
packaging one directory
|
109 |
|
110 |
# Insert keys |
|
removed register_format()
|
111 |
my @insert_keys = keys %$param; |
packaging one directory
|
112 |
|
113 |
# Templte for insert |
|
renamed update tag to update...
|
114 |
my $source = "insert into $table {insert_param " |
update document
|
115 |
. join(' ', @insert_keys) . '}'; |
renamed default_query_filter...
|
116 |
$source .= " $append" if $append; |
packaging one directory
|
117 |
|
118 |
# Execute query |
|
renamed default_query_filter...
|
119 |
my $ret_val = $self->execute($source, param => $param, |
removed experimental registe...
|
120 |
filter => $filter); |
packaging one directory
|
121 |
|
122 |
return $ret_val; |
|
123 |
} |
|
124 | ||
cleanup update and update_al...
|
125 |
our %VALID_UPDATE_ARGS |
removed register_format()
|
126 |
= map { $_ => 1 } qw/table param where append filter allow_update_all/; |
cleanup update and update_al...
|
127 | |
packaging one directory
|
128 |
sub update { |
select, insert, update, upda...
|
129 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
130 |
|
131 |
# Check arguments |
|
select, insert, update, upda...
|
132 |
foreach my $name (keys %args) { |
add tests
|
133 |
croak qq{"$name" is invalid argument} |
cleanup update and update_al...
|
134 |
unless $VALID_UPDATE_ARGS{$name}; |
135 |
} |
|
136 |
|
|
137 |
# Arguments |
|
select, insert, update, upda...
|
138 |
my $table = $args{table} || ''; |
139 |
my $param = $args{param} || {}; |
|
140 |
my $where = $args{where} || {}; |
|
add tests
|
141 |
my $append = $args{append} || ''; |
select, insert, update, upda...
|
142 |
my $filter = $args{filter}; |
143 |
my $allow_update_all = $args{allow_update_all}; |
|
packaging one directory
|
144 |
|
145 |
# Update keys |
|
removed register_format()
|
146 |
my @update_keys = keys %$param; |
packaging one directory
|
147 |
|
148 |
# Where keys |
|
removed register_format()
|
149 |
my @where_keys = keys %$where; |
packaging one directory
|
150 |
|
151 |
# Not exists where keys |
|
add tests
|
152 |
croak qq{"where" argument must be specified and } . |
153 |
qq{contains the pairs of column name and value} |
|
cleanup update and update_al...
|
154 |
if !@where_keys && !$allow_update_all; |
packaging one directory
|
155 |
|
156 |
# Update clause |
|
renamed update tag to update...
|
157 |
my $update_clause = '{update_param ' . join(' ', @update_keys) . '}'; |
packaging one directory
|
158 |
|
159 |
# Where clause |
|
160 |
my $where_clause = ''; |
|
simplify filtering system
|
161 |
my $new_where = {}; |
many change
|
162 |
|
packaging one directory
|
163 |
if (@where_keys) { |
164 |
$where_clause = 'where '; |
|
add tests
|
165 |
$where_clause .= "{= $_} and " for @where_keys; |
packaging one directory
|
166 |
$where_clause =~ s/ and $//; |
167 |
} |
|
168 |
|
|
add tests
|
169 |
# Source of SQL |
renamed default_query_filter...
|
170 |
my $source = "update $table $update_clause $where_clause"; |
add tests
|
171 |
$source .= " $append" if $append; |
packaging one directory
|
172 |
|
changed argument of tag proc...
|
173 |
# Rearrange parameters |
removed register_format()
|
174 |
foreach my $wkey (@where_keys) { |
simplify filtering system
|
175 |
|
removed register_format()
|
176 |
if (exists $param->{$wkey}) { |
177 |
$param->{$wkey} = [$param->{$wkey}] |
|
178 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
simplify filtering system
|
179 |
|
removed register_format()
|
180 |
push @{$param->{$wkey}}, $where->{$wkey}; |
simplify filtering system
|
181 |
} |
add tests
|
182 |
else { |
removed register_format()
|
183 |
$param->{$wkey} = $where->{$wkey}; |
add tests
|
184 |
} |
simplify filtering system
|
185 |
} |
packaging one directory
|
186 |
|
187 |
# Execute query |
|
renamed default_query_filter...
|
188 |
my $ret_val = $self->execute($source, param => $param, |
add tests
|
189 |
filter => $filter); |
packaging one directory
|
190 |
|
191 |
return $ret_val; |
|
192 |
} |
|
193 | ||
select, insert, update, upda...
|
194 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
packaging one directory
|
195 | |
refactoring delete and delet...
|
196 |
our %VALID_DELETE_ARGS |
removed register_format()
|
197 |
= map { $_ => 1 } qw/table where append filter allow_delete_all/; |
refactoring delete and delet...
|
198 | |
packaging one directory
|
199 |
sub delete { |
select, insert, update, upda...
|
200 |
my ($self, %args) = @_; |
refactoring delete and delet...
|
201 |
|
202 |
# Check arguments |
|
select, insert, update, upda...
|
203 |
foreach my $name (keys %args) { |
add tests
|
204 |
croak qq{"$name" is invalid argument} |
refactoring delete and delet...
|
205 |
unless $VALID_DELETE_ARGS{$name}; |
206 |
} |
|
207 |
|
|
208 |
# Arguments |
|
select, insert, update, upda...
|
209 |
my $table = $args{table} || ''; |
210 |
my $where = $args{where} || {}; |
|
add tests
|
211 |
my $append = $args{append}; |
select, insert, update, upda...
|
212 |
my $filter = $args{filter}; |
213 |
my $allow_delete_all = $args{allow_delete_all}; |
|
packaging one directory
|
214 |
|
215 |
# Where keys |
|
removed register_format()
|
216 |
my @where_keys = keys %$where; |
packaging one directory
|
217 |
|
218 |
# Not exists where keys |
|
add tests
|
219 |
croak qq{"where" argument must be specified and } . |
220 |
qq{contains the pairs of column name and value} |
|
refactoring delete and delet...
|
221 |
if !@where_keys && !$allow_delete_all; |
packaging one directory
|
222 |
|
223 |
# Where clause |
|
224 |
my $where_clause = ''; |
|
225 |
if (@where_keys) { |
|
226 |
$where_clause = 'where '; |
|
add tests
|
227 |
$where_clause .= "{= $_} and " for @where_keys; |
packaging one directory
|
228 |
$where_clause =~ s/ and $//; |
229 |
} |
|
230 |
|
|
add tests
|
231 |
# Source of SQL |
renamed default_query_filter...
|
232 |
my $source = "delete from $table $where_clause"; |
add tests
|
233 |
$source .= " $append" if $append; |
packaging one directory
|
234 |
|
235 |
# Execute query |
|
renamed default_query_filter...
|
236 |
my $ret_val = $self->execute($source, param => $where, |
add tests
|
237 |
filter => $filter); |
packaging one directory
|
238 |
|
239 |
return $ret_val; |
|
240 |
} |
|
241 | ||
select, insert, update, upda...
|
242 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
243 | |
refactoring select
|
244 |
our %VALID_SELECT_ARGS |
added commit method
|
245 |
= map { $_ => 1 } qw/table column where append relation filter param/; |
refactoring select
|
246 | |
packaging one directory
|
247 |
sub select { |
select, insert, update, upda...
|
248 |
my ($self, %args) = @_; |
packaging one directory
|
249 |
|
refactoring select
|
250 |
# Check arguments |
select, insert, update, upda...
|
251 |
foreach my $name (keys %args) { |
add tests
|
252 |
croak qq{"$name" is invalid argument} |
refactoring select
|
253 |
unless $VALID_SELECT_ARGS{$name}; |
254 |
} |
|
packaging one directory
|
255 |
|
refactoring select
|
256 |
# Arguments |
select, insert, update, upda...
|
257 |
my $tables = $args{table} || []; |
removed register_format()
|
258 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
select, insert, update, upda...
|
259 |
my $columns = $args{column} || []; |
update document
|
260 |
my $where = $args{where}; |
select, insert, update, upda...
|
261 |
my $relation = $args{relation}; |
262 |
my $append = $args{append}; |
|
263 |
my $filter = $args{filter}; |
|
packaging one directory
|
264 |
|
add tests
|
265 |
# Source of SQL |
renamed default_query_filter...
|
266 |
my $source = 'select '; |
packaging one directory
|
267 |
|
added commit method
|
268 |
# Column clause |
packaging one directory
|
269 |
if (@$columns) { |
270 |
foreach my $column (@$columns) { |
|
renamed default_query_filter...
|
271 |
$source .= "$column, "; |
packaging one directory
|
272 |
} |
renamed default_query_filter...
|
273 |
$source =~ s/, $/ /; |
packaging one directory
|
274 |
} |
275 |
else { |
|
renamed default_query_filter...
|
276 |
$source .= '* '; |
packaging one directory
|
277 |
} |
278 |
|
|
added commit method
|
279 |
# Table |
renamed default_query_filter...
|
280 |
$source .= 'from '; |
packaging one directory
|
281 |
foreach my $table (@$tables) { |
renamed default_query_filter...
|
282 |
$source .= "$table, "; |
packaging one directory
|
283 |
} |
renamed default_query_filter...
|
284 |
$source =~ s/, $/ /; |
packaging one directory
|
285 |
|
added commit method
|
286 |
# Where clause |
update document
|
287 |
my $param; |
288 |
if (ref $where eq 'HASH') { |
|
289 |
$param = $where; |
|
290 |
$source .= 'where ('; |
|
291 |
foreach my $where_key (keys %$where) { |
|
renamed default_query_filter...
|
292 |
$source .= "{= $where_key} and "; |
packaging one directory
|
293 |
} |
update document
|
294 |
$source =~ s/ and $//; |
295 |
$source .= ') '; |
|
296 |
} |
|
297 |
elsif (ref $where eq 'ARRAY') { |
|
298 |
my$where_str = $where->[0] || ''; |
|
299 |
$param = $where->[1]; |
|
300 |
|
|
301 |
$source .= "where ($where_str) "; |
|
packaging one directory
|
302 |
} |
303 |
|
|
added commit method
|
304 |
# Relation |
305 |
if ($relation) { |
|
update document
|
306 |
$source .= $where ? "and " : "where "; |
added commit method
|
307 |
foreach my $rkey (keys %$relation) { |
renamed default_query_filter...
|
308 |
$source .= "$rkey = " . $relation->{$rkey} . " and "; |
packaging one directory
|
309 |
} |
310 |
} |
|
renamed default_query_filter...
|
311 |
$source =~ s/ and $//; |
added commit method
|
312 |
|
313 |
# Append some statement |
|
renamed default_query_filter...
|
314 |
$source .= " $append" if $append; |
packaging one directory
|
315 |
|
316 |
# Execute query |
|
update document
|
317 |
my $result = $self->execute($source, param => $param, |
318 |
filter => $filter); |
|
packaging one directory
|
319 |
|
320 |
return $result; |
|
321 |
} |
|
322 | ||
renamed build_query to creat...
|
323 |
sub create_query { |
renamed default_query_filter...
|
324 |
my ($self, $source) = @_; |
removed register_format()
|
325 |
|
renamed default_query_filter...
|
326 |
# Cache |
added cache_method attribute
|
327 |
my $cache = $self->cache; |
version 0.0901
|
328 |
|
removed reconnect method
|
329 |
# Create query |
330 |
my $query; |
|
added cache_method attribute
|
331 |
if ($cache) { |
332 |
|
|
renamed default_query_filter...
|
333 |
# Get query |
334 |
my $q = $self->cache_method->($self, $source); |
|
added cache_method attribute
|
335 |
|
336 |
# Create query |
|
337 |
$query = DBIx::Custom::Query->new($q) if $q; |
|
removed reconnect method
|
338 |
} |
added cache_method attribute
|
339 |
|
340 |
unless ($query) { |
|
renamed default_query_filter...
|
341 | |
342 |
# Create SQL object |
|
renamed update tag to update...
|
343 |
my $builder = $self->query_builder; |
added cache_method attribute
|
344 |
|
345 |
# Create query |
|
fixed Carp trast relationshi...
|
346 |
$query = $builder->build_query($source); |
347 | ||
added cache_method attribute
|
348 |
# Cache query |
renamed default_query_filter...
|
349 |
$self->cache_method->($self, $source, |
added cache_method attribute
|
350 |
{sql => $query->sql, |
351 |
columns => $query->columns}) |
|
352 |
if $cache; |
|
removed reconnect method
|
353 |
} |
version 0.0901
|
354 |
|
removed reconnect method
|
355 |
# Prepare statement handle |
add tests
|
356 |
my $sth; |
357 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
removed experimental registe...
|
358 |
$self->_croak($@, qq{. SQL: "$query->{sql}"}) if $@; |
renamed fetch_rows to fetch_...
|
359 |
|
removed reconnect method
|
360 |
# Set statement handle |
361 |
$query->sth($sth); |
|
362 |
|
|
363 |
return $query; |
|
364 |
} |
|
365 | ||
removed experimental registe...
|
366 |
sub _croak { |
367 |
my ($self, $error, $append) = @_; |
|
368 |
$append ||= ""; |
|
369 |
|
|
370 |
# Verbose |
|
371 |
if ($Carp::Verbose) { croak $error } |
|
372 |
|
|
373 |
# Not verbose |
|
374 |
else { |
|
375 |
|
|
376 |
# Remove line and module infromation |
|
377 |
my $at_pos = rindex($error, ' at '); |
|
378 |
$error = substr($error, 0, $at_pos); |
|
379 |
$error =~ s/\s+$//; |
|
380 |
|
|
381 |
croak "$error$append"; |
|
382 |
} |
|
383 |
} |
|
384 | ||
removed reconnect method
|
385 |
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter/; |
386 | ||
387 |
sub execute{ |
|
select, insert, update, upda...
|
388 |
my ($self, $query, %args) = @_; |
removed reconnect method
|
389 |
|
390 |
# Check arguments |
|
select, insert, update, upda...
|
391 |
foreach my $name (keys %args) { |
add tests
|
392 |
croak qq{"$name" is invalid argument} |
removed reconnect method
|
393 |
unless $VALID_EXECUTE_ARGS{$name}; |
394 |
} |
|
395 |
|
|
select, insert, update, upda...
|
396 |
my $params = $args{param} || {}; |
removed reconnect method
|
397 |
|
add tests
|
398 |
# First argument is the soruce of SQL |
renamed build_query to creat...
|
399 |
$query = $self->create_query($query) |
changed argument of tag proc...
|
400 |
unless ref $query; |
removed reconnect method
|
401 |
|
select, insert, update, upda...
|
402 |
my $filter = $args{filter} || $query->filter || {}; |
removed reconnect method
|
403 |
|
404 |
# Create bind value |
|
405 |
my $bind_values = $self->_build_bind_values($query, $params, $filter); |
|
406 |
|
|
407 |
# Execute |
|
408 |
my $sth = $query->sth; |
|
add tests
|
409 |
my $affected; |
410 |
eval {$affected = $sth->execute(@$bind_values)}; |
|
removed experimental registe...
|
411 |
$self->_croak($@) if $@; |
removed reconnect method
|
412 |
|
413 |
# Return resultset if select statement is executed |
|
414 |
if ($sth->{NUM_OF_FIELDS}) { |
|
415 |
|
|
416 |
# Create result |
|
renamed default_query_filter...
|
417 |
my $result = $self->result_class->new( |
418 |
sth => $sth, |
|
419 |
default_filter => $self->default_fetch_filter, |
|
added check_filter attribute
|
420 |
filters => $self->filters, |
421 |
filter_check => $self->filter_check |
|
renamed default_query_filter...
|
422 |
); |
423 | ||
removed reconnect method
|
424 |
return $result; |
425 |
} |
|
426 |
return $affected; |
|
427 |
} |
|
428 | ||
429 |
sub _build_bind_values { |
|
430 |
my ($self, $query, $params, $filter) = @_; |
|
431 |
|
|
432 |
# binding values |
|
433 |
my @bind_values; |
|
add tests
|
434 | |
435 |
# Filter |
|
436 |
$filter ||= {}; |
|
437 |
|
|
438 |
# Parameter |
|
439 |
$params ||= {}; |
|
440 |
|
|
441 |
# Check filter |
|
442 |
$self->_check_filter($self->filters, $filter, |
|
443 |
$self->default_bind_filter, $params) |
|
444 |
if $self->filter_check; |
|
removed reconnect method
|
445 |
|
446 |
# Build bind values |
|
447 |
my $count = {}; |
|
448 |
foreach my $column (@{$query->columns}) { |
|
449 |
|
|
450 |
# Value |
|
451 |
my $value = ref $params->{$column} eq 'ARRAY' |
|
452 |
? $params->{$column}->[$count->{$column} || 0] |
|
453 |
: $params->{$column}; |
|
454 |
|
|
add tests
|
455 |
# Filtering |
renamed default_query_filter...
|
456 |
my $fname = $filter->{$column} || $self->default_bind_filter || ''; |
add tests
|
457 |
my $filter_func = $fname ? $self->filters->{$fname} : undef; |
removed reconnect method
|
458 |
push @bind_values, $filter_func |
459 |
? $filter_func->($value) |
|
460 |
: $value; |
|
461 |
|
|
462 |
# Count up |
|
463 |
$count->{$column}++; |
|
464 |
} |
|
465 |
|
|
466 |
return \@bind_values; |
|
467 |
} |
|
468 | ||
add tests
|
469 |
sub _check_filter { |
470 |
my ($self, $filters, $filter, $default_filter, $params) = @_; |
|
471 |
|
|
472 |
# Filter name not exists |
|
473 |
foreach my $fname (values %$filter) { |
|
474 |
croak qq{Bind filter "$fname" is not registered} |
|
475 |
unless exists $filters->{$fname}; |
|
476 |
} |
|
477 |
|
|
478 |
# Default filter name not exists |
|
479 |
croak qq{Default bind filter "$default_filter" is not registered} |
|
480 |
if $default_filter && ! exists $filters->{$default_filter}; |
|
481 |
|
|
482 |
# Column name not exists |
|
483 |
foreach my $column (keys %$filter) { |
|
484 |
|
|
485 |
croak qq{Column name "$column" in bind filter is not found in paramters} |
|
486 |
unless exists $params->{$column}; |
|
487 |
} |
|
488 |
} |
|
489 | ||
fixed DBIx::Custom::QueryBui...
|
490 |
1; |
491 | ||
removed reconnect method
|
492 |
=head1 NAME |
493 | ||
renamed build_query to creat...
|
494 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
removed reconnect method
|
495 | |
496 |
=head1 SYNOPSYS |
|
cleanup
|
497 | |
renamed build_query to creat...
|
498 |
Connect to the database. |
499 |
|
|
500 |
use DBIx::Custom; |
|
renamed update tag to update...
|
501 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
removed reconnect method
|
502 |
user => 'ken', password => '!LFKD%$&'); |
cleanup
|
503 | |
renamed build_query to creat...
|
504 |
Insert, update, and delete |
cleanup
|
505 | |
removed reconnect method
|
506 |
# Insert |
507 |
$dbi->insert(table => 'books', |
|
renamed update tag to update...
|
508 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
509 |
filter => {title => 'encode_utf8'}); |
510 |
|
|
511 |
# Update |
|
512 |
$dbi->update(table => 'books', |
|
renamed update tag to update...
|
513 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
514 |
where => {id => 5}, |
515 |
filter => {title => 'encode_utf8'}); |
|
516 |
|
|
517 |
# Update all |
|
518 |
$dbi->update_all(table => 'books', |
|
renamed update tag to update...
|
519 |
param => {title => 'Perl'}, |
removed reconnect method
|
520 |
filter => {title => 'encode_utf8'}); |
521 |
|
|
522 |
# Delete |
|
523 |
$dbi->delete(table => 'books', |
|
524 |
where => {author => 'Ken'}, |
|
525 |
filter => {title => 'encode_utf8'}); |
|
526 |
|
|
527 |
# Delete all |
|
528 |
$dbi->delete_all(table => 'books'); |
|
cleanup
|
529 | |
renamed build_query to creat...
|
530 |
Select |
cleanup
|
531 | |
removed reconnect method
|
532 |
# Select |
533 |
my $result = $dbi->select(table => 'books'); |
|
renamed fetch_rows to fetch_...
|
534 |
|
renamed build_query to creat...
|
535 |
# Select, more complex |
renamed fetch_rows to fetch_...
|
536 |
my $result = $dbi->select( |
update document
|
537 |
table => 'books', |
538 |
column => [qw/author title/], |
|
539 |
where => {author => 'Ken'}, |
|
updated document
|
540 |
append => 'order by id limit 5', |
renamed build_query to creat...
|
541 |
filter => {title => 'encode_utf8'} |
renamed fetch_rows to fetch_...
|
542 |
); |
added commit method
|
543 |
|
renamed build_query to creat...
|
544 |
# Select, join table |
added commit method
|
545 |
my $result = $dbi->select( |
renamed build_query to creat...
|
546 |
table => ['books', 'rental'], |
547 |
column => ['books.name as book_name'] |
|
added commit method
|
548 |
relation => {'books.id' => 'rental.book_id'} |
549 |
); |
|
updated document
|
550 |
|
551 |
# Select, more flexible where |
|
552 |
my $result = $dbi->select( |
|
553 |
table => 'books', |
|
554 |
where => ['{= author} and {like title}', |
|
555 |
{author => 'Ken', title => '%Perl%'}] |
|
556 |
); |
|
cleanup
|
557 | |
renamed build_query to creat...
|
558 |
Execute SQL |
cleanup
|
559 | |
renamed build_query to creat...
|
560 |
# Execute SQL |
removed register_format()
|
561 |
$dbi->execute("select title from books"); |
562 |
|
|
renamed build_query to creat...
|
563 |
# Execute SQL with hash binding and filtering |
updated document
|
564 |
$dbi->execute("select id from books where {= author} and {like title}", |
removed register_format()
|
565 |
param => {author => 'ken', title => '%Perl%'}, |
renamed build_query to creat...
|
566 |
filter => {title => 'encode_utf8'}); |
removed reconnect method
|
567 | |
568 |
# Create query and execute it |
|
renamed build_query to creat...
|
569 |
my $query = $dbi->create_query( |
updated document
|
570 |
"select id from books where {= author} and {like title}" |
removed reconnect method
|
571 |
); |
updated document
|
572 |
$dbi->execute($query, param => {author => 'Ken', title => '%Perl%'}) |
cleanup
|
573 | |
updated document
|
574 |
Other features. |
cleanup
|
575 | |
removed register_format()
|
576 |
# Default filter |
renamed default_query_filter...
|
577 |
$dbi->default_bind_filter('encode_utf8'); |
removed register_format()
|
578 |
$dbi->default_fetch_filter('decode_utf8'); |
cleanup
|
579 | |
580 |
# Get DBI object |
|
581 |
my $dbh = $dbi->dbh; |
|
582 | ||
583 |
Fetch row. |
|
584 | ||
removed register_format()
|
585 |
# Fetch |
586 |
while (my $row = $result->fetch) { |
|
587 |
# ... |
|
588 |
} |
|
589 |
|
|
590 |
# Fetch hash |
|
591 |
while (my $row = $result->fetch_hash) { |
|
592 |
|
|
593 |
} |
|
594 |
|
|
renamed update tag to update...
|
595 |
=head1 DESCRIPTIONS |
removed reconnect method
|
596 | |
renamed build_query to creat...
|
597 |
=head2 1. Features |
removed reconnect method
|
598 | |
renamed build_query to creat...
|
599 |
L<DBIx::Custom> is one of L<DBI> interface modules, |
600 |
such as L<DBIx::Class>, L<DBIx::Simple>. |
|
removed reconnect method
|
601 | |
renamed build_query to creat...
|
602 |
This module is not O/R mapper. O/R mapper is useful, |
603 |
but you must learn many syntax of the O/R mapper, |
|
updated document
|
604 |
which is almost another language. |
605 |
Created SQL statement is offten not effcient and damage SQL performance. |
|
renamed build_query to creat...
|
606 |
so you have to execute raw SQL in the end. |
removed reconnect method
|
607 | |
renamed build_query to creat...
|
608 |
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
updated document
|
609 |
L<DBIx::Custom> provide flexible hash parameter binding and filtering system, |
610 |
and suger methods, such as C<select()>, C<update()>, C<delete()>, C<select()> |
|
611 |
to execute SQL easily. |
|
removed reconnect method
|
612 | |
updated document
|
613 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
614 |
but de-facto standard, |
|
615 |
so all people learing database know it. |
|
renamed update tag to update...
|
616 |
If you already know SQL, |
617 |
you learn a little thing to use L<DBIx::Custom>. |
|
removed reconnect method
|
618 | |
renamed update tag to update...
|
619 |
=head2 2. Connect to the database |
removed reconnect method
|
620 | |
renamed build_query to creat...
|
621 |
C<connect()> method create a new L<DBIx::Custom> |
622 |
object and connect to the database. |
|
removed reconnect method
|
623 | |
renamed build_query to creat...
|
624 |
use DBIx::Custom; |
renamed update tag to update...
|
625 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
renamed build_query to creat...
|
626 |
user => 'ken', password => '!LFKD%$&'); |
627 | ||
renamed update tag to update...
|
628 |
If database is SQLite, use L<DBIx::Custom::SQLite> instead. |
629 |
you connect database easily. |
|
update document
|
630 | |
631 |
use DBIx::Custom::SQLite; |
|
renamed update tag to update...
|
632 |
my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname'); |
update document
|
633 |
|
cleanup
|
634 |
If database is MySQL, use L<DBIx::Custom::MySQL>. |
update document
|
635 | |
636 |
use DBIx::Custom::MySQL; |
|
renamed update tag to update...
|
637 |
my $dbi = DBIx::Custom::MySQL->connect( |
638 |
database => 'dbname', |
|
639 |
user => 'ken', |
|
640 |
password => '!LFKD%$&' |
|
641 |
); |
|
update document
|
642 | |
renamed update tag to update...
|
643 |
=head2 3. Suger methods |
renamed build_query to creat...
|
644 | |
645 |
L<DBIx::Custom> has suger methods, such as C<insert()>, C<update()>, |
|
renamed update tag to update...
|
646 |
C<delete()> or C<select()>. If you want to do small works, |
updated document
|
647 |
You don't have to create SQL statements. |
renamed build_query to creat...
|
648 | |
update document
|
649 |
=head3 insert() |
650 | ||
updated document
|
651 |
Execute insert statement. |
652 | ||
update document
|
653 |
$dbi->insert(table => 'books', |
renamed update tag to update...
|
654 |
param => {title => 'Perl', author => 'Ken'}); |
update document
|
655 | |
656 |
The following SQL is executed. |
|
657 | ||
updated document
|
658 |
insert into (title, author) values (?, ?); |
update document
|
659 | |
renamed update tag to update...
|
660 |
The values of C<title> and C<author> is embedded into the placeholders. |
update document
|
661 | |
renamed update tag to update...
|
662 |
C<append> and C<filter> argument can be specified. |
663 |
See also "METHODS" section. |
|
update document
|
664 | |
665 |
=head3 update() |
|
666 | ||
updated document
|
667 |
Execute update statement. |
668 | ||
update document
|
669 |
$dbi->update(table => 'books', |
renamed update tag to update...
|
670 |
param => {title => 'Perl', author => 'Ken'}, |
update document
|
671 |
where => {id => 5}); |
672 | ||
673 |
The following SQL is executed. |
|
674 | ||
675 |
update books set title = ?, author = ?; |
|
676 | ||
renamed update tag to update...
|
677 |
The values of C<title> and C<author> is embedded into the placeholders. |
update document
|
678 | |
renamed update tag to update...
|
679 |
C<append> and C<filter> argument can be specified. |
680 |
See also "METHOD" section. |
|
update document
|
681 | |
renamed update tag to update...
|
682 |
If you want to update all rows, use C<update_all()> method. |
update document
|
683 | |
684 |
=head3 delete() |
|
685 | ||
updated document
|
686 |
Execute delete statement. |
687 | ||
update document
|
688 |
$dbi->delete(table => 'books', |
689 |
where => {author => 'Ken'}); |
|
690 | ||
691 |
The following SQL is executed. |
|
692 | ||
693 |
delete from books where id = ?; |
|
694 | ||
updated document
|
695 |
The value of C<id> is embedded into the placehodler. |
update document
|
696 | |
renamed update tag to update...
|
697 |
C<append> and C<filter> argument can be specified. |
698 |
see also "METHODS" section. |
|
update document
|
699 | |
renamed update tag to update...
|
700 |
If you want to delete all rows, use C<delete_all()> method. |
update document
|
701 | |
702 |
=head3 select() |
|
703 | ||
updated document
|
704 |
Execute select statement, only C<table> argument specified : |
update document
|
705 | |
706 |
my $result = $dbi->select(table => 'books'); |
|
707 | ||
708 |
The following SQL is executed. |
|
709 | ||
710 |
select * from books; |
|
711 | ||
712 |
the result of C<select()> method is L<DBIx::Custom::Result> object. |
|
renamed update tag to update...
|
713 |
You can fetch a row by C<fetch()> method. |
update document
|
714 | |
715 |
while (my $row = $result->fetch) { |
|
716 |
my $title = $row->[0]; |
|
717 |
my $author = $row->[1]; |
|
718 |
} |
|
719 | ||
720 |
L<DBIx::Custom::Result> has various methods to fetch row. |
|
renamed update tag to update...
|
721 |
See "4. Fetch row". |
update document
|
722 | |
renamed update tag to update...
|
723 |
C<column> and C<where> arguments specified. |
update document
|
724 | |
725 |
my $result = $dbi->select( |
|
726 |
table => 'books', |
|
727 |
column => [qw/author title/], |
|
renamed update tag to update...
|
728 |
where => {author => 'Ken'} |
729 |
); |
|
update document
|
730 | |
731 |
The following SQL is executed. |
|
732 | ||
733 |
select author, title from books where author = ?; |
|
734 | ||
renamed update tag to update...
|
735 |
the value of C<author> is embdded into the placeholder. |
update document
|
736 | |
updated document
|
737 |
If you want to join tables, specify C<relation> argument. |
update document
|
738 | |
739 |
my $result = $dbi->select( |
|
740 |
table => ['books', 'rental'], |
|
741 |
column => ['books.name as book_name'] |
|
742 |
relation => {'books.id' => 'rental.book_id'} |
|
743 |
); |
|
744 | ||
745 |
The following SQL is executed. |
|
746 | ||
renamed update tag to update...
|
747 |
select books.name as book_name from books, rental |
update document
|
748 |
where books.id = rental.book_id; |
749 | ||
renamed update tag to update...
|
750 |
If you want to add some string to the end of SQL statement, |
751 |
use C<append> argument. |
|
update document
|
752 | |
753 |
my $result = $dbi->select( |
|
754 |
table => 'books', |
|
755 |
where => {author => 'Ken'}, |
|
756 |
append => 'order by price limit 5', |
|
757 |
); |
|
758 | ||
759 |
The following SQL is executed. |
|
760 | ||
761 |
select * books where author = ? order by price limit 5; |
|
762 | ||
renamed update tag to update...
|
763 |
C<filter> argument can be specified. |
764 |
see also "METHODS" section. |
|
update document
|
765 | |
renamed update tag to update...
|
766 |
=head2 4. Fetch row |
update document
|
767 | |
updated document
|
768 |
C<select()> method return L<DBIx::Custom::Result> object. |
769 |
You can fetch row by various methods. |
|
renamed update tag to update...
|
770 |
Note that in this section, array means array reference, |
771 |
and hash meanse hash reference. |
|
update document
|
772 | |
773 |
Fetch row into array. |
|
774 |
|
|
775 |
while (my $row = $result->fetch) { |
|
776 |
my $author = $row->[0]; |
|
777 |
my $title = $row->[1]; |
|
778 |
|
|
779 |
} |
|
780 | ||
781 |
Fetch only a first row into array. |
|
782 | ||
783 |
my $row = $result->fetch_first; |
|
784 | ||
785 |
Fetch multiple rows into array of array. |
|
786 | ||
787 |
while (my $rows = $result->fetch_multi(5)) { |
|
788 |
my $first_author = $rows->[0][0]; |
|
789 |
my $first_title = $rows->[0][1]; |
|
790 |
my $second_author = $rows->[1][0]; |
|
791 |
my $second_value = $rows->[1][1]; |
|
792 |
|
|
793 |
} |
|
794 |
|
|
795 |
Fetch all rows into array of array. |
|
796 | ||
797 |
my $rows = $result->fetch_all; |
|
798 | ||
799 |
Fetch row into hash. |
|
800 | ||
801 |
# Fetch a row into hash |
|
802 |
while (my $row = $result->fetch_hash) { |
|
803 |
my $title = $row->{title}; |
|
804 |
my $author = $row->{author}; |
|
805 |
|
|
806 |
} |
|
807 | ||
808 |
Fetch only a first row into hash |
|
809 | ||
810 |
my $row = $result->fetch_hash_first; |
|
811 |
|
|
812 |
Fetch multiple rows into array of hash |
|
813 | ||
814 |
while (my $rows = $result->fetch_hash_multi(5)) { |
|
815 |
my $first_title = $rows->[0]{title}; |
|
816 |
my $first_author = $rows->[0]{author}; |
|
817 |
my $second_title = $rows->[1]{title}; |
|
818 |
my $second_author = $rows->[1]{author}; |
|
819 |
|
|
820 |
} |
|
821 |
|
|
822 |
Fetch all rows into array of hash |
|
823 | ||
824 |
my $rows = $result->fetch_hash_all; |
|
removed DESTROY method(not b...
|
825 | |
cleanup
|
826 |
If you want to access statement handle of L<DBI>, use C<sth> attribute. |
removed DESTROY method(not b...
|
827 | |
update document
|
828 |
my $sth = $result->sth; |
removed DESTROY method(not b...
|
829 | |
renamed update tag to update...
|
830 |
=head2 5. Hash parameter binding |
removed reconnect method
|
831 | |
update document
|
832 |
L<DBIx::Custom> provides hash parameter binding. |
833 | ||
renamed update tag to update...
|
834 |
At frist, I show normal parameter binding. |
update document
|
835 | |
836 |
use DBI; |
|
837 |
my $dbh = DBI->connect(...); |
|
838 |
my $sth = $dbh->prepare( |
|
839 |
"select * from books where author = ? and title like ?;" |
|
840 |
); |
|
841 |
$sth->execute('Ken', '%Perl%'); |
|
842 | ||
updated document
|
843 |
This is very good way because database system can enable SQL caching, |
renamed update tag to update...
|
844 |
and parameter is quoted automatically. this is secure. |
update document
|
845 | |
updated document
|
846 |
L<DBIx::Custom> hash parameter binding system improve |
renamed update tag to update...
|
847 |
normal parameter binding to use hash parameter. |
update document
|
848 | |
849 |
my $result = $dbi->execute( |
|
850 |
"select * from books where {= author} and {like title};" |
|
851 |
param => {author => 'Ken', title => '%Perl%'} |
|
852 |
); |
|
853 | ||
854 |
This is same as the normal way, execpt that the parameter is hash. |
|
renamed update tag to update...
|
855 |
{= author} and {like title} is called C<tag>. |
856 |
tag is expand to placeholder string internally. |
|
update document
|
857 | |
858 |
select * from books where {= author} and {like title} |
|
859 |
-> select * from books where author = ? and title like ?; |
|
860 | ||
updated document
|
861 |
The following tags is available. |
862 | ||
863 |
[TAG] [REPLACED] |
|
864 |
{? NAME} -> ? |
|
865 |
{= NAME} -> NAME = ? |
|
866 |
{<> NAME} -> NAME <> ? |
|
867 |
|
|
868 |
{< NAME} -> NAME < ? |
|
869 |
{> NAME} -> NAME > ? |
|
870 |
{>= NAME} -> NAME >= ? |
|
871 |
{<= NAME} -> NAME <= ? |
|
872 |
|
|
873 |
{like NAME} -> NAME like ? |
|
874 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
875 |
|
|
renamed update tag to update...
|
876 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
877 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
updated document
|
878 | |
879 |
See also L<DBIx::Custom::QueryBuilder>. |
|
880 | ||
removed DBIx::Custom::Query ...
|
881 |
C<{> and C<}> is reserved. If you use these charactors, |
882 |
you must escape them using '\'. Note that '\' is |
|
883 |
already perl escaped charactor, so you must write '\\'. |
|
updated document
|
884 | |
removed DBIx::Custom::Query ...
|
885 |
'select * from books \\{ something statement \\}' |
update document
|
886 | |
renamed update tag to update...
|
887 |
=head2 6. Filtering |
update document
|
888 | |
889 |
Usually, Perl string is kept as internal string. |
|
890 |
If you want to save the string to database, You must encode the string. |
|
891 |
Filtering system help you to convert a data to another data |
|
892 |
when you save to the data and get the data form database. |
|
893 | ||
updated document
|
894 |
If you want to register filter, use C<register_filter()> method. |
update document
|
895 | |
896 |
$dbi->register_filter( |
|
897 |
to_upper_case => sub { |
|
898 |
my $value = shift; |
|
899 |
return uc $value; |
|
900 |
} |
|
901 |
); |
|
902 | ||
903 |
C<encode_utf8> and C<decode_utf8> filter is registerd by default. |
|
904 | ||
905 |
You can specify these filters to C<filter> argument of C<execute()> method. |
|
906 | ||
907 |
my $result = $dbi->execute( |
|
908 |
"select * from books where {= author} and {like title};" |
|
updated document
|
909 |
param => {author => 'Ken', title => '%Perl%'}, |
update document
|
910 |
filter => {author => 'to_upper_case, title => 'encode_utf8'} |
911 |
); |
|
912 | ||
renamed update tag to update...
|
913 |
C<filter> argument can be specified to suger methods, such as |
cleanup
|
914 |
C<insert()>, C<update()>, C<update_all()>, |
renamed update tag to update...
|
915 |
C<delete()>, C<delete_all()>, C<select()>. |
update document
|
916 | |
renamed update tag to update...
|
917 |
# insert(), having filter argument |
update document
|
918 |
$dbi->insert(table => 'books', |
renamed update tag to update...
|
919 |
param => {title => 'Perl', author => 'Ken'}, |
update document
|
920 |
filter => {title => 'encode_utf8'}); |
renamed update tag to update...
|
921 |
|
922 |
# select(), having filter argument |
|
update document
|
923 |
my $result = $dbi->select( |
924 |
table => 'books', |
|
925 |
column => [qw/author title/], |
|
926 |
where => {author => 'Ken'}, |
|
927 |
append => 'order by id limit 1', |
|
928 |
filter => {title => 'encode_utf8'} |
|
929 |
); |
|
930 | ||
updated document
|
931 |
Filter works each parmeter, but you prepare default filter for all parameters. |
update document
|
932 | |
933 |
$dbi->default_bind_filter('encode_utf8'); |
|
934 | ||
renamed update tag to update...
|
935 |
C<filter()> argument overwrites this default filter. |
update document
|
936 |
|
937 |
$dbi->default_bind_filter('encode_utf8'); |
|
938 |
$dbi->insert( |
|
939 |
table => 'books', |
|
renamed update tag to update...
|
940 |
param => {title => 'Perl', author => 'Ken', price => 1000}, |
update document
|
941 |
filter => {author => 'to_upper_case', price => undef} |
942 |
); |
|
943 | ||
renamed update tag to update...
|
944 |
This is same as the following example. |
update document
|
945 | |
946 |
$dbi->insert( |
|
947 |
table => 'books', |
|
renamed update tag to update...
|
948 |
param => {title => 'Perl', author => 'Ken', price => 1000}, |
update document
|
949 |
filter => {title => 'encode_uft8' author => 'to_upper_case'} |
950 |
); |
|
951 | ||
updated document
|
952 |
You can also specify filter when the row is fetched. This is reverse of bind filter. |
update document
|
953 | |
954 |
my $result = $dbi->select(table => 'books'); |
|
955 |
$result->filter({title => 'decode_utf8', author => 'to_upper_case'}); |
|
956 | ||
renamed update tag to update...
|
957 |
Filter works each column value, but you prepare a default filter |
958 |
for all clumn value. |
|
update document
|
959 | |
960 |
$dbi->default_fetch_filter('decode_utf8'); |
|
961 | ||
renamed update tag to update...
|
962 |
C<filter()> method of L<DBIx::Custom::Result> |
963 |
overwrites this default filter. |
|
update document
|
964 | |
965 |
$dbi->default_fetch_filter('decode_utf8'); |
|
966 |
my $result = $dbi->select( |
|
967 |
table => 'books', |
|
968 |
columns => ['title', 'author', 'price'] |
|
969 |
); |
|
970 |
$result->filter({author => 'to_upper_case', price => undef}); |
|
971 | ||
972 |
This is same as the following one. |
|
973 | ||
974 |
my $result = $dbi->select( |
|
975 |
table => 'books', |
|
976 |
columns => ['title', 'author', 'price'] |
|
977 |
); |
|
978 |
$result->filter({title => 'decode_utf8', author => 'to_upper_case'}); |
|
removed reconnect method
|
979 | |
renamed update tag to update...
|
980 |
Note that in fetch filter, column names must be lower case |
981 |
even if the column name conatains upper case charactors. |
|
982 |
This is requirment not to depend database systems. |
|
added check_filter attribute
|
983 | |
cleanup
|
984 |
=head2 7. Get high performance |
updated document
|
985 | |
updated document
|
986 |
=head3 Disable filter checking |
987 | ||
renamed update tag to update...
|
988 |
Filter checking is executed by default. |
989 |
This is done to check right filter name is specified, |
|
990 |
but sometimes damage performance. |
|
updated document
|
991 | |
renamed update tag to update...
|
992 |
If you disable this filter checking, |
993 |
Set C<filter_check> attribute to 0. |
|
updated document
|
994 | |
renamed update tag to update...
|
995 |
$dbi->filter_check(0); |
updated document
|
996 | |
renamed update tag to update...
|
997 |
=head3 Use execute() method instead suger methods |
998 | ||
999 |
If you execute insert statement by C<insert()> method, |
|
1000 |
you sometimes can't get required performance. |
|
updated document
|
1001 | |
1002 |
C<insert()> method is a little slow because SQL statement and statement handle |
|
1003 |
is created every time. |
|
1004 | ||
1005 |
In that case, you can prepare a query by C<create_query()> method. |
|
1006 |
|
|
1007 |
my $query = $dbi->create_query( |
|
renamed update tag to update...
|
1008 |
"insert into books {insert_param title author};" |
updated document
|
1009 |
); |
cleanup
|
1010 | |
1011 |
Return value of C<create_query()> is L<DBIx::Custom::Query> object. |
|
1012 |
This keep the information of SQL and column names. |
|
1013 | ||
1014 |
{ |
|
1015 |
sql => 'insert into books (title, author) values (?, ?);', |
|
1016 |
columns => ['title', 'author'] |
|
1017 |
} |
|
1018 | ||
1019 |
Execute query repeatedly. |
|
updated document
|
1020 |
|
1021 |
my $inputs = [ |
|
1022 |
{title => 'Perl', author => 'Ken'}, |
|
1023 |
{title => 'Good days', author => 'Mike'} |
|
1024 |
]; |
|
1025 |
|
|
1026 |
foreach my $input (@$inputs) { |
|
1027 |
$dbi->execute($query, $input); |
|
1028 |
} |
|
1029 | ||
cleanup
|
1030 |
This is faster than C<insert()> method. |
updated document
|
1031 | |
cleanup
|
1032 |
=head3 caching |
updated document
|
1033 | |
cleanup
|
1034 |
C<execute()> method caches the parsed result of the source of SQL. |
updated document
|
1035 |
Default to 1 |
1036 | ||
1037 |
$dbi->cache(1); |
|
1038 | ||
1039 |
Caching is on memory, but you can change this by C<cache_method()>. |
|
1040 |
First argument is L<DBIx::Custom> object. |
|
cleanup
|
1041 |
Second argument is a source of SQL, |
1042 |
such as "select * from books where {= title} and {= author};"; |
|
updated document
|
1043 |
Third argument is parsed result, such as |
1044 |
{sql => "select * from books where title = ? and author = ?", |
|
1045 |
columns => ['title', 'author']}, this is hash reference. |
|
cleanup
|
1046 |
If arguments is more than two, this method is called to set cache. |
1047 |
If not, this method is called to get cache. |
|
updated document
|
1048 | |
cleanup
|
1049 |
$dbi->cache_method(sub { |
updated document
|
1050 |
sub { |
1051 |
my $self = shift; |
|
1052 |
|
|
1053 |
$self->{_cached} ||= {}; |
|
1054 |
|
|
1055 |
# Set cache |
|
1056 |
if (@_ > 1) { |
|
1057 |
$self->{_cached}{$_[0]} = $_[1] |
|
1058 |
} |
|
1059 |
|
|
1060 |
# Get cache |
|
1061 |
else { |
|
1062 |
return $self->{_cached}{$_[0]} |
|
1063 |
} |
|
1064 |
} |
|
1065 |
}); |
|
1066 | ||
renamed update tag to update...
|
1067 |
=head2 8. More features |
updated document
|
1068 | |
1069 |
=head3 Get DBI object |
|
1070 | ||
1071 |
You can get L<DBI> object and call any method of L<DBI>. |
|
1072 | ||
1073 |
$dbi->dbh->begin_work; |
|
1074 |
$dbi->dbh->commit; |
|
1075 |
$dbi->dbh->rollback; |
|
1076 | ||
1077 |
=head3 Change Result class |
|
1078 | ||
1079 |
You can change Result class if you need. |
|
1080 | ||
1081 |
package Your::Result; |
|
1082 |
use base 'DBIx::Custom::Result'; |
|
1083 |
|
|
1084 |
sub some_method { ... } |
|
1085 | ||
1086 |
1; |
|
1087 |
|
|
1088 |
package main; |
|
1089 |
|
|
1090 |
use Your::Result; |
|
1091 |
|
|
1092 |
my $dbi = DBIx::Custom->connect(...); |
|
1093 |
$dbi->result_class('Your::Result'); |
|
1094 | ||
1095 |
=head3 Custamize SQL builder object |
|
1096 | ||
1097 |
You can custamize SQL builder object |
|
1098 | ||
1099 |
my $dbi = DBIx::Custom->connect(...); |
|
1100 |
$dbi->query_builder->register_tag_processor( |
|
1101 |
name => sub { |
|
1102 |
... |
|
1103 |
} |
|
1104 |
); |
|
1105 | ||
update document
|
1106 |
=head1 ATTRIBUTES |
packaging one directory
|
1107 | |
removed DBIx::Custom commit ...
|
1108 |
=head2 C<user> |
packaging one directory
|
1109 | |
cleanup
|
1110 |
my $user = $dbi->user; |
1111 |
$dbi = $dbi->user('Ken'); |
|
removed DESTROY method(not b...
|
1112 | |
cleanup
|
1113 |
User name. |
1114 |
C<connect()> method use this value to connect the database. |
|
bind_filter argument is chan...
|
1115 |
|
removed DBIx::Custom commit ...
|
1116 |
=head2 C<password> |
packaging one directory
|
1117 | |
cleanup
|
1118 |
my $password = $dbi->password; |
1119 |
$dbi = $dbi->password('lkj&le`@s'); |
|
packaging one directory
|
1120 | |
cleanup
|
1121 |
Password. |
1122 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1123 | |
removed DBIx::Custom commit ...
|
1124 |
=head2 C<data_source> |
packaging one directory
|
1125 | |
cleanup
|
1126 |
my $data_source = $dbi->data_source; |
cleanup
|
1127 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
1128 | |
cleanup
|
1129 |
Data source. |
1130 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1131 | |
removed DBIx::Custom commit ...
|
1132 |
=head2 C<dbh> |
packaging one directory
|
1133 | |
cleanup
|
1134 |
my $dbh = $dbi->dbh; |
1135 |
$dbi = $dbi->dbh($dbh); |
|
packaging one directory
|
1136 | |
cleanup
|
1137 |
L<DBI> object. You can call all methods of L<DBI>. |
packaging one directory
|
1138 | |
removed DBIx::Custom commit ...
|
1139 |
=head2 C<filters> |
packaging one directory
|
1140 | |
cleanup
|
1141 |
my $filters = $dbi->filters; |
cleanup
|
1142 |
$dbi = $dbi->filters(\%filters); |
version 0.0901
|
1143 | |
removed DESTROY method(not b...
|
1144 |
Filter functions. |
renamed build_query to creat...
|
1145 |
"encode_utf8" and "decode_utf8" is registered by default. |
version 0.0901
|
1146 | |
renamed default_query_filter...
|
1147 |
=head2 C<default_bind_filter> |
packaging one directory
|
1148 | |
cleanup
|
1149 |
my $default_bind_filter = $dbi->default_bind_filter |
1150 |
$dbi = $dbi->default_bind_filter('encode_utf8'); |
|
packaging one directory
|
1151 | |
cleanup
|
1152 |
Default filter when parameter binding is executed. |
packaging one directory
|
1153 | |
removed DESTROY method(not b...
|
1154 |
=head2 C<default_fetch_filter> |
bind_filter argument is chan...
|
1155 | |
cleanup
|
1156 |
my $default_fetch_filter = $dbi->default_fetch_filter; |
1157 |
$dbi = $dbi->default_fetch_filter('decode_utf8'); |
|
bind_filter argument is chan...
|
1158 | |
cleanup
|
1159 |
Default filter when row is fetched. |
packaging one directory
|
1160 | |
removed DESTROY method(not b...
|
1161 |
=head2 C<result_class> |
bind_filter argument is chan...
|
1162 | |
cleanup
|
1163 |
my $result_class = $dbi->result_class; |
1164 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
packaging one directory
|
1165 | |
removed DESTROY method(not b...
|
1166 |
Result class for select statement. |
renamed default_query_filter...
|
1167 |
Default to L<DBIx::Custom::Result>. |
update document
|
1168 | |
renamed update tag to update...
|
1169 |
=head2 C<query_builder> |
added commit method
|
1170 | |
renamed update tag to update...
|
1171 |
my $sql_class = $dbi->query_builder; |
1172 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1173 | |
renamed update tag to update...
|
1174 |
SQL builder. C<query_builder()> must be |
renamed build_query to creat...
|
1175 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
1176 |
Default to L<DBIx::Custom::QueryBuilder> object. |
|
cleanup
|
1177 | |
1178 |
=head2 C<cache> |
|
1179 | ||
1180 |
my $cache = $dbi->cache; |
|
1181 |
$dbi = $dbi->cache(1); |
|
1182 | ||
renamed build_query to creat...
|
1183 |
Enable parsed L<DBIx::Custom::Query> object caching. |
cleanup
|
1184 |
Default to 1. |
1185 | ||
1186 |
=head2 C<cache_method> |
|
1187 | ||
1188 |
$dbi = $dbi->cache_method(\&cache_method); |
|
1189 |
$cache_method = $dbi->cache_method |
|
1190 | ||
renamed build_query to creat...
|
1191 |
Method to set and get caches. |
cleanup
|
1192 | |
1193 |
B<Example:> |
|
1194 | ||
1195 |
$dbi->cache_method( |
|
1196 |
sub { |
|
1197 |
my $self = shift; |
|
1198 |
|
|
1199 |
$self->{_cached} ||= {}; |
|
1200 |
|
|
1201 |
if (@_ > 1) { |
|
1202 |
$self->{_cached}{$_[0]} = $_[1] |
|
1203 |
} |
|
1204 |
else { |
|
1205 |
return $self->{_cached}{$_[0]} |
|
1206 |
} |
|
1207 |
} |
|
1208 |
); |
|
added commit method
|
1209 | |
added check_filter attribute
|
1210 |
=head2 C<filter_check> |
1211 | ||
1212 |
my $filter_check = $dbi->filter_check; |
|
1213 |
$dbi = $dbi->filter_check(0); |
|
1214 | ||
1215 |
Enable filter check. |
|
1216 |
Default to 1. |
|
1217 |
This check maybe damege performance. |
|
cleanup
|
1218 |
If you require performance, set C<filter_check> attribute to 0. |
added check_filter attribute
|
1219 | |
removed reconnect method
|
1220 |
=head1 METHODS |
added commit method
|
1221 | |
cleanup
|
1222 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
1223 |
and implements the following new ones. |
|
added commit method
|
1224 | |
removed DBIx::Custom commit ...
|
1225 |
=head2 C<connect> |
packaging one directory
|
1226 | |
cleanup
|
1227 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
update document
|
1228 |
user => 'ken', password => '!LFKD%$&'); |
bind_filter argument is chan...
|
1229 | |
cleanup
|
1230 |
Create a new L<DBIx::Custom> object and connect to the database. |
renamed build_query to creat...
|
1231 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1232 |
C<AutoCommit> and C<RaiseError> options are true, |
renamed build_query to creat...
|
1233 |
and C<PrintError> option is false by default. |
packaging one directory
|
1234 | |
removed DBIx::Custom commit ...
|
1235 |
=head2 C<insert> |
packaging one directory
|
1236 | |
cleanup
|
1237 |
$dbi->insert(table => $table, |
1238 |
param => \%param, |
|
1239 |
append => $append, |
|
1240 |
filter => \%filter); |
|
update document
|
1241 | |
renamed build_query to creat...
|
1242 |
Execute insert statement. |
1243 |
C<insert> method have C<table>, C<param>, C<append> |
|
1244 |
and C<filter> arguments. |
|
1245 |
C<table> is a table name. |
|
cleanup
|
1246 |
C<param> is the pairs of column name value. this must be hash reference. |
renamed build_query to creat...
|
1247 |
C<append> is a string added at the end of the SQL statement. |
1248 |
C<filter> is filters when parameter binding is executed. |
|
1249 |
This is overwrites C<default_bind_filter>. |
|
cleanup
|
1250 |
Return value of C<insert()> is the count of affected rows. |
renamed build_query to creat...
|
1251 | |
removed DESTROY method(not b...
|
1252 |
B<Example:> |
version 0.0901
|
1253 | |
removed register_format()
|
1254 |
$dbi->insert(table => 'books', |
1255 |
param => {title => 'Perl', author => 'Taro'}, |
|
1256 |
append => "some statement", |
|
1257 |
filter => {title => 'encode_utf8'}) |
|
version 0.0901
|
1258 | |
removed DBIx::Custom commit ...
|
1259 |
=head2 C<update> |
packaging one directory
|
1260 | |
cleanup
|
1261 |
$dbi->update(table => $table, |
1262 |
param => \%params, |
|
1263 |
where => \%where, |
|
1264 |
append => $append, |
|
1265 |
filter => \%filter) |
|
version 0.0901
|
1266 | |
renamed build_query to creat...
|
1267 |
Execute update statement. |
1268 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
|
1269 |
and C<filter> arguments. |
|
1270 |
C<table> is a table name. |
|
1271 |
C<param> is column-value pairs. this must be hash reference. |
|
1272 |
C<where> is where clause. this must be hash reference. |
|
1273 |
C<append> is a string added at the end of the SQL statement. |
|
1274 |
C<filter> is filters when parameter binding is executed. |
|
1275 |
This is overwrites C<default_bind_filter>. |
|
cleanup
|
1276 |
Return value of C<update()> is the count of affected rows. |
update document
|
1277 | |
removed DESTROY method(not b...
|
1278 |
B<Example:> |
bind_filter argument is chan...
|
1279 | |
removed register_format()
|
1280 |
$dbi->update(table => 'books', |
1281 |
param => {title => 'Perl', author => 'Taro'}, |
|
1282 |
where => {id => 5}, |
|
cleanup
|
1283 |
append => "some statement", |
added commit method
|
1284 |
filter => {title => 'encode_utf8'}); |
version 0.0901
|
1285 | |
removed DBIx::Custom commit ...
|
1286 |
=head2 C<update_all> |
packaging one directory
|
1287 | |
cleanup
|
1288 |
$dbi->update_all(table => $table, |
1289 |
param => \%params, |
|
1290 |
filter => \%filter, |
|
1291 |
append => $append); |
|
update document
|
1292 | |
renamed build_query to creat...
|
1293 |
Execute update statement to update all rows. |
1294 |
Arguments is same as C<update> method, |
|
1295 |
except that C<update_all> don't have C<where> argument. |
|
cleanup
|
1296 |
Return value of C<update_all()> is the count of affected rows. |
version 0.0901
|
1297 | |
removed DESTROY method(not b...
|
1298 |
B<Example:> |
update document
|
1299 | |
removed register_format()
|
1300 |
$dbi->update_all(table => 'books', |
1301 |
param => {author => 'taro'}, |
|
1302 |
filter => {author => 'encode_utf8'}); |
|
packaging one directory
|
1303 | |
removed DBIx::Custom commit ...
|
1304 |
=head2 C<delete> |
packaging one directory
|
1305 | |
cleanup
|
1306 |
$dbi->delete(table => $table, |
1307 |
where => \%where, |
|
1308 |
append => $append, |
|
1309 |
filter => \%filter); |
|
bind_filter argument is chan...
|
1310 | |
renamed build_query to creat...
|
1311 |
Execute delete statement. |
1312 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
1313 |
C<table> is a table name. |
|
1314 |
C<where> is where clause. this must be hash reference. |
|
1315 |
C<append> is a string added at the end of the SQL statement. |
|
1316 |
C<filter> is filters when parameter binding is executed. |
|
cleanup
|
1317 |
Return value of C<delete()> is the count of affected rows. |
renamed build_query to creat...
|
1318 | |
removed DESTROY method(not b...
|
1319 |
B<Example:> |
packaging one directory
|
1320 | |
removed register_format()
|
1321 |
$dbi->delete(table => 'books', |
1322 |
where => {id => 5}, |
|
1323 |
append => 'some statement', |
|
removed reconnect method
|
1324 |
filter => {id => 'encode_utf8'}); |
version 0.0901
|
1325 | |
removed DBIx::Custom commit ...
|
1326 |
=head2 C<delete_all> |
packaging one directory
|
1327 | |
cleanup
|
1328 |
$dbi->delete_all(table => $table); |
packaging one directory
|
1329 | |
renamed build_query to creat...
|
1330 |
Execute delete statement to delete all rows. |
1331 |
Arguments is same as C<delete> method, |
|
1332 |
except that C<delete_all> don't have C<where> argument. |
|
cleanup
|
1333 |
Return value of C<delete_all()> is the count of affected rows. |
bind_filter argument is chan...
|
1334 | |
removed DESTROY method(not b...
|
1335 |
B<Example:> |
removed register_format()
|
1336 |
|
removed reconnect method
|
1337 |
$dbi->delete_all(table => 'books'); |
packaging one directory
|
1338 | |
removed DBIx::Custom commit ...
|
1339 |
=head2 C<select> |
packaging one directory
|
1340 |
|
cleanup
|
1341 |
my $result = $dbi->select(table => $table, |
1342 |
column => [@column], |
|
1343 |
where => \%where, |
|
1344 |
append => $append, |
|
1345 |
relation => \%relation, |
|
1346 |
filter => \%filter); |
|
update document
|
1347 | |
renamed build_query to creat...
|
1348 |
Execute select statement. |
cleanup
|
1349 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
renamed build_query to creat...
|
1350 |
C<relation> and C<filter> arguments. |
1351 |
C<table> is a table name. |
|
cleanup
|
1352 |
C<where> is where clause. this is normally hash reference. |
renamed build_query to creat...
|
1353 |
C<append> is a string added at the end of the SQL statement. |
1354 |
C<filter> is filters when parameter binding is executed. |
|
update document
|
1355 | |
removed DESTROY method(not b...
|
1356 |
B<Example:> |
update document
|
1357 | |
added commit method
|
1358 |
# select * from books; |
cleanup
|
1359 |
my $result = $dbi->select(table => 'books'); |
packaging one directory
|
1360 |
|
renamed build_query to creat...
|
1361 |
# select * from books where title = ?; |
1362 |
my $result = $dbi->select(table => 'books', where => {title => 'Perl'}); |
|
update document
|
1363 |
|
renamed build_query to creat...
|
1364 |
# select title, author from books where id = ? for update; |
cleanup
|
1365 |
my $result = $dbi->select( |
removed register_format()
|
1366 |
table => 'books', |
removed reconnect method
|
1367 |
column => ['title', 'author'], |
removed register_format()
|
1368 |
where => {id => 1}, |
1369 |
appned => 'for update' |
|
update document
|
1370 |
); |
1371 |
|
|
renamed update tag to update...
|
1372 |
# select books.name as book_name from books, rental |
added commit method
|
1373 |
# where books.id = rental.book_id; |
1374 |
my $result = $dbi->select( |
|
removed reconnect method
|
1375 |
table => ['books', 'rental'], |
1376 |
column => ['books.name as book_name'] |
|
added commit method
|
1377 |
relation => {'books.id' => 'rental.book_id'} |
update document
|
1378 |
); |
1379 | ||
cleanup
|
1380 |
If you use more complex condition, |
1381 |
you can specify a array reference to C<where> argument. |
|
1382 | ||
1383 |
my $result = $dbi->select( |
|
1384 |
table => 'books', |
|
1385 |
column => ['title', 'author'], |
|
1386 |
where => ['{= title} or {like author}', |
|
1387 |
{title => '%Perl%', author => 'Ken'}] |
|
1388 |
); |
|
1389 | ||
1390 |
First element is a string. it contains tags, |
|
1391 |
such as "{= title} or {like author}". |
|
1392 |
Second element is paramters. |
|
1393 | ||
renamed build_query to creat...
|
1394 |
=head2 C<create_query> |
removed reconnect method
|
1395 |
|
renamed build_query to creat...
|
1396 |
my $query = $dbi->create_query( |
cleanup
|
1397 |
"select * from books where {= author} and {like title};" |
removed DBIx::Custom commit ...
|
1398 |
); |
1399 | ||
cleanup
|
1400 |
Create the instance of L<DBIx::Custom::Query> from the source of SQL. |
1401 |
If you want to get high performance, |
|
1402 |
use C<create_query()> method and execute it by C<execute()> method |
|
1403 |
instead of suger methods. |
|
1404 | ||
1405 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
|
packaging one directory
|
1406 | |
removed DBIx::Custom commit ...
|
1407 |
=head2 C<execute> |
removed reconnect method
|
1408 | |
cleanup
|
1409 |
my $result = $dbi->execute($query, param => $params, filter => \%filter); |
1410 |
my $result = $dbi->execute($source, param => $params, filter => \%filter); |
|
removed reconnect method
|
1411 | |
cleanup
|
1412 |
Execute query or the source of SQL. |
1413 |
Query is L<DBIx::Custom::Query> object. |
|
1414 |
Return value is L<DBIx::Custom::Result> if select statement is executed, |
|
1415 |
or the count of affected rows if insert, update, delete statement is executed. |
|
removed reconnect method
|
1416 | |
removed DBIx::Custom commit ...
|
1417 |
B<Example:> |
removed reconnect method
|
1418 | |
cleanup
|
1419 |
my $result = $dbi->execute( |
1420 |
"select * from books where {= author} and {like title}", |
|
1421 |
param => {author => 'Ken', title => '%Perl%'} |
|
1422 |
); |
|
removed reconnect method
|
1423 |
|
1424 |
while (my $row = $result->fetch) { |
|
cleanup
|
1425 |
my $author = $row->[0]; |
1426 |
my $title = $row->[1]; |
|
removed reconnect method
|
1427 |
} |
1428 | ||
removed DBIx::Custom commit ...
|
1429 |
=head2 C<register_filter> |
removed reconnect method
|
1430 | |
1431 |
$dbi->register_filter(%filters); |
|
removed DESTROY method(not b...
|
1432 |
$dbi->register_filter(\%filters); |
removed reconnect method
|
1433 |
|
cleanup
|
1434 |
Register filter. Registered filters is available in the following attributes |
renamed build_query to creat...
|
1435 |
or arguments. |
1436 | ||
1437 |
=over 4 |
|
1438 | ||
1439 |
=item * |
|
1440 | ||
cleanup
|
1441 |
C<default_bind_filter>, C<default_fetch_filter> |
renamed build_query to creat...
|
1442 | |
1443 |
=item * |
|
1444 | ||
1445 |
C<filter> argument of C<insert()>, C<update()>, |
|
cleanup
|
1446 |
C<update_all()>, C<delete()>, C<delete_all()>, C<select()> |
1447 |
methods |
|
renamed build_query to creat...
|
1448 | |
1449 |
=item * |
|
1450 | ||
cleanup
|
1451 |
C<execute()> method |
renamed build_query to creat...
|
1452 | |
1453 |
=item * |
|
1454 | ||
cleanup
|
1455 |
C<default_filter> and C<filter> of C<DBIx::Custom::Query> |
renamed build_query to creat...
|
1456 | |
1457 |
=item * |
|
1458 | ||
cleanup
|
1459 |
C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
renamed build_query to creat...
|
1460 | |
1461 |
=back |
|
removed DBIx::Custom commit ...
|
1462 | |
1463 |
B<Example:> |
|
packaging one directory
|
1464 | |
removed reconnect method
|
1465 |
$dbi->register_filter( |
1466 |
encode_utf8 => sub { |
|
1467 |
my $value = shift; |
|
1468 |
|
|
1469 |
require Encode; |
|
1470 |
|
|
1471 |
return Encode::encode('UTF-8', $value); |
|
1472 |
}, |
|
1473 |
decode_utf8 => sub { |
|
1474 |
my $value = shift; |
|
1475 |
|
|
1476 |
require Encode; |
|
1477 |
|
|
1478 |
return Encode::decode('UTF-8', $value) |
|
1479 |
} |
|
1480 |
); |
|
1481 | ||
DBIx::Custom is now stable
|
1482 |
=head1 STABILITY |
1483 | ||
1484 |
L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature. |
|
1485 | ||
removed DESTROY method(not b...
|
1486 |
=head1 BUGS |
1487 | ||
renamed build_query to creat...
|
1488 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
1489 | |
1490 |
C<< <kimoto.yuki at gmail.com> >> |
|
1491 | ||
1492 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1493 | ||
removed reconnect method
|
1494 |
=head1 AUTHOR |
1495 | ||
1496 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
1497 | |
packaging one directory
|
1498 |
=head1 COPYRIGHT & LICENSE |
1499 | ||
1500 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
1501 | ||
1502 |
This program is free software; you can redistribute it and/or modify it |
|
1503 |
under the same terms as Perl itself. |
|
1504 | ||
1505 |
=cut |
|
added cache_method attribute
|
1506 | |
1507 |