cleanup
|
1 |
package DBIx::Custom; |
2 | ||
remove experimental DBIx::Cu...
|
3 |
our $VERSION = '0.1655'; |
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; |
added experimental DBIx::Cus...
|
16 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
17 |
use DBIx::Custom::Model; |
cleanup
|
18 |
use DBIx::Custom::Tag; |
all filter can receive array...
|
19 |
use DBIx::Custom::Util; |
update document
|
20 |
use Encode qw/encode_utf8 decode_utf8/; |
packaging one directory
|
21 | |
fix tests
|
22 |
__PACKAGE__->attr( |
added experimental DBIx::Cus...
|
23 |
[qw/data_source dbh password user/], |
fix tests
|
24 |
cache => 1, |
add default_dbi_option()
|
25 |
dbi_option => sub { {} }, |
26 |
default_dbi_option => sub {{ |
|
27 |
RaiseError => 1, |
|
28 |
PrintError => 0, |
|
29 |
AutoCommit => 1 |
|
30 |
}}, |
|
add models() attribute
|
31 |
models => sub { {} }, |
cleanup
|
32 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
many changed
|
33 |
result_class => 'DBIx::Custom::Result', |
update pod
|
34 |
safety_column_name => sub { qr/^[\w\.]*$/ }, |
35 |
stash => sub { {} } |
|
many changed
|
36 |
); |
37 | ||
38 |
__PACKAGE__->attr( |
|
39 |
cache_method => sub { |
|
40 |
sub { |
|
41 |
my $self = shift; |
|
42 |
|
|
43 |
$self->{_cached} ||= {}; |
|
44 |
|
|
45 |
if (@_ > 1) { |
|
46 |
$self->{_cached}{$_[0]} = $_[1] |
|
47 |
} |
|
48 |
else { |
|
49 |
return $self->{_cached}{$_[0]} |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
); |
|
54 | ||
55 |
__PACKAGE__->attr( |
|
fix tests
|
56 |
filters => sub { |
57 |
{ |
|
58 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
59 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
60 |
} |
|
many changed
|
61 |
} |
fix tests
|
62 |
); |
cleanup
|
63 | |
added helper method
|
64 |
our $AUTOLOAD; |
65 |
sub AUTOLOAD { |
|
66 |
my $self = shift; |
|
67 | ||
renamed helper to method.
|
68 |
# Method name |
69 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
70 | |
renamed helper to method.
|
71 |
# Method |
72 |
$self->{_methods} ||= {}; |
|
add feture. all model class ...
|
73 |
if (my $method = $self->{_methods}->{$mname}) { |
74 |
return $self->$method(@_) |
|
75 |
} |
|
76 |
elsif ($self->dbh->can($mname)) { |
|
77 |
$self->dbh->$mname(@_); |
|
78 |
} |
|
79 |
else { |
|
80 |
croak qq/Can't locate object method "$mname" via "$package"/ |
|
81 |
} |
|
added helper method
|
82 |
} |
83 | ||
renamed auto_filter to apply...
|
84 |
sub apply_filter { |
many changed
|
85 |
my ($self, $table, @cinfos) = @_; |
86 | ||
87 |
# Initialize filters |
|
cleanup
|
88 |
$self->{filter} ||= {}; |
many changed
|
89 |
$self->{filter}{out} ||= {}; |
90 |
$self->{filter}{in} ||= {}; |
|
all filter can receive array...
|
91 |
$self->{filter}{end} ||= {}; |
cleanup
|
92 |
|
many changed
|
93 |
# Create filters |
94 |
my $usage = "Usage: \$dbi->apply_filter(" . |
|
fix bug : filter can't over...
|
95 |
"TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " . |
96 |
"COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)"; |
|
many changed
|
97 | |
98 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
|
added auto_filter method
|
99 |
|
many changed
|
100 |
# Column |
101 |
my $column = $cinfos[$i]; |
|
added auto_filter method
|
102 |
|
all filter can receive array...
|
103 |
if (ref $column eq 'ARRAY') { |
104 |
foreach my $c (@$column) { |
|
105 |
push @cinfos, $c, $cinfos[$i + 1]; |
|
106 |
} |
|
107 |
next; |
|
108 |
} |
|
109 |
|
|
fix bug : filter can't over...
|
110 |
# Filter info |
111 |
my $finfo = $cinfos[$i + 1] || {}; |
|
all filter can receive array...
|
112 |
croak "$usage (table: $table)" unless ref $finfo eq 'HASH'; |
fix bug : filter can't over...
|
113 |
foreach my $ftype (keys %$finfo) { |
all filter can receive array...
|
114 |
croak "$usage (table: $table 2)" unless $ftype eq 'in' || $ftype eq 'out' |
fix bug : filter can't over...
|
115 |
|| $ftype eq 'end'; |
many changed
|
116 |
} |
117 |
|
|
fix bug : filter can't over...
|
118 |
foreach my $way (qw/in out end/) { |
119 |
my $filter = $finfo->{$way}; |
|
cleanup
|
120 |
|
fix bug : filter can't over...
|
121 |
# State |
122 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
|
123 |
: !defined $filter ? 'not_defined' |
|
124 |
: ref $filter eq 'CODE' ? 'code' |
|
125 |
: 'name'; |
|
126 |
|
|
127 |
next if $state eq 'not_exists'; |
|
128 |
|
|
129 |
# Check filter |
|
130 |
croak qq{Filter "$filter" is not registered} |
|
131 |
if $state eq 'name' |
|
132 |
&& ! exists $self->filters->{$filter}; |
|
133 |
|
|
134 |
# Filter |
|
135 |
my $f = $state eq 'not_defined' ? undef |
|
136 |
: $state eq 'code' ? $filter |
|
137 |
: $self->filters->{$filter}; |
|
138 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
139 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
140 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
many changed
|
141 |
} |
added auto_filter method
|
142 |
} |
143 |
|
|
many changed
|
144 |
return $self; |
added auto_filter method
|
145 |
} |
146 | ||
renamed helper to method.
|
147 |
sub method { |
added helper method
|
148 |
my $self = shift; |
149 |
|
|
150 |
# Merge |
|
renamed helper to method.
|
151 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
152 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
added helper method
|
153 |
|
154 |
return $self; |
|
155 |
} |
|
156 | ||
packaging one directory
|
157 |
sub connect { |
cleanup
|
158 |
my $self = ref $_[0] ? shift : shift->new(@_);; |
removed register_format()
|
159 |
|
many changed
|
160 |
# Attributes |
packaging one directory
|
161 |
my $data_source = $self->data_source; |
many changed
|
162 |
croak qq{"data_source" must be specified to connect()"} |
check arguments of connect m...
|
163 |
unless $data_source; |
packaging one directory
|
164 |
my $user = $self->user; |
165 |
my $password = $self->password; |
|
renamed dbi_options to dbi_o...
|
166 |
my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}}; |
added dbi_options attribute
|
167 |
|
update document
|
168 |
# Connect |
select, insert, update, upda...
|
169 |
my $dbh = eval {DBI->connect( |
packaging one directory
|
170 |
$data_source, |
171 |
$user, |
|
172 |
$password, |
|
173 |
{ |
|
add default_dbi_option()
|
174 |
%{$self->default_dbi_option}, |
renamed dbi_options to dbi_o...
|
175 |
%$dbi_option |
packaging one directory
|
176 |
} |
177 |
)}; |
|
178 |
|
|
update document
|
179 |
# Connect error |
packaging one directory
|
180 |
croak $@ if $@; |
181 |
|
|
update document
|
182 |
# Database handle |
packaging one directory
|
183 |
$self->dbh($dbh); |
update document
|
184 |
|
packaging one directory
|
185 |
return $self; |
186 |
} |
|
187 | ||
cleanup
|
188 |
sub create_query { |
189 |
my ($self, $source) = @_; |
|
update document
|
190 |
|
cleanup
|
191 |
# Cache |
192 |
my $cache = $self->cache; |
|
update document
|
193 |
|
cleanup
|
194 |
# Create query |
195 |
my $query; |
|
196 |
if ($cache) { |
|
197 |
|
|
198 |
# Get query |
|
199 |
my $q = $self->cache_method->($self, $source); |
|
200 |
|
|
201 |
# Create query |
|
add table tag
|
202 |
if ($q) { |
203 |
$query = DBIx::Custom::Query->new($q); |
|
204 |
$query->filters($self->filters); |
|
205 |
} |
|
cleanup
|
206 |
} |
207 |
|
|
208 |
unless ($query) { |
|
cleanup insert
|
209 | |
cleanup
|
210 |
# Create SQL object |
211 |
my $builder = $self->query_builder; |
|
212 |
|
|
213 |
# Create query |
|
214 |
$query = $builder->build_query($source); |
|
removed register_format()
|
215 | |
cleanup
|
216 |
# Cache query |
217 |
$self->cache_method->($self, $source, |
|
218 |
{sql => $query->sql, |
|
add table tag
|
219 |
columns => $query->columns, |
220 |
tables => $query->tables}) |
|
cleanup
|
221 |
if $cache; |
cleanup insert
|
222 |
} |
223 |
|
|
cleanup
|
224 |
# Prepare statement handle |
225 |
my $sth; |
|
226 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
renamed DBIx::Custom::TagPro...
|
227 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
packaging one directory
|
228 |
|
cleanup
|
229 |
# Set statement handle |
230 |
$query->sth($sth); |
|
packaging one directory
|
231 |
|
cleanup
|
232 |
# Set filters |
233 |
$query->filters($self->filters); |
|
234 |
|
|
cleanup
|
235 |
return $query; |
packaging one directory
|
236 |
} |
237 | ||
cleanup
|
238 |
our %VALID_DELETE_ARGS |
added experimental sugar met...
|
239 |
= map { $_ => 1 } qw/table where append filter allow_delete_all query/; |
cleanup update and update_al...
|
240 | |
cleanup
|
241 |
sub delete { |
select, insert, update, upda...
|
242 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
243 |
|
244 |
# Check arguments |
|
select, insert, update, upda...
|
245 |
foreach my $name (keys %args) { |
add tests
|
246 |
croak qq{"$name" is invalid argument} |
cleanup
|
247 |
unless $VALID_DELETE_ARGS{$name}; |
cleanup update and update_al...
|
248 |
} |
249 |
|
|
250 |
# Arguments |
|
select, insert, update, upda...
|
251 |
my $table = $args{table} || ''; |
added table not specified ex...
|
252 |
croak qq{"table" option must be specified} unless $table; |
select, insert, update, upda...
|
253 |
my $where = $args{where} || {}; |
select() where can't receive...
|
254 |
my $append = $args{append}; |
select, insert, update, upda...
|
255 |
my $filter = $args{filter}; |
cleanup
|
256 |
my $allow_delete_all = $args{allow_delete_all}; |
added auto_filter method
|
257 | |
make delete() using where ob...
|
258 |
# Where |
259 |
my $w; |
|
260 |
if (ref $where eq 'HASH') { |
|
261 |
my $clause = ['and']; |
|
262 |
push @$clause, "{= $_}" for keys %$where; |
|
263 |
$w = $self->where; |
|
264 |
$w->clause($clause); |
|
improved delete() and update...
|
265 |
$w->param($where); |
packaging one directory
|
266 |
} |
select() where can't receive...
|
267 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
268 |
$w = $where; |
|
269 |
$where = $w->param; |
|
270 |
} |
|
make delete() using where ob...
|
271 |
croak qq{"where" must be hash refernce or DBIx::Custom::Where object} |
272 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
273 |
|
|
select() where can't receive...
|
274 |
# String where |
275 |
my $swhere = "$w"; |
|
improved delete() and update...
|
276 |
|
make delete() using where ob...
|
277 |
croak qq{"where" must be specified} |
select() where can't receive...
|
278 |
if $swhere eq '' && !$allow_delete_all; |
make delete() using where ob...
|
279 | |
cleanup
|
280 |
# SQL stack |
281 |
my @sql; |
|
282 | ||
283 |
# Delete |
|
284 |
push @sql, "delete from $table $swhere"; |
|
285 |
push @sql, $append if $append; |
|
286 |
|
|
287 |
my $sql = join(' ', @sql); |
|
packaging one directory
|
288 |
|
added experimental sugar met...
|
289 |
# Create query |
cleanup
|
290 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
291 |
return $query if $args{query}; |
292 |
|
|
packaging one directory
|
293 |
# Execute query |
added auto_filter method
|
294 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
295 |
$query, param => $where, filter => $filter, |
renamed auto_filter to apply...
|
296 |
table => $table); |
packaging one directory
|
297 |
|
298 |
return $ret_val; |
|
299 |
} |
|
300 | ||
cleanup
|
301 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
302 | |
add experimental update_at()...
|
303 |
our %VALID_DELETE_AT_ARGS |
304 |
= map { $_ => 1 } qw/table where append filter query |
|
305 |
primary_key param/; |
|
306 | ||
307 |
sub delete_at { |
|
308 |
my ($self, %args) = @_; |
|
309 |
|
|
310 |
# Check arguments |
|
311 |
foreach my $name (keys %args) { |
|
312 |
croak qq{"$name" is invalid argument} |
|
313 |
unless $VALID_DELETE_AT_ARGS{$name}; |
|
314 |
} |
|
315 |
|
|
316 |
# Primary key |
|
317 |
my $primary_keys = delete $args{primary_key}; |
|
318 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
319 |
|
|
320 |
# Where clause |
|
321 |
my $where = {}; |
|
322 |
if (exists $args{where}) { |
|
323 |
my $where_columns = delete $args{where}; |
|
324 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
- added experimental DBIx::C...
|
325 | |
326 |
croak qq{"where" must be constant value or array reference} |
|
327 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
add experimental update_at()...
|
328 |
|
329 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
330 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
331 |
} |
|
332 |
} |
|
- added experimental DBIx::C...
|
333 |
|
334 |
if (exists $args{param}) { |
|
add experimental update_at()...
|
335 |
my $param = delete $args{param}; |
336 |
|
|
337 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
- added experimental DBIx::C...
|
338 |
delete $param->{$primary_keys->[$i]}; |
add experimental update_at()...
|
339 |
} |
340 |
} |
|
341 |
|
|
342 |
return $self->delete(where => $where, %args); |
|
343 |
} |
|
344 | ||
added helper method
|
345 |
sub DESTROY { } |
346 | ||
renamed auto_filter to apply...
|
347 |
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter table/; |
refactoring delete and delet...
|
348 | |
cleanup
|
349 |
sub execute{ |
350 |
my ($self, $query, %args) = @_; |
|
refactoring delete and delet...
|
351 |
|
352 |
# Check arguments |
|
select, insert, update, upda...
|
353 |
foreach my $name (keys %args) { |
add tests
|
354 |
croak qq{"$name" is invalid argument} |
cleanup
|
355 |
unless $VALID_EXECUTE_ARGS{$name}; |
refactoring delete and delet...
|
356 |
} |
357 |
|
|
cleanup
|
358 |
my $params = $args{param} || {}; |
packaging one directory
|
359 |
|
cleanup
|
360 |
# First argument is the soruce of SQL |
361 |
$query = $self->create_query($query) |
|
362 |
unless ref $query; |
|
packaging one directory
|
363 |
|
add table tag
|
364 |
# Applied filter |
cleanup
|
365 |
my $filter = {}; |
all filter can receive array...
|
366 |
|
add table tag
|
367 |
my $tables = $query->tables; |
368 |
my $arg_tables = $args{table} || []; |
|
369 |
$arg_tables = [$arg_tables] |
|
370 |
unless ref $arg_tables eq 'ARRAY'; |
|
371 |
push @$tables, @$arg_tables; |
|
remove experimental DBIx::Cu...
|
372 |
|
renamed auto_filter to apply...
|
373 |
foreach my $table (@$tables) { |
remove experimental DBIx::Cu...
|
374 |
next unless $table; |
cleanup
|
375 |
$filter = { |
376 |
%$filter, |
|
377 |
%{$self->{filter}{out}->{$table} || {}} |
|
added auto_filter method
|
378 |
} |
379 |
} |
|
380 |
|
|
cleanup
|
381 |
# Filter argument |
all filter can receive array...
|
382 |
my $f = DBIx::Custom::Util::array_filter_to_hash($args{filter}) |
383 |
|| $query->filter || {}; |
|
cleanup
|
384 |
foreach my $column (keys %$f) { |
385 |
my $fname = $f->{$column}; |
|
renamed auto_filter to apply...
|
386 |
if (!defined $fname) { |
cleanup
|
387 |
$f->{$column} = undef; |
renamed auto_filter to apply...
|
388 |
} |
389 |
elsif (ref $fname ne 'CODE') { |
|
many changed
|
390 |
croak qq{Filter "$fname" is not registered"} |
cleanup
|
391 |
unless exists $self->filters->{$fname}; |
392 |
|
|
cleanup
|
393 |
$f->{$column} = $self->filters->{$fname}; |
cleanup
|
394 |
} |
395 |
} |
|
cleanup
|
396 |
$filter = {%$filter, %$f}; |
packaging one directory
|
397 |
|
added experimental not_exist...
|
398 |
# Bind |
399 |
my $bind = $self->_bind($params, $query->columns, $filter); |
|
cleanup
|
400 |
|
401 |
# Execute |
|
added experimental not_exist...
|
402 |
my $sth = $query->sth; |
cleanup
|
403 |
my $affected; |
added experimental not_exist...
|
404 |
eval {$affected = $sth->execute(@$bind)}; |
renamed DBIx::Custom::TagPro...
|
405 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
cleanup
|
406 |
|
407 |
# Return resultset if select statement is executed |
|
408 |
if ($sth->{NUM_OF_FIELDS}) { |
|
409 |
|
|
fix bug : filter can't over...
|
410 |
# Result in and end filter |
411 |
my $in_filter = {}; |
|
412 |
my $end_filter = {}; |
|
cleanup
|
413 |
foreach my $table (@$tables) { |
remove experimental DBIx::Cu...
|
414 |
next unless $table; |
cleanup
|
415 |
$in_filter = { |
416 |
%$in_filter, |
|
417 |
%{$self->{filter}{in}{$table} || {}} |
|
fix bug : filter can't over...
|
418 |
}; |
419 |
$end_filter = { |
|
420 |
%$end_filter, |
|
421 |
%{$self->{filter}{end}{$table} || {}} |
|
422 |
}; |
|
cleanup
|
423 |
} |
424 |
|
|
425 |
# Result |
|
426 |
my $result = $self->result_class->new( |
|
cleanup
|
427 |
sth => $sth, |
428 |
filters => $self->filters, |
|
429 |
filter_check => $self->filter_check, |
|
cleanup
|
430 |
default_filter => $self->{default_in_filter}, |
fix bug : filter can't over...
|
431 |
filter => $in_filter || {}, |
432 |
end_filter => $end_filter || {} |
|
cleanup
|
433 |
); |
434 | ||
435 |
return $result; |
|
436 |
} |
|
437 |
return $affected; |
|
438 |
} |
|
439 | ||
added auto_filter method
|
440 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append |
added experimental sugar met...
|
441 |
filter query/; |
cleanup
|
442 |
sub insert { |
443 |
my ($self, %args) = @_; |
|
444 | ||
445 |
# Check arguments |
|
446 |
foreach my $name (keys %args) { |
|
447 |
croak qq{"$name" is invalid argument} |
|
448 |
unless $VALID_INSERT_ARGS{$name}; |
|
packaging one directory
|
449 |
} |
450 |
|
|
cleanup
|
451 |
# Arguments |
added table not specified ex...
|
452 |
my $table = $args{table}; |
453 |
croak qq{"table" option must be specified} unless $table; |
|
cleanup
|
454 |
my $param = $args{param} || {}; |
455 |
my $append = $args{append} || ''; |
|
456 |
my $filter = $args{filter}; |
|
457 |
|
|
select() where can't receive...
|
458 |
# Columns |
459 |
my @columns; |
|
460 |
my $safety = $self->safety_column_name; |
|
461 |
foreach my $column (keys %$param) { |
|
462 |
croak qq{"$column" is not safety column name} |
|
463 |
unless $column =~ /$safety/; |
|
464 |
push @columns, $column; |
|
465 |
} |
|
cleanup
|
466 |
|
cleanup
|
467 |
# SQL stack |
468 |
my @sql; |
|
469 |
|
|
470 |
# Insert |
|
471 |
push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}'; |
|
472 |
push @sql, $append if $append; |
|
473 |
|
|
select() where can't receive...
|
474 |
# SQL |
cleanup
|
475 |
my $sql = join (' ', @sql); |
packaging one directory
|
476 |
|
added experimental sugar met...
|
477 |
# Create query |
cleanup
|
478 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
479 |
return $query if $args{query}; |
480 |
|
|
packaging one directory
|
481 |
# Execute query |
added auto_filter method
|
482 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
483 |
$query, |
added auto_filter method
|
484 |
param => $param, |
485 |
filter => $filter, |
|
renamed auto_filter to apply...
|
486 |
table => $table |
added auto_filter method
|
487 |
); |
packaging one directory
|
488 |
|
489 |
return $ret_val; |
|
490 |
} |
|
491 | ||
- added experimental DBIx::C...
|
492 |
our %VALID_INSERT_AT_ARGS |
493 |
= map { $_ => 1 } qw/table param |
|
494 |
where append filter query |
|
495 |
primary_key param/; |
|
496 | ||
497 |
sub insert_at { |
|
498 |
my ($self, %args) = @_; |
|
499 |
|
|
500 |
# Check arguments |
|
501 |
foreach my $name (keys %args) { |
|
502 |
croak qq{"$name" is invalid argument} |
|
503 |
unless $VALID_INSERT_AT_ARGS{$name}; |
|
504 |
} |
|
505 |
|
|
506 |
# Primary key |
|
507 |
my $primary_keys = delete $args{primary_key}; |
|
508 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
509 |
|
|
510 |
# Where clause |
|
511 |
my $where = {}; |
|
512 |
my $param = {}; |
|
513 |
|
|
514 |
if (exists $args{where}) { |
|
515 |
my $where_columns = delete $args{where}; |
|
516 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
517 | ||
518 |
croak qq{"where" must be constant value or array reference} |
|
519 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
520 |
|
|
521 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
522 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
523 |
} |
|
524 |
} |
|
525 |
|
|
526 |
if (exists $args{param}) { |
|
527 |
$param = delete $args{param}; |
|
528 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
529 |
delete $param->{$primary_keys->[$i]}; |
|
530 |
} |
|
531 |
} |
|
532 |
|
|
533 |
$param = {%$param, %$where}; |
|
534 |
|
|
535 |
return $self->insert(param => $param, %args); |
|
536 |
} |
|
537 | ||
remove experimental DBIx::Cu...
|
538 |
sub insert_param { |
539 |
my ($self, $param) = @_; |
|
540 |
|
|
added experimental update_pa...
|
541 |
# Insert paramter tag |
remove experimental DBIx::Cu...
|
542 |
my @tag; |
543 |
push @tag, '{insert_param'; |
|
added experimental update_pa...
|
544 |
my $safety = $self->safety_column_name; |
remove experimental DBIx::Cu...
|
545 |
foreach my $column (keys %$param) { |
added experimental update_pa...
|
546 |
croak qq{"$column" is not safety column name} |
547 |
unless $column =~ /$safety/; |
|
remove experimental DBIx::Cu...
|
548 |
push @tag, $column; |
549 |
} |
|
550 |
push @tag, '}'; |
|
551 |
|
|
552 |
return join ' ', @tag; |
|
553 |
} |
|
554 | ||
pod fix
|
555 |
sub each_column { |
added experimental iterate_a...
|
556 |
my ($self, $cb) = @_; |
557 |
|
|
558 |
# Iterate all tables |
|
559 |
my $sth_tables = $self->dbh->table_info; |
|
560 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
561 |
|
|
562 |
# Table |
|
563 |
my $table = $table_info->{TABLE_NAME}; |
|
564 |
|
|
565 |
# Iterate all columns |
|
566 |
my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%'); |
|
567 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
568 |
my $column = $column_info->{COLUMN_NAME}; |
|
removed experimental txn_sco...
|
569 |
$self->$cb($table, $column, $column_info); |
added experimental iterate_a...
|
570 |
} |
571 |
} |
|
572 |
} |
|
573 | ||
added dbi_options attribute
|
574 |
sub new { |
575 |
my $self = shift->SUPER::new(@_); |
|
576 |
|
|
577 |
# Check attribute names |
|
578 |
my @attrs = keys %$self; |
|
579 |
foreach my $attr (@attrs) { |
|
580 |
croak qq{"$attr" is invalid attribute name} |
|
581 |
unless $self->can($attr); |
|
582 |
} |
|
cleanup
|
583 | |
584 |
$self->register_tag( |
|
585 |
'?' => \&DBIx::Custom::Tag::placeholder, |
|
586 |
'=' => \&DBIx::Custom::Tag::equal, |
|
587 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
588 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
589 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
590 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
591 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
592 |
'like' => \&DBIx::Custom::Tag::like, |
|
593 |
'in' => \&DBIx::Custom::Tag::in, |
|
594 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
595 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
596 |
); |
|
added dbi_options attribute
|
597 |
|
598 |
return $self; |
|
599 |
} |
|
600 | ||
added experimental not_exist...
|
601 |
sub not_exists { bless {}, 'DBIx::Custom::NotExists' } |
602 | ||
cleanup
|
603 |
sub register_filter { |
604 |
my $invocant = shift; |
|
605 |
|
|
606 |
# Register filter |
|
607 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
608 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
609 |
|
|
610 |
return $invocant; |
|
611 |
} |
|
packaging one directory
|
612 | |
renamed DBIx::Custom::TagPro...
|
613 |
sub register_tag { shift->query_builder->register_tag(@_) } |
added register_tag_processor
|
614 | |
refactoring select
|
615 |
our %VALID_SELECT_ARGS |
- added experimental DBIx::C...
|
616 |
= map { $_ => 1 } qw/table column where append relation filter query selection join/; |
617 | ||
618 |
sub _need_tables { |
|
619 |
my ($self, $tree, $need_tables, $tables) = @_; |
|
620 |
|
|
621 |
foreach my $table (@$tables) { |
|
622 |
|
|
623 |
if ($tree->{$table}) { |
|
624 |
$need_tables->{$table} = 1; |
|
625 |
$self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}]) |
|
626 |
} |
|
627 |
} |
|
628 |
} |
|
refactoring select
|
629 | |
packaging one directory
|
630 |
sub select { |
select, insert, update, upda...
|
631 |
my ($self, %args) = @_; |
packaging one directory
|
632 |
|
refactoring select
|
633 |
# Check arguments |
select, insert, update, upda...
|
634 |
foreach my $name (keys %args) { |
add tests
|
635 |
croak qq{"$name" is invalid argument} |
refactoring select
|
636 |
unless $VALID_SELECT_ARGS{$name}; |
637 |
} |
|
packaging one directory
|
638 |
|
refactoring select
|
639 |
# Arguments |
added table not specified ex...
|
640 |
my $table = $args{table}; |
641 |
my $tables = ref $table eq 'ARRAY' ? $table |
|
642 |
: defined $table ? [$table] |
|
643 |
: []; |
|
add experimental selection o...
|
644 |
my $columns = $args{column} || []; |
select method column option ...
|
645 |
$columns = [$columns] unless ref $columns; |
add experimental selection o...
|
646 |
my $selection = $args{selection} || ''; |
647 |
my $where = $args{where} || {}; |
|
648 |
my $append = $args{append}; |
|
649 |
my $filter = $args{filter}; |
|
- added experimental DBIx::C...
|
650 |
my $join = $args{join} || []; |
651 |
croak qq{"join" must be array reference} |
|
652 |
unless ref $join eq 'ARRAY'; |
|
remove experimental DBIx::Cu...
|
653 |
|
cleanup
|
654 |
my @join_tables; |
655 |
unshift @join_tables, $tables->[-1]; |
|
remove experimental DBIx::Cu...
|
656 |
|
cleanup
|
657 |
# Relation table(DEPRECATED!); |
658 |
$self->_add_relation_table($args{relation}, $tables); |
|
packaging one directory
|
659 |
|
cleanup
|
660 |
# SQL stack |
661 |
my @sql; |
|
662 |
|
|
663 |
push @sql, 'select'; |
|
packaging one directory
|
664 |
|
add experimental selection o...
|
665 |
if ($selection) { |
666 |
push @sql, $selection; |
|
cleanup
|
667 |
push @join_tables, @{$self->_tables($selection)}; |
add experimental selection o...
|
668 |
} |
669 |
else { |
|
670 |
# Column clause |
|
671 |
if (@$columns) { |
|
672 |
foreach my $column (@$columns) { |
|
cleanup
|
673 |
push @join_tables, @{$self->_tables($column)}; |
add experimental selection o...
|
674 |
push @sql, ($column, ','); |
675 |
} |
|
676 |
pop @sql if $sql[-1] eq ','; |
|
677 |
} |
|
678 |
else { push @sql, '*' } |
|
679 |
|
|
680 |
# Table |
|
681 |
croak qq{"table" option must be specified} unless @$tables; |
|
682 |
push @sql, 'from'; |
|
683 |
foreach my $table (@$tables) { |
|
684 |
push @sql, ($table, ','); |
|
packaging one directory
|
685 |
} |
cleanup
|
686 |
pop @sql if $sql[-1] eq ','; |
packaging one directory
|
687 |
} |
688 |
|
|
select() where can't receive...
|
689 |
# Where |
690 |
my $w; |
|
added experimental DBIx::Cus...
|
691 |
if (ref $where eq 'HASH') { |
select() where can't receive...
|
692 |
my $clause = ['and']; |
693 |
push @$clause, "{= $_}" for keys %$where; |
|
694 |
$w = $self->where; |
|
695 |
$w->clause($clause); |
|
696 |
$w->param($where); |
|
added experimental DBIx::Cus...
|
697 |
} |
698 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
|
select() where can't receive...
|
699 |
$w = $where; |
700 |
$where = $w->param; |
|
packaging one directory
|
701 |
} |
702 |
|
|
select() where can't receive...
|
703 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} |
704 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
705 |
|
|
706 |
# String where |
|
707 |
my $swhere = "$w"; |
|
remove experimental DBIx::Cu...
|
708 |
|
709 |
# Table name in Where |
|
cleanup
|
710 |
unshift @join_tables, @{$self->_tables($swhere)}; |
remove experimental DBIx::Cu...
|
711 |
|
- added experimental DBIx::C...
|
712 |
# Join |
713 |
if (@$join) { |
|
714 |
my $tree = {}; |
|
715 |
|
|
716 |
for (my $i = 0; $i < @$join; $i++) { |
|
remove experimental DBIx::Cu...
|
717 |
|
- added experimental DBIx::C...
|
718 |
my $join_clause = $join->[$i]; |
remove experimental DBIx::Cu...
|
719 |
|
- added experimental DBIx::C...
|
720 |
if ($join_clause =~ /\s([^\.\s]+?)\..+\s([^\.\s]+?)\./) { |
721 |
|
|
722 |
my $table1 = $1; |
|
723 |
my $table2 = $2; |
|
724 |
|
|
725 |
croak qq{right side table of "$join_clause" must be uniq} |
|
726 |
if exists $tree->{$table2}; |
|
727 |
|
|
728 |
$tree->{$table2} |
|
729 |
= {position => $i, parent => $table1, join => $join_clause}; |
|
remove experimental DBIx::Cu...
|
730 |
} |
- added experimental DBIx::C...
|
731 |
else { |
732 |
croak qq{join "$join_clause" must be two table name}; |
|
remove experimental DBIx::Cu...
|
733 |
} |
734 |
} |
|
- added experimental DBIx::C...
|
735 |
|
736 |
my $need_tables = {}; |
|
737 |
$self->_need_tables($tree, $need_tables, \@join_tables); |
|
738 |
|
|
739 |
|
|
740 |
my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables; |
|
741 | ||
742 |
foreach my $need_table (@need_tables) { |
|
743 |
push @sql, $tree->{$need_table}{join}; |
|
744 |
} |
|
remove experimental DBIx::Cu...
|
745 |
} |
746 |
|
|
747 |
# Add where |
|
cleanup
|
748 |
push @sql, $swhere; |
select() where can't receive...
|
749 |
|
cleanup
|
750 |
# Relation(DEPRECATED!); |
751 |
$self->_push_relation(\@sql, $tables, $args{relation}, $swhere eq '' ? 1 : 0); |
|
752 |
|
|
cleanup
|
753 |
# Append statement |
754 |
push @sql, $append if $append; |
|
755 |
|
|
756 |
# SQL |
|
757 |
my $sql = join (' ', @sql); |
|
packaging one directory
|
758 |
|
added experimental sugar met...
|
759 |
# Create query |
cleanup
|
760 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
761 |
return $query if $args{query}; |
762 |
|
|
cleanup
|
763 |
unshift @$tables, @join_tables; |
remove experimental DBIx::Cu...
|
764 |
|
packaging one directory
|
765 |
# Execute query |
added auto_filter method
|
766 |
my $result = $self->execute( |
select() where can't receive...
|
767 |
$query, param => $where, filter => $filter, |
768 |
table => $tables); |
|
packaging one directory
|
769 |
|
770 |
return $result; |
|
771 |
} |
|
772 | ||
add experimental update_at()...
|
773 |
our %VALID_SELECT_AT_ARGS |
774 |
= map { $_ => 1 } qw/table column where append relation filter query selection |
|
remove experimental DBIx::Cu...
|
775 |
param primary_key left_join/; |
add experimental update_at()...
|
776 | |
777 |
sub select_at { |
|
778 |
my ($self, %args) = @_; |
|
779 |
|
|
780 |
# Check arguments |
|
781 |
foreach my $name (keys %args) { |
|
782 |
croak qq{"$name" is invalid argument} |
|
783 |
unless $VALID_SELECT_AT_ARGS{$name}; |
|
784 |
} |
|
785 |
|
|
786 |
# Primary key |
|
787 |
my $primary_keys = delete $args{primary_key}; |
|
788 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
789 |
|
|
DBIx::Custom::Model select()...
|
790 |
# Table |
791 |
croak qq{"table" option must be specified} unless $args{table}; |
|
792 |
my $table = ref $args{table} ? $args{table}->[-1] : $args{table}; |
|
793 |
|
|
add experimental update_at()...
|
794 |
# Where clause |
795 |
my $where = {}; |
|
796 |
if (exists $args{where}) { |
|
797 |
my $where_columns = delete $args{where}; |
|
- added experimental DBIx::C...
|
798 |
|
799 |
croak qq{"where" must be constant value or array reference} |
|
800 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
801 |
|
|
add experimental update_at()...
|
802 |
$where_columns = [$where_columns] unless ref $where_columns; |
803 |
|
|
804 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
DBIx::Custom::Model select()...
|
805 |
$where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i]; |
add experimental update_at()...
|
806 |
} |
807 |
} |
|
- added experimental DBIx::C...
|
808 |
|
809 |
if (exists $args{param}) { |
|
add experimental update_at()...
|
810 |
my $param = delete $args{param}; |
811 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
- added experimental DBIx::C...
|
812 |
delete $param->{$primary_keys->[$i]}; |
add experimental update_at()...
|
813 |
} |
814 |
} |
|
815 |
|
|
816 |
return $self->select(where => $where, %args); |
|
817 |
} |
|
818 | ||
add feture. all model class ...
|
819 |
sub model { |
820 |
my ($self, $name, $model) = @_; |
|
removed experimental base_ta...
|
821 |
|
822 |
# Set |
|
add feture. all model class ...
|
823 |
if ($model) { |
add models() attribute
|
824 |
$self->models->{$name} = $model; |
removed experimental base_ta...
|
825 |
return $self; |
826 |
} |
|
827 |
|
|
add feture. all model class ...
|
828 |
# Check model existance |
829 |
croak qq{Model "$name" is not included} |
|
add models() attribute
|
830 |
unless $self->models->{$name}; |
removed experimental base_ta...
|
831 |
|
832 |
# Get |
|
add models() attribute
|
833 |
return $self->models->{$name}; |
removed experimental base_ta...
|
834 |
} |
835 | ||
add feture. all model class ...
|
836 |
sub include_model { |
837 |
my ($self, $name_space, $model_infos) = @_; |
|
remove DBIx::Custom::Model
|
838 |
|
add feture. all model class ...
|
839 |
$name_space ||= ''; |
840 |
unless ($model_infos) { |
|
841 |
# Load name space module |
|
842 |
croak qq{"$name_space" is invalid class name} |
|
843 |
if $name_space =~ /[^\w:]/; |
|
844 |
eval "use $name_space"; |
|
845 |
croak qq{Name space module "$name_space.pm" is needed. $@} if $@; |
|
table object call dbi object...
|
846 |
|
add feture. all model class ...
|
847 |
# Search model modules |
848 |
my $path = $INC{"$name_space.pm"}; |
|
849 |
$path =~ s/\.pm$//; |
|
850 |
opendir my $dh, $path |
|
851 |
or croak qq{Can't open directory "$path": $!}; |
|
852 |
$model_infos = []; |
|
853 |
while (my $module = readdir $dh) { |
|
854 |
push @$model_infos, $module |
|
855 |
if $module =~ s/\.pm$//; |
|
removed experimental base_ta...
|
856 |
} |
add feture. all model class ...
|
857 |
|
858 |
close $dh; |
|
859 |
} |
|
860 |
|
|
861 |
foreach my $model_info (@$model_infos) { |
|
862 |
|
|
add experimental DBIx::Custo...
|
863 |
# Model class, name, table |
add feture. all model class ...
|
864 |
my $model_class; |
add experimental DBIx::Custo...
|
865 |
my $model_name; |
866 |
my $model_table; |
|
add feture. all model class ...
|
867 |
if (ref $model_info eq 'HASH') { |
add experimental DBIx::Custo...
|
868 |
$model_class = $model_info->{class}; |
869 |
$model_name = $model_info->{name}; |
|
870 |
$model_table = $model_info->{table}; |
|
871 |
|
|
872 |
$model_name ||= $model_class; |
|
873 |
$model_table ||= $model_name; |
|
add feture. all model class ...
|
874 |
} |
add experimental DBIx::Custo...
|
875 |
else { $model_class =$model_name = $model_table = $model_info } |
add feture. all model class ...
|
876 |
my $mclass = "${name_space}::$model_class"; |
table object call dbi object...
|
877 |
|
removed experimental base_ta...
|
878 |
# Load |
add feture. all model class ...
|
879 |
croak qq{"$mclass" is invalid class name} |
880 |
if $mclass =~ /[^\w:]/; |
|
881 |
unless ($mclass->can('isa')) { |
|
882 |
eval "use $mclass"; |
|
removed experimental base_ta...
|
883 |
croak $@ if $@; |
884 |
} |
|
table object call dbi object...
|
885 |
|
removed experimental base_ta...
|
886 |
# Instantiate |
add feture. all model class ...
|
887 |
my $model = $mclass->new(dbi => $self); |
add experimental DBIx::Custo...
|
888 |
$model->name($model_name) unless $model->name; |
889 |
$model->table($model_table) unless $model->table; |
|
removed experimental DBIx::C...
|
890 |
|
removed experimental base_ta...
|
891 |
# Set |
add experimental DBIx::Custo...
|
892 |
$self->model($model->name, $model); |
add experimental DBIx::Custo...
|
893 |
|
894 |
# Apply filter |
|
all filter can receive array...
|
895 |
croak "${name_space}::$model_class filter must be array reference" |
896 |
unless ref $model->filter eq 'ARRAY'; |
|
897 |
$self->apply_filter($model->table, @{$model->filter}); |
|
table object call dbi object...
|
898 |
} |
removed experimental base_ta...
|
899 |
return $self; |
remove DBIx::Custom::Model
|
900 |
} |
901 | ||
add experimental setup_model...
|
902 |
sub setup_model { |
903 |
my $self = shift; |
|
904 |
|
|
905 |
$self->each_column( |
|
906 |
sub { |
|
907 |
my ($self, $table, $column, $column_info) = @_; |
|
908 |
|
|
909 |
if (my $model = $self->models->{$table}) { |
|
910 |
push @{$model->columns}, $column; |
|
911 |
} |
|
912 |
} |
|
913 |
); |
|
add experimental DBIx::Custo...
|
914 |
return $self; |
add experimental setup_model...
|
915 |
} |
916 | ||
cleanup
|
917 |
our %VALID_UPDATE_ARGS |
renamed auto_filter to apply...
|
918 |
= map { $_ => 1 } qw/table param |
added experimental sugar met...
|
919 |
where append filter allow_update_all query/; |
cleanup
|
920 | |
921 |
sub update { |
|
922 |
my ($self, %args) = @_; |
|
version 0.0901
|
923 |
|
cleanup
|
924 |
# Check arguments |
925 |
foreach my $name (keys %args) { |
|
926 |
croak qq{"$name" is invalid argument} |
|
927 |
unless $VALID_UPDATE_ARGS{$name}; |
|
removed reconnect method
|
928 |
} |
added cache_method attribute
|
929 |
|
cleanup
|
930 |
# Arguments |
931 |
my $table = $args{table} || ''; |
|
added table not specified ex...
|
932 |
croak qq{"table" option must be specified} unless $table; |
cleanup
|
933 |
my $param = $args{param} || {}; |
934 |
my $where = $args{where} || {}; |
|
select() where can't receive...
|
935 |
my $append = $args{append} || ''; |
cleanup
|
936 |
my $filter = $args{filter}; |
937 |
my $allow_update_all = $args{allow_update_all}; |
|
version 0.0901
|
938 |
|
cleanup
|
939 |
# Update keys |
select() where can't receive...
|
940 |
my @clumns = keys %$param; |
941 | ||
942 |
# Columns |
|
943 |
my @columns; |
|
944 |
my $safety = $self->safety_column_name; |
|
945 |
foreach my $column (keys %$param) { |
|
946 |
croak qq{"$column" is not safety column name} |
|
947 |
unless $column =~ /$safety/; |
|
948 |
push @columns, $column; |
|
949 |
} |
|
950 |
|
|
cleanup
|
951 |
# Update clause |
select() where can't receive...
|
952 |
my $update_clause = '{update_param ' . join(' ', @clumns) . '}'; |
improved delete() and update...
|
953 | |
954 |
# Where |
|
955 |
my $w; |
|
956 |
if (ref $where eq 'HASH') { |
|
957 |
my $clause = ['and']; |
|
958 |
push @$clause, "{= $_}" for keys %$where; |
|
959 |
$w = $self->where; |
|
960 |
$w->clause($clause); |
|
961 |
$w->param($where); |
|
962 |
} |
|
select() where can't receive...
|
963 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
964 |
$w = $where; |
|
965 |
$where = $w->param; |
|
966 |
} |
|
removed experimental registe...
|
967 |
|
improved delete() and update...
|
968 |
croak qq{"where" must be hash refernce or DBIx::Custom::Where object} |
969 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
removed reconnect method
|
970 |
|
select() where can't receive...
|
971 |
# String where |
972 |
my $swhere = "$w"; |
|
improved delete() and update...
|
973 |
|
974 |
croak qq{"where" must be specified} |
|
select() where can't receive...
|
975 |
if "$swhere" eq '' && !$allow_update_all; |
removed reconnect method
|
976 |
|
cleanup
|
977 |
# SQL stack |
978 |
my @sql; |
|
979 |
|
|
980 |
# Update |
|
981 |
push @sql, "update $table $update_clause $swhere"; |
|
982 |
push @sql, $append if $append; |
|
removed reconnect method
|
983 |
|
cleanup
|
984 |
# Rearrange parameters |
improved delete() and update...
|
985 |
foreach my $wkey (keys %$where) { |
removed reconnect method
|
986 |
|
cleanup
|
987 |
if (exists $param->{$wkey}) { |
988 |
$param->{$wkey} = [$param->{$wkey}] |
|
989 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
990 |
|
|
991 |
push @{$param->{$wkey}}, $where->{$wkey}; |
|
992 |
} |
|
993 |
else { |
|
994 |
$param->{$wkey} = $where->{$wkey}; |
|
995 |
} |
|
removed reconnect method
|
996 |
} |
cleanup
|
997 |
|
cleanup
|
998 |
# SQL |
999 |
my $sql = join(' ', @sql); |
|
1000 |
|
|
added experimental sugar met...
|
1001 |
# Create query |
cleanup
|
1002 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
1003 |
return $query if $args{query}; |
1004 |
|
|
cleanup
|
1005 |
# Execute query |
added experimental sugar met...
|
1006 |
my $ret_val = $self->execute($query, param => $param, |
added auto_filter method
|
1007 |
filter => $filter, |
renamed auto_filter to apply...
|
1008 |
table => $table); |
cleanup
|
1009 |
|
1010 |
return $ret_val; |
|
removed reconnect method
|
1011 |
} |
1012 | ||
cleanup
|
1013 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
1014 | ||
add experimental update_at()...
|
1015 |
our %VALID_UPDATE_AT_ARGS |
1016 |
= map { $_ => 1 } qw/table param |
|
1017 |
where append filter query |
|
1018 |
primary_key param/; |
|
1019 | ||
1020 |
sub update_at { |
|
1021 |
my ($self, %args) = @_; |
|
1022 |
|
|
1023 |
# Check arguments |
|
1024 |
foreach my $name (keys %args) { |
|
1025 |
croak qq{"$name" is invalid argument} |
|
1026 |
unless $VALID_UPDATE_AT_ARGS{$name}; |
|
1027 |
} |
|
1028 |
|
|
1029 |
# Primary key |
|
1030 |
my $primary_keys = delete $args{primary_key}; |
|
1031 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
1032 |
|
|
1033 |
# Where clause |
|
1034 |
my $where = {}; |
|
1035 |
my $param = {}; |
|
1036 |
|
|
1037 |
if (exists $args{where}) { |
|
1038 |
my $where_columns = delete $args{where}; |
|
1039 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
- added experimental DBIx::C...
|
1040 | |
1041 |
croak qq{"where" must be constant value or array reference} |
|
1042 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
add experimental update_at()...
|
1043 |
|
1044 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
1045 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
1046 |
} |
|
1047 |
} |
|
- added experimental DBIx::C...
|
1048 |
|
1049 |
if (exists $args{param}) { |
|
add experimental update_at()...
|
1050 |
$param = delete $args{param}; |
1051 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
- added experimental DBIx::C...
|
1052 |
delete $param->{$primary_keys->[$i]}; |
add experimental update_at()...
|
1053 |
} |
1054 |
} |
|
1055 |
|
|
1056 |
return $self->update(where => $where, param => $param, %args); |
|
1057 |
} |
|
1058 | ||
remove experimental DBIx::Cu...
|
1059 |
sub update_param { |
1060 |
my ($self, $param) = @_; |
|
1061 |
|
|
added experimental update_pa...
|
1062 |
# Update parameter tag |
remove experimental DBIx::Cu...
|
1063 |
my @tag; |
1064 |
push @tag, '{update_param'; |
|
added experimental update_pa...
|
1065 |
my $safety = $self->safety_column_name; |
remove experimental DBIx::Cu...
|
1066 |
foreach my $column (keys %$param) { |
added experimental update_pa...
|
1067 |
croak qq{"$column" is not safety column name} |
1068 |
unless $column =~ /$safety/; |
|
remove experimental DBIx::Cu...
|
1069 |
push @tag, $column; |
1070 |
} |
|
1071 |
push @tag, '}'; |
|
1072 |
|
|
1073 |
return join ' ', @tag; |
|
1074 |
} |
|
1075 | ||
cleanup
|
1076 |
sub where { |
select() where can't receive...
|
1077 |
my $self = shift; |
1078 | ||
1079 |
return DBIx::Custom::Where->new( |
|
1080 |
query_builder => $self->query_builder, |
|
1081 |
safety_column_name => $self->safety_column_name |
|
1082 |
); |
|
cleanup
|
1083 |
} |
added experimental DBIx::Cus...
|
1084 | |
added experimental not_exist...
|
1085 |
sub _bind { |
cleanup
|
1086 |
my ($self, $params, $columns, $filter) = @_; |
removed reconnect method
|
1087 |
|
cleanup
|
1088 |
# bind values |
added experimental not_exist...
|
1089 |
my @bind; |
add tests
|
1090 |
|
removed reconnect method
|
1091 |
# Build bind values |
1092 |
my $count = {}; |
|
added experimental not_exist...
|
1093 |
my $not_exists = {}; |
cleanup
|
1094 |
foreach my $column (@$columns) { |
removed reconnect method
|
1095 |
|
1096 |
# Value |
|
added experimental not_exist...
|
1097 |
my $value; |
1098 |
if(ref $params->{$column} eq 'ARRAY') { |
|
1099 |
my $i = $count->{$column} || 0; |
|
1100 |
$i += $not_exists->{$column} || 0; |
|
1101 |
my $found; |
|
1102 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
1103 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
1104 |
$not_exists->{$column}++; |
|
1105 |
} |
|
1106 |
else { |
|
1107 |
$value = $params->{$column}->[$k]; |
|
1108 |
$found = 1; |
|
1109 |
last |
|
1110 |
} |
|
1111 |
} |
|
1112 |
next unless $found; |
|
1113 |
} |
|
1114 |
else { $value = $params->{$column} } |
|
removed reconnect method
|
1115 |
|
cleanup
|
1116 |
# Filter |
1117 |
my $f = $filter->{$column} || $self->{default_out_filter} || ''; |
|
cleanup
|
1118 |
|
added experimental not_exist...
|
1119 |
push @bind, $f ? $f->($value) : $value; |
removed reconnect method
|
1120 |
|
1121 |
# Count up |
|
1122 |
$count->{$column}++; |
|
1123 |
} |
|
1124 |
|
|
added experimental not_exist...
|
1125 |
return \@bind; |
removed reconnect method
|
1126 |
} |
1127 | ||
cleanup
|
1128 |
sub _croak { |
1129 |
my ($self, $error, $append) = @_; |
|
1130 |
$append ||= ""; |
|
1131 |
|
|
1132 |
# Verbose |
|
1133 |
if ($Carp::Verbose) { croak $error } |
|
1134 |
|
|
1135 |
# Not verbose |
|
1136 |
else { |
|
1137 |
|
|
1138 |
# Remove line and module infromation |
|
1139 |
my $at_pos = rindex($error, ' at '); |
|
1140 |
$error = substr($error, 0, $at_pos); |
|
1141 |
$error =~ s/\s+$//; |
|
1142 |
|
|
1143 |
croak "$error$append"; |
|
1144 |
} |
|
1145 |
} |
|
1146 | ||
remove experimental DBIx::Cu...
|
1147 |
sub _tables { |
1148 |
my ($self, $source) = @_; |
|
1149 |
|
|
1150 |
my $tables = []; |
|
1151 |
|
|
1152 |
my $safety_name = $self->safety_column_name; |
|
1153 |
|
|
1154 |
while ($source =~ /\b(\w+)\./g) { |
|
1155 |
push @$tables, $1; |
|
1156 |
} |
|
1157 |
|
|
1158 |
return $tables; |
|
1159 |
} |
|
1160 | ||
cleanup
|
1161 | |
1162 | ||
cleanup
|
1163 |
# DEPRECATED! |
cleanup
|
1164 |
__PACKAGE__->attr( |
1165 |
dbi_options => sub { {} }, |
|
1166 |
filter_check => 1 |
|
1167 |
); |
|
renamed dbi_options to dbi_o...
|
1168 | |
cleanup
|
1169 |
# DEPRECATED! |
cleanup
|
1170 |
sub default_bind_filter { |
1171 |
my $self = shift; |
|
1172 |
|
|
1173 |
if (@_) { |
|
1174 |
my $fname = $_[0]; |
|
1175 |
|
|
1176 |
if (@_ && !$fname) { |
|
1177 |
$self->{default_out_filter} = undef; |
|
1178 |
} |
|
1179 |
else { |
|
many changed
|
1180 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1181 |
unless exists $self->filters->{$fname}; |
1182 |
|
|
1183 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
1184 |
} |
|
1185 |
return $self; |
|
1186 |
} |
|
1187 |
|
|
1188 |
return $self->{default_out_filter}; |
|
1189 |
} |
|
1190 | ||
cleanup
|
1191 |
# DEPRECATED! |
cleanup
|
1192 |
sub default_fetch_filter { |
1193 |
my $self = shift; |
|
1194 |
|
|
1195 |
if (@_) { |
|
many changed
|
1196 |
my $fname = $_[0]; |
1197 | ||
cleanup
|
1198 |
if (@_ && !$fname) { |
1199 |
$self->{default_in_filter} = undef; |
|
1200 |
} |
|
1201 |
else { |
|
many changed
|
1202 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1203 |
unless exists $self->filters->{$fname}; |
1204 |
|
|
1205 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
1206 |
} |
|
1207 |
|
|
1208 |
return $self; |
|
1209 |
} |
|
1210 |
|
|
many changed
|
1211 |
return $self->{default_in_filter}; |
cleanup
|
1212 |
} |
1213 | ||
cleanup
|
1214 |
# DEPRECATED! |
renamed DBIx::Custom::TagPro...
|
1215 |
sub register_tag_processor { |
1216 |
return shift->query_builder->register_tag_processor(@_); |
|
1217 |
} |
|
1218 | ||
cleanup
|
1219 |
# DEPRECATED! |
1220 |
sub _push_relation { |
|
1221 |
my ($self, $sql, $tables, $relation, $need_where) = @_; |
|
1222 |
|
|
1223 |
if (keys %{$relation || {}}) { |
|
1224 |
push @$sql, $need_where ? 'where' : 'and'; |
|
1225 |
foreach my $rcolumn (keys %$relation) { |
|
1226 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1227 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1228 |
push @$tables, ($table1, $table2); |
|
1229 |
push @$sql, ("$rcolumn = " . $relation->{$rcolumn}, 'and'); |
|
1230 |
} |
|
1231 |
} |
|
1232 |
pop @$sql if $sql->[-1] eq 'and'; |
|
1233 |
} |
|
1234 | ||
1235 |
# DEPRECATED! |
|
1236 |
sub _add_relation_table { |
|
1237 |
my ($self, $relation, $tables) = @_; |
|
1238 |
|
|
1239 |
if (keys %{$relation || {}}) { |
|
1240 |
foreach my $rcolumn (keys %$relation) { |
|
1241 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1242 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1243 |
my $table1_exists; |
|
1244 |
my $table2_exists; |
|
1245 |
foreach my $table (@$tables) { |
|
1246 |
$table1_exists = 1 if $table eq $table1; |
|
1247 |
$table2_exists = 1 if $table eq $table2; |
|
1248 |
} |
|
1249 |
unshift @$tables, $table1 unless $table1_exists; |
|
1250 |
unshift @$tables, $table2 unless $table2_exists; |
|
1251 |
} |
|
1252 |
} |
|
1253 |
} |
|
1254 | ||
fixed DBIx::Custom::QueryBui...
|
1255 |
1; |
1256 | ||
removed reconnect method
|
1257 |
=head1 NAME |
1258 | ||
renamed build_query to creat...
|
1259 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
removed reconnect method
|
1260 | |
1261 |
=head1 SYNOPSYS |
|
cleanup
|
1262 | |
renamed build_query to creat...
|
1263 |
use DBIx::Custom; |
renamed update tag to update...
|
1264 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
renamed dbi_options to dbi_o...
|
1265 |
user => 'ken', password => '!LFKD%$&', |
1266 |
dbi_option => {mysql_enable_utf8 => 1}); |
|
cleanup
|
1267 | |
removed reconnect method
|
1268 |
# Insert |
added insert, update, update...
|
1269 |
$dbi->insert(table => 'book', |
renamed update tag to update...
|
1270 |
param => {title => 'Perl', author => 'Ken'}, |
all filter can receive array...
|
1271 |
filter => [title => 'to_something']); |
removed reconnect method
|
1272 |
|
1273 |
# Update |
|
added insert, update, update...
|
1274 |
$dbi->update(table => 'book', |
renamed update tag to update...
|
1275 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
1276 |
where => {id => 5}, |
all filter can receive array...
|
1277 |
filter => [title => 'to_something']); |
removed reconnect method
|
1278 |
|
1279 |
# Update all |
|
added insert, update, update...
|
1280 |
$dbi->update_all(table => 'book', |
renamed update tag to update...
|
1281 |
param => {title => 'Perl'}, |
all filter can receive array...
|
1282 |
filter => [title => 'to_something']); |
removed reconnect method
|
1283 |
|
1284 |
# Delete |
|
added insert, update, update...
|
1285 |
$dbi->delete(table => 'book', |
removed reconnect method
|
1286 |
where => {author => 'Ken'}, |
all filter can receive array...
|
1287 |
filter => [title => 'to_something']); |
removed reconnect method
|
1288 |
|
1289 |
# Delete all |
|
added insert, update, update...
|
1290 |
$dbi->delete_all(table => 'book'); |
cleanup
|
1291 | |
removed reconnect method
|
1292 |
# Select |
renamed fetch_rows to fetch_...
|
1293 |
my $result = $dbi->select( |
added insert, update, update...
|
1294 |
table => 'book', |
update document
|
1295 |
column => [qw/author title/], |
1296 |
where => {author => 'Ken'}, |
|
renamed dbi_options to dbi_o...
|
1297 |
relation => {'book.id' => 'rental.book_id'}, |
updated document
|
1298 |
append => 'order by id limit 5', |
all filter can receive array...
|
1299 |
filter => [title => 'to_something'] |
added commit method
|
1300 |
); |
cleanup
|
1301 | |
renamed build_query to creat...
|
1302 |
# Execute SQL |
added insert, update, update...
|
1303 |
$dbi->execute("select title from book"); |
removed register_format()
|
1304 |
|
renamed build_query to creat...
|
1305 |
# Execute SQL with hash binding and filtering |
added insert, update, update...
|
1306 |
$dbi->execute("select id from book where {= author} and {like title}", |
removed register_format()
|
1307 |
param => {author => 'ken', title => '%Perl%'}, |
all filter can receive array...
|
1308 |
filter => [title => 'to_something']); |
removed reconnect method
|
1309 | |
1310 |
# Create query and execute it |
|
renamed build_query to creat...
|
1311 |
my $query = $dbi->create_query( |
added insert, update, update...
|
1312 |
"select id from book where {= author} and {like title}" |
removed reconnect method
|
1313 |
); |
updated document
|
1314 |
$dbi->execute($query, param => {author => 'Ken', title => '%Perl%'}) |
cleanup
|
1315 | |
1316 |
# Get DBI object |
|
1317 |
my $dbh = $dbi->dbh; |
|
1318 | ||
removed register_format()
|
1319 |
# Fetch |
1320 |
while (my $row = $result->fetch) { |
|
1321 |
# ... |
|
1322 |
} |
|
1323 |
|
|
1324 |
# Fetch hash |
|
1325 |
while (my $row = $result->fetch_hash) { |
|
1326 |
|
|
1327 |
} |
|
1328 |
|
|
renamed update tag to update...
|
1329 |
=head1 DESCRIPTIONS |
removed reconnect method
|
1330 | |
renamed build_query to creat...
|
1331 |
L<DBIx::Custom> is one of L<DBI> interface modules, |
1332 |
such as L<DBIx::Class>, L<DBIx::Simple>. |
|
removed reconnect method
|
1333 | |
renamed build_query to creat...
|
1334 |
This module is not O/R mapper. O/R mapper is useful, |
1335 |
but you must learn many syntax of the O/R mapper, |
|
updated document
|
1336 |
which is almost another language. |
1337 |
Created SQL statement is offten not effcient and damage SQL performance. |
|
renamed build_query to creat...
|
1338 |
so you have to execute raw SQL in the end. |
removed reconnect method
|
1339 | |
renamed build_query to creat...
|
1340 |
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
updated document
|
1341 |
L<DBIx::Custom> provide flexible hash parameter binding and filtering system, |
added experimental expand me...
|
1342 |
and suger methods, such as C<insert()>, C<update()>, C<delete()>, C<select()> |
updated document
|
1343 |
to execute SQL easily. |
removed reconnect method
|
1344 | |
updated document
|
1345 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
1346 |
but de-facto standard, |
|
1347 |
so all people learing database know it. |
|
renamed update tag to update...
|
1348 |
If you already know SQL, |
1349 |
you learn a little thing to use L<DBIx::Custom>. |
|
removed reconnect method
|
1350 | |
pod fix
|
1351 |
See L<DBIx::Custom::Guide> for more details. |
1352 | ||
1353 |
=head1 GUIDE |
|
1354 | ||
1355 |
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide |
|
1356 | ||
1357 |
=head1 EXAMPLES |
|
1358 | ||
1359 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples |
|
updated document
|
1360 | |
update document
|
1361 |
=head1 ATTRIBUTES |
packaging one directory
|
1362 | |
cleanup
|
1363 |
=head2 C<cache> |
packaging one directory
|
1364 | |
cleanup
|
1365 |
my $cache = $dbi->cache; |
1366 |
$dbi = $dbi->cache(1); |
|
removed DESTROY method(not b...
|
1367 | |
cleanup
|
1368 |
Enable parsed L<DBIx::Custom::Query> object caching. |
1369 |
Default to 1. |
|
packaging one directory
|
1370 | |
removed DBIx::Custom commit ...
|
1371 |
=head2 C<data_source> |
packaging one directory
|
1372 | |
cleanup
|
1373 |
my $data_source = $dbi->data_source; |
cleanup
|
1374 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
1375 | |
cleanup
|
1376 |
Data source. |
1377 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1378 | |
removed DBIx::Custom commit ...
|
1379 |
=head2 C<dbh> |
packaging one directory
|
1380 | |
cleanup
|
1381 |
my $dbh = $dbi->dbh; |
1382 |
$dbi = $dbi->dbh($dbh); |
|
packaging one directory
|
1383 | |
cleanup
|
1384 |
L<DBI> object. You can call all methods of L<DBI>. |
packaging one directory
|
1385 | |
renamed dbi_options to dbi_o...
|
1386 |
=head2 C<dbi_option> |
added dbi_options attribute
|
1387 | |
renamed dbi_options to dbi_o...
|
1388 |
my $dbi_option = $dbi->dbi_option; |
1389 |
$dbi = $dbi->dbi_option($dbi_option); |
|
added dbi_options attribute
|
1390 | |
1391 |
DBI options. |
|
add default_dbi_option()
|
1392 | |
1393 |
Each option specified can ovewrite C<default_dbi_option>. |
|
1394 | ||
1395 |
C<connect()> method use this value to connect the database. |
|
1396 | ||
1397 | ||
1398 |
=head2 C<default_dbi_option> |
|
1399 | ||
1400 |
my $default_dbi_option = $dbi->default_dbi_option; |
|
1401 |
$dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1402 | ||
1403 |
DBI default options. |
|
1404 | ||
1405 |
RaiseError => 1, |
|
1406 |
PrintError => 0, |
|
1407 |
AutoCommit => 1, |
|
1408 | ||
added dbi_options attribute
|
1409 |
C<connect()> method use this value to connect the database. |
1410 | ||
cleanup
|
1411 |
Default filter when row is fetched. |
packaging one directory
|
1412 | |
cleanup
|
1413 |
=head2 C<filters> |
bind_filter argument is chan...
|
1414 | |
cleanup
|
1415 |
my $filters = $dbi->filters; |
1416 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
1417 | |
add models() attribute
|
1418 |
Filters |
1419 | ||
1420 |
=head2 C<(experimental) models> |
|
1421 | ||
1422 |
my $models = $dbi->models; |
|
1423 |
$dbi = $dbi->models(\%models); |
|
1424 | ||
1425 |
Models |
|
1426 | ||
cleanup
|
1427 |
=head2 C<password> |
1428 | ||
1429 |
my $password = $dbi->password; |
|
1430 |
$dbi = $dbi->password('lkj&le`@s'); |
|
1431 | ||
1432 |
Password. |
|
1433 |
C<connect()> method use this value to connect the database. |
|
update document
|
1434 | |
renamed update tag to update...
|
1435 |
=head2 C<query_builder> |
added commit method
|
1436 | |
renamed update tag to update...
|
1437 |
my $sql_class = $dbi->query_builder; |
1438 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1439 | |
renamed update tag to update...
|
1440 |
SQL builder. C<query_builder()> must be |
renamed build_query to creat...
|
1441 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
1442 |
Default to L<DBIx::Custom::QueryBuilder> object. |
|
cleanup
|
1443 | |
cleanup
|
1444 |
=head2 C<result_class> |
cleanup
|
1445 | |
cleanup
|
1446 |
my $result_class = $dbi->result_class; |
1447 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
1448 | |
cleanup
|
1449 |
Result class for select statement. |
1450 |
Default to L<DBIx::Custom::Result>. |
|
cleanup
|
1451 | |
update pod
|
1452 |
=head2 C<(experimental) safety_column_name> |
1453 | ||
1454 |
my $safety_column_name = $self->safety_column_name; |
|
1455 |
$dbi = $self->safety_column_name($name); |
|
1456 | ||
1457 |
Safety column name regex. |
|
1458 |
Default is qr/^[\w\.]*$/ |
|
1459 | ||
cleanup
|
1460 |
=head2 C<user> |
cleanup
|
1461 | |
cleanup
|
1462 |
my $user = $dbi->user; |
1463 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
1464 | |
cleanup
|
1465 |
User name. |
1466 |
C<connect()> method use this value to connect the database. |
|
update pod
|
1467 | |
cleanup
|
1468 |
=head1 METHODS |
added commit method
|
1469 | |
cleanup
|
1470 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
autoload DBI method
|
1471 |
and use all method of L<DBI> |
cleanup
|
1472 |
and implements the following new ones. |
added check_filter attribute
|
1473 | |
cleanup
|
1474 |
=head2 C<(experimental) apply_filter> |
added auto_filter method
|
1475 | |
renamed auto_filter to apply...
|
1476 |
$dbi->apply_filter( |
added auto_filter method
|
1477 |
$table, |
fix bug : filter can't over...
|
1478 |
$column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1} |
1479 |
$column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2} |
|
renamed auto_filter to apply...
|
1480 |
..., |
added auto_filter method
|
1481 |
); |
1482 | ||
renamed auto_filter to apply...
|
1483 |
C<apply_filter> is automatically filter for columns of table. |
added auto_filter method
|
1484 |
This have effect C<insert>, C<update>, C<delete>. C<select> |
cleanup
|
1485 |
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method. |
1486 | ||
cleanup
|
1487 |
If you want to have effect C<execute()> method, use C<table> |
cleanup
|
1488 |
arguments. |
added auto_filter method
|
1489 | |
cleanup
|
1490 |
$result = $dbi->execute( |
1491 |
"select * from table1 where {= key1} and {= key2};", |
|
1492 |
param => {key1 => 1, key2 => 2}, |
|
renamed auto_filter to apply...
|
1493 |
table => ['table1'] |
cleanup
|
1494 |
); |
fix bug : filter can't over...
|
1495 | |
1496 |
You can use three name as column name. |
|
1497 | ||
1498 |
1. column : author |
|
1499 |
2. table.column : book.author |
|
1500 |
3. table__column : book__author |
|
1501 | ||
removed DBIx::Custom commit ...
|
1502 |
=head2 C<connect> |
packaging one directory
|
1503 | |
cleanup
|
1504 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
update document
|
1505 |
user => 'ken', password => '!LFKD%$&'); |
bind_filter argument is chan...
|
1506 | |
cleanup
|
1507 |
Create a new L<DBIx::Custom> object and connect to the database. |
renamed build_query to creat...
|
1508 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1509 |
C<AutoCommit> and C<RaiseError> options are true, |
renamed build_query to creat...
|
1510 |
and C<PrintError> option is false by default. |
packaging one directory
|
1511 | |
cleanup
|
1512 |
=head2 C<create_query> |
1513 |
|
|
1514 |
my $query = $dbi->create_query( |
|
added insert, update, update...
|
1515 |
"select * from book where {= author} and {like title};" |
cleanup
|
1516 |
); |
update document
|
1517 | |
cleanup
|
1518 |
Create the instance of L<DBIx::Custom::Query> from the source of SQL. |
1519 |
If you want to get high performance, |
|
1520 |
use C<create_query()> method and execute it by C<execute()> method |
|
1521 |
instead of suger methods. |
|
bind_filter argument is chan...
|
1522 | |
cleanup
|
1523 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
version 0.0901
|
1524 | |
cleanup
|
1525 |
=head2 C<execute> |
packaging one directory
|
1526 | |
all filter can receive array...
|
1527 |
my $result = $dbi->execute($query, param => $params, filter => \@filter); |
1528 |
my $result = $dbi->execute($source, param => $params, filter => \@filter); |
|
update document
|
1529 | |
cleanup
|
1530 |
Execute query or the source of SQL. |
1531 |
Query is L<DBIx::Custom::Query> object. |
|
1532 |
Return value is L<DBIx::Custom::Result> if select statement is executed, |
|
1533 |
or the count of affected rows if insert, update, delete statement is executed. |
|
version 0.0901
|
1534 | |
removed DBIx::Custom commit ...
|
1535 |
=head2 C<delete> |
packaging one directory
|
1536 | |
cleanup
|
1537 |
$dbi->delete(table => $table, |
1538 |
where => \%where, |
|
1539 |
append => $append, |
|
all filter can receive array...
|
1540 |
filter => \@filter, |
added experimental sugar met...
|
1541 |
query => 1); |
bind_filter argument is chan...
|
1542 | |
renamed build_query to creat...
|
1543 |
Execute delete statement. |
1544 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
1545 |
C<table> is a table name. |
|
1546 |
C<where> is where clause. this must be hash reference. |
|
1547 |
C<append> is a string added at the end of the SQL statement. |
|
1548 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1549 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1550 |
default to 0. This is experimental. |
|
cleanup
|
1551 |
Return value of C<delete()> is the count of affected rows. |
renamed build_query to creat...
|
1552 | |
removed DBIx::Custom commit ...
|
1553 |
=head2 C<delete_all> |
packaging one directory
|
1554 | |
cleanup
|
1555 |
$dbi->delete_all(table => $table); |
packaging one directory
|
1556 | |
renamed build_query to creat...
|
1557 |
Execute delete statement to delete all rows. |
1558 |
Arguments is same as C<delete> method, |
|
1559 |
except that C<delete_all> don't have C<where> argument. |
|
cleanup
|
1560 |
Return value of C<delete_all()> is the count of affected rows. |
bind_filter argument is chan...
|
1561 | |
added experimental DBIx::Cus...
|
1562 |
=head3 C<(experimental) delete_at()> |
add experimental update_at()...
|
1563 | |
1564 |
To delete row by using primary key, use C<delete_at()> |
|
1565 | ||
1566 |
$dbi->delete_at( |
|
1567 |
table => 'book', |
|
1568 |
primary_key => ['id'], |
|
1569 |
where => ['123'] |
|
1570 |
); |
|
1571 | ||
1572 |
In this example, row which id column is 123 is deleted. |
|
1573 |
NOTE that you must pass array reference as C<where>. |
|
1574 | ||
1575 |
You can also write arguments like this. |
|
1576 | ||
1577 |
$dbi->delete_at( |
|
1578 |
table => 'book', |
|
1579 |
primary_key => ['id'], |
|
1580 |
param => {id => '123'} |
|
1581 |
); |
|
1582 | ||
cleanup
|
1583 |
=head2 C<insert> |
1584 | ||
1585 |
$dbi->insert(table => $table, |
|
1586 |
param => \%param, |
|
1587 |
append => $append, |
|
all filter can receive array...
|
1588 |
filter => \@filter, |
added experimental sugar met...
|
1589 |
query => 1); |
cleanup
|
1590 | |
1591 |
Execute insert statement. |
|
1592 |
C<insert> method have C<table>, C<param>, C<append> |
|
1593 |
and C<filter> arguments. |
|
1594 |
C<table> is a table name. |
|
1595 |
C<param> is the pairs of column name value. this must be hash reference. |
|
1596 |
C<append> is a string added at the end of the SQL statement. |
|
1597 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1598 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1599 |
default to 0. This is experimental. |
|
cleanup
|
1600 |
This is overwrites C<default_bind_filter>. |
1601 |
Return value of C<insert()> is the count of affected rows. |
|
1602 | ||
added experimental DBIx::Cus...
|
1603 |
=head3 C<(experimental) insert_at()> |
1604 | ||
1605 |
To insert row by using primary key, use C<insert_at()> |
|
1606 | ||
1607 |
$dbi->insert_at( |
|
1608 |
table => 'book', |
|
1609 |
primary_key => ['id'], |
|
1610 |
where => ['123'], |
|
1611 |
param => {name => 'Ken'} |
|
1612 |
); |
|
1613 | ||
1614 |
In this example, row which id column is 123 is inserted. |
|
1615 |
NOTE that you must pass array reference as C<where>. |
|
1616 |
If C<param> contains primary key, |
|
1617 |
the key and value is delete from C<param>. |
|
1618 | ||
added experimental update_pa...
|
1619 |
=head2 C<(experimental) insert_param> |
1620 | ||
1621 |
my $insert_param = $dbi->insert_param({title => 'a', age => 2}); |
|
1622 | ||
1623 |
Create insert parameter tag. |
|
1624 | ||
1625 |
{title => 'a', age => 2} -> {insert_param title age} |
|
1626 | ||
pod fix
|
1627 |
=head2 C<(experimental) each_column> |
added experimental iterate_a...
|
1628 | |
pod fix
|
1629 |
$dbi->each_column( |
added experimental iterate_a...
|
1630 |
sub { |
add experimental setup_model...
|
1631 |
my ($self, $table, $column, $column_info) = @_; |
added experimental iterate_a...
|
1632 |
|
add experimental setup_model...
|
1633 |
my $type = $column_info->{TYPE_NAME}; |
pod fix
|
1634 |
|
1635 |
if ($type eq 'DATE') { |
|
1636 |
# ... |
|
1637 |
} |
|
added experimental iterate_a...
|
1638 |
} |
1639 |
); |
|
pod fix
|
1640 |
Get column informations from database. |
1641 |
Argument is callback. |
|
1642 |
You can do anything in callback. |
|
added experimental not_exist...
|
1643 |
Callback receive four arguments, dbi object, table name, |
add experimental setup_model...
|
1644 |
column name and column information. |
added experimental not_exist...
|
1645 | |
add feture. all model class ...
|
1646 |
=head2 C<(experimental) include_model> |
removed experimental base_ta...
|
1647 | |
add feture. all model class ...
|
1648 |
$dbi->include_model( |
1649 |
'MyModel' => [ |
|
removed experimental base_ta...
|
1650 |
'book', 'person', 'company' |
1651 |
] |
|
1652 |
); |
|
1653 | ||
add feture. all model class ...
|
1654 |
Include models. First argument is name space. |
removed experimental base_ta...
|
1655 |
Second argument is array reference of class base names. |
1656 | ||
add feture. all model class ...
|
1657 |
If you don't specify second argument, All models under name space is |
1658 |
included. |
|
1659 | ||
1660 |
$dbi->include_model('MyModel'); |
|
1661 | ||
1662 |
Note that in this case name spece module is needed. |
|
1663 | ||
1664 |
# MyModel.pm |
|
1665 |
package MyModel; |
|
1666 |
|
|
1667 |
use base 'DBIx::Custom::Model'; |
|
1668 | ||
1669 |
The following model is instantiated and included. |
|
removed experimental base_ta...
|
1670 | |
add feture. all model class ...
|
1671 |
MyModel::book |
1672 |
MyModel::person |
|
1673 |
MyModel::company |
|
removed experimental base_ta...
|
1674 | |
add feture. all model class ...
|
1675 |
You can get these instance by C<model()>. |
removed experimental base_ta...
|
1676 | |
add feture. all model class ...
|
1677 |
my $book_model = $dbi->model('book'); |
removed experimental base_ta...
|
1678 | |
add feture. all model class ...
|
1679 |
If you want to other name as model class, |
removed experimental base_ta...
|
1680 |
you can do like this. |
1681 | ||
add feture. all model class ...
|
1682 |
$dbi->include_model( |
1683 |
'MyModel' => [ |
|
removed experimental base_ta...
|
1684 |
{'book' => 'Book'}, |
1685 |
{'person' => 'Person'} |
|
1686 |
] |
|
1687 |
); |
|
1688 | ||
added experimental not_exist...
|
1689 |
=head2 C<(experimental) method> |
1690 | ||
1691 |
$dbi->method( |
|
1692 |
update_or_insert => sub { |
|
1693 |
my $self = shift; |
|
1694 |
# do something |
|
1695 |
}, |
|
1696 |
find_or_create => sub { |
|
1697 |
my $self = shift; |
|
1698 |
# do something |
|
1699 |
} |
|
1700 |
); |
|
1701 | ||
1702 |
Register method. These method is called from L<DBIx::Custom> object directory. |
|
1703 | ||
1704 |
$dbi->update_or_insert; |
|
1705 |
$dbi->find_or_create; |
|
1706 | ||
1707 |
=head2 C<new> |
|
1708 | ||
1709 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
|
1710 |
user => 'ken', password => '!LFKD%$&'); |
|
1711 | ||
1712 |
Create a new L<DBIx::Custom> object. |
|
1713 | ||
1714 |
=head2 C<(experimental) not_exists> |
|
1715 | ||
1716 |
my $not_exists = $dbi->not_exists; |
|
1717 | ||
1718 |
Get DBIx::Custom::NotExists object. |
|
experimental extended select...
|
1719 | |
cleanup
|
1720 |
=head2 C<register_filter> |
1721 | ||
1722 |
$dbi->register_filter(%filters); |
|
1723 |
$dbi->register_filter(\%filters); |
|
1724 |
|
|
1725 |
Register filter. Registered filters is available in the following attributes |
|
1726 |
or arguments. |
|
1727 | ||
1728 |
=over 4 |
|
1729 | ||
1730 |
=item * |
|
1731 | ||
1732 |
C<filter> argument of C<insert()>, C<update()>, |
|
1733 |
C<update_all()>, C<delete()>, C<delete_all()>, C<select()> |
|
1734 |
methods |
|
1735 | ||
1736 |
=item * |
|
1737 | ||
1738 |
C<execute()> method |
|
1739 | ||
1740 |
=item * |
|
1741 | ||
1742 |
C<default_filter> and C<filter> of C<DBIx::Custom::Query> |
|
1743 | ||
1744 |
=item * |
|
1745 | ||
1746 |
C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
|
1747 | ||
1748 |
=back |
|
1749 | ||
renamed DBIx::Custom::TagPro...
|
1750 |
=head2 C<register_tag> |
added register_tag_processor
|
1751 | |
renamed DBIx::Custom::TagPro...
|
1752 |
$dbi->register_tag( |
added register_tag_processor
|
1753 |
limit => sub { |
1754 |
...; |
|
1755 |
} |
|
1756 |
); |
|
1757 | ||
cleanup
|
1758 |
Register tag. |
added register_tag_processor
|
1759 | |
added auto_filter method
|
1760 |
=head2 C<rollback> |
cleanup
|
1761 | |
1762 |
$dbi->rollback; |
|
1763 | ||
1764 |
Rollback transaction. |
|
1765 |
This is same as L<DBI>'s C<rollback>. |
|
1766 | ||
removed DBIx::Custom commit ...
|
1767 |
=head2 C<select> |
packaging one directory
|
1768 |
|
select method column option ...
|
1769 |
my $result = $dbi->select( |
1770 |
table => $table, |
|
1771 |
column => [@column], |
|
1772 |
where => \%where, |
|
1773 |
append => $append, |
|
1774 |
relation => \%relation, |
|
- added experimental DBIx::C...
|
1775 |
join => ['left outer join company on book.company_id = company.id'] |
select method column option ...
|
1776 |
filter => \%filter, |
1777 |
query => 1, |
|
1778 |
selection => $selection |
|
1779 |
); |
|
update document
|
1780 | |
renamed build_query to creat...
|
1781 |
Execute select statement. |
cleanup
|
1782 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
renamed build_query to creat...
|
1783 |
C<relation> and C<filter> arguments. |
1784 |
C<table> is a table name. |
|
select method column option ...
|
1785 |
C<column> is column names. this is array reference or string. |
cleanup
|
1786 |
C<where> is where clause. this is normally hash reference. |
renamed build_query to creat...
|
1787 |
C<append> is a string added at the end of the SQL statement. |
1788 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1789 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1790 |
default to 0. This is experimental. |
|
add experimental selection o...
|
1791 |
C<selection> is string of column name and tables. This is experimental |
1792 | ||
1793 |
selection => 'name, location.name as location_name ' . |
|
1794 |
'from company inner join location' |
|
update document
|
1795 | |
cleanup
|
1796 |
First element is a string. it contains tags, |
1797 |
such as "{= title} or {like author}". |
|
1798 |
Second element is paramters. |
|
1799 | ||
- added experimental DBIx::C...
|
1800 |
C<join> is join clause after from clause. |
cleanup
|
1801 |
This is experimental. |
1802 | ||
added experimental DBIx::Cus...
|
1803 |
=head3 C<(experimental) select_at()> |
add experimental update_at()...
|
1804 | |
1805 |
To select row by using primary key, use C<select_at()>. |
|
1806 | ||
1807 |
$dbi->select_at(table => 'book', primary_key => ['id'], where => ['123']); |
|
1808 | ||
1809 |
In this example, row which id colunm is 123 is selected. |
|
1810 |
NOTE that you must pass array reference as C<where>. |
|
1811 | ||
cleanup
|
1812 |
=head2 C<update> |
removed reconnect method
|
1813 | |
cleanup
|
1814 |
$dbi->update(table => $table, |
1815 |
param => \%params, |
|
1816 |
where => \%where, |
|
1817 |
append => $append, |
|
all filter can receive array...
|
1818 |
filter => \@filter, |
added experimental sugar met...
|
1819 |
query => 1) |
removed reconnect method
|
1820 | |
cleanup
|
1821 |
Execute update statement. |
1822 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
|
1823 |
and C<filter> arguments. |
|
1824 |
C<table> is a table name. |
|
1825 |
C<param> is column-value pairs. this must be hash reference. |
|
1826 |
C<where> is where clause. this must be hash reference. |
|
1827 |
C<append> is a string added at the end of the SQL statement. |
|
1828 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1829 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1830 |
default to 0. This is experimental. |
|
cleanup
|
1831 |
This is overwrites C<default_bind_filter>. |
1832 |
Return value of C<update()> is the count of affected rows. |
|
removed reconnect method
|
1833 | |
added experimental update_pa...
|
1834 |
=head2 C<(experimental) update_param> |
1835 | ||
1836 |
my $update_param = $dbi->update_param({title => 'a', age => 2}); |
|
1837 | ||
1838 |
Create update parameter tag. |
|
1839 | ||
1840 |
{title => 'a', age => 2} -> {update_param title age} |
|
1841 | ||
add feture. all model class ...
|
1842 |
=head2 C<(experimental) model> |
remove DBIx::Custom::Model
|
1843 | |
add feture. all model class ...
|
1844 |
$dbi->model('book')->method( |
remove DBIx::Custom::Model
|
1845 |
insert => sub { ... }, |
1846 |
update => sub { ... } |
|
1847 |
); |
|
1848 |
|
|
add feture. all model class ...
|
1849 |
my $model = $dbi->model('book'); |
remove DBIx::Custom::Model
|
1850 | |
add feture. all model class ...
|
1851 |
Set and get a L<DBIx::Custom::Model> object, |
remove DBIx::Custom::Model
|
1852 | |
add experimental setup_model...
|
1853 |
=head2 C<(experimental) setup_model> |
1854 | ||
1855 |
$dbi->setup_model; |
|
1856 | ||
1857 |
Setup all model objects. |
|
1858 |
C<columns> and C<primary_key> is automatically set. |
|
1859 | ||
cleanup
|
1860 |
=head2 C<update_all> |
renamed build_query to creat...
|
1861 | |
cleanup
|
1862 |
$dbi->update_all(table => $table, |
1863 |
param => \%params, |
|
all filter can receive array...
|
1864 |
filter => \@filter, |
cleanup
|
1865 |
append => $append); |
renamed build_query to creat...
|
1866 | |
cleanup
|
1867 |
Execute update statement to update all rows. |
1868 |
Arguments is same as C<update> method, |
|
1869 |
except that C<update_all> don't have C<where> argument. |
|
1870 |
Return value of C<update_all()> is the count of affected rows. |
|
removed DBIx::Custom commit ...
|
1871 | |
added experimental DBIx::Cus...
|
1872 |
=head3 C<(experimental) update_at()> |
add experimental update_at()...
|
1873 | |
1874 |
To update row by using primary key, use C<update_at()> |
|
1875 | ||
1876 |
$dbi->update_at( |
|
1877 |
table => 'book', |
|
1878 |
primary_key => ['id'], |
|
1879 |
where => ['123'], |
|
1880 |
param => {name => 'Ken'} |
|
1881 |
); |
|
1882 | ||
1883 |
In this example, row which id column is 123 is updated. |
|
1884 |
NOTE that you must pass array reference as C<where>. |
|
1885 |
If C<param> contains primary key, |
|
1886 |
the key and value is delete from C<param>. |
|
1887 | ||
fix tests
|
1888 |
=head2 C<(experimental) where> |
1889 | ||
1890 |
my $where = $dbi->where; |
|
1891 | ||
1892 |
Create a new L<DBIx::Custom::Where> object. |
|
1893 | ||
cleanup
|
1894 |
=head2 C<cache_method> |
cleanup
|
1895 | |
1896 |
$dbi = $dbi->cache_method(\&cache_method); |
|
1897 |
$cache_method = $dbi->cache_method |
|
1898 | ||
1899 |
Method to set and get caches. |
|
1900 | ||
cleanup
|
1901 |
=head1 Tags |
1902 | ||
1903 |
The following tags is available. |
|
1904 | ||
add experimental selection o...
|
1905 |
=head2 C<(experimental) table> |
add table tag
|
1906 | |
1907 |
Table tag |
|
1908 | ||
1909 |
{table TABLE} -> TABLE |
|
1910 | ||
1911 |
This is used to teach what is applied table to C<execute()>. |
|
1912 | ||
cleanup
|
1913 |
=head2 C<?> |
1914 | ||
1915 |
Placeholder tag. |
|
1916 | ||
1917 |
{? NAME} -> ? |
|
1918 | ||
1919 |
=head2 C<=> |
|
1920 | ||
1921 |
Equal tag. |
|
1922 | ||
1923 |
{= NAME} -> NAME = ? |
|
1924 | ||
1925 |
=head2 C<E<lt>E<gt>> |
|
1926 | ||
1927 |
Not equal tag. |
|
1928 | ||
1929 |
{<> NAME} -> NAME <> ? |
|
1930 | ||
1931 |
=head2 C<E<lt>> |
|
1932 | ||
1933 |
Lower than tag |
|
1934 | ||
1935 |
{< NAME} -> NAME < ? |
|
1936 | ||
1937 |
=head2 C<E<gt>> |
|
1938 | ||
1939 |
Greater than tag |
|
1940 | ||
1941 |
{> NAME} -> NAME > ? |
|
1942 | ||
1943 |
=head2 C<E<gt>=> |
|
1944 | ||
1945 |
Greater than or equal tag |
|
1946 | ||
1947 |
{>= NAME} -> NAME >= ? |
|
1948 | ||
1949 |
=head2 C<E<lt>=> |
|
1950 | ||
1951 |
Lower than or equal tag |
|
1952 | ||
1953 |
{<= NAME} -> NAME <= ? |
|
1954 | ||
1955 |
=head2 C<like> |
|
1956 | ||
1957 |
Like tag |
|
1958 | ||
1959 |
{like NAME} -> NAME like ? |
|
1960 | ||
1961 |
=head2 C<in> |
|
1962 | ||
1963 |
In tag. |
|
1964 | ||
1965 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
1966 | ||
1967 |
=head2 C<insert_param> |
|
1968 | ||
1969 |
Insert parameter tag. |
|
1970 | ||
1971 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
1972 | ||
1973 |
=head2 C<update_param> |
|
1974 | ||
1975 |
Updata parameter tag. |
|
1976 | ||
1977 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
1978 | ||
DBIx::Custom is now stable
|
1979 |
=head1 STABILITY |
1980 | ||
cleanup
|
1981 |
L<DBIx::Custom> is stable. APIs keep backword compatible |
1982 |
except experimental one in the feature. |
|
DBIx::Custom is now stable
|
1983 | |
removed DESTROY method(not b...
|
1984 |
=head1 BUGS |
1985 | ||
renamed build_query to creat...
|
1986 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
1987 | |
1988 |
C<< <kimoto.yuki at gmail.com> >> |
|
1989 | ||
1990 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1991 | ||
removed reconnect method
|
1992 |
=head1 AUTHOR |
1993 | ||
1994 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
1995 | |
packaging one directory
|
1996 |
=head1 COPYRIGHT & LICENSE |
1997 | ||
cleanup
|
1998 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
1999 | |
2000 |
This program is free software; you can redistribute it and/or modify it |
|
2001 |
under the same terms as Perl itself. |
|
2002 | ||
2003 |
=cut |
|
added cache_method attribute
|
2004 | |
2005 |