cleanup
|
1 |
package DBIx::Custom; |
2 | ||
updatedd pod
|
3 |
our $VERSION = '0.1690'; |
fixed DBIx::Custom::QueryBui...
|
4 |
use 5.008001; |
cleanup
|
5 | |
updatedd pod
|
6 |
use Object::Simple -base; |
many change
|
7 | |
packaging one directory
|
8 |
use Carp 'croak'; |
9 |
use DBI; |
|
10 |
use DBIx::Custom::Result; |
|
cleanup
|
11 |
use DBIx::Custom::Query; |
cleanup
|
12 |
use DBIx::Custom::QueryBuilder; |
added experimental DBIx::Cus...
|
13 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
14 |
use DBIx::Custom::Model; |
cleanup
|
15 |
use DBIx::Custom::Tag; |
cleanup
|
16 |
use DBIx::Custom::Util qw/_array_to_hash _subname/; |
improved debug message
|
17 |
use Encode qw/encode encode_utf8 decode_utf8/; |
packaging one directory
|
18 | |
added environment variable D...
|
19 |
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0; |
improved debug message
|
20 |
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8'; |
added environment variable D...
|
21 | |
added EXPERIMENTAL execute()...
|
22 |
our @COMMON_ARGS = qw/table query filter type id primary_key type_rule_off/; |
cleanup
|
23 | |
updatedd pod
|
24 |
has [qw/connector dsn password user/], |
removed from cache() and cac...
|
25 |
cache => 0, |
many changed
|
26 |
cache_method => sub { |
27 |
sub { |
|
28 |
my $self = shift; |
|
29 |
|
|
30 |
$self->{_cached} ||= {}; |
|
31 |
|
|
32 |
if (@_ > 1) { |
|
update pod
|
33 |
$self->{_cached}{$_[0]} = $_[1]; |
many changed
|
34 |
} |
35 |
else { |
|
update pod
|
36 |
return $self->{_cached}{$_[0]}; |
many changed
|
37 |
} |
38 |
} |
|
update pod
|
39 |
}, |
40 |
dbi_option => sub { {} }, |
|
41 |
default_dbi_option => sub { |
|
42 |
{ |
|
43 |
RaiseError => 1, |
|
44 |
PrintError => 0, |
|
45 |
AutoCommit => 1 |
|
46 |
} |
|
47 |
}, |
|
fix tests
|
48 |
filters => sub { |
49 |
{ |
|
50 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
51 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
52 |
} |
|
update pod
|
53 |
}, |
54 |
models => sub { {} }, |
|
55 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
|
56 |
result_class => 'DBIx::Custom::Result', |
|
added EXPERIMENTAL reserved_...
|
57 |
reserved_word_quote => '', |
update pod
|
58 |
safety_character => '\w', |
updatedd pod
|
59 |
stash => sub { {} }; |
cleanup
|
60 | |
added helper method
|
61 |
our $AUTOLOAD; |
62 |
sub AUTOLOAD { |
|
63 |
my $self = shift; |
|
64 | ||
renamed helper to method.
|
65 |
# Method name |
66 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
67 | |
cleanup
|
68 |
# Call method |
renamed helper to method.
|
69 |
$self->{_methods} ||= {}; |
add feture. all model class ...
|
70 |
if (my $method = $self->{_methods}->{$mname}) { |
71 |
return $self->$method(@_) |
|
72 |
} |
|
- removed EXPERIMENTAL Prefo...
|
73 |
elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) { |
- added EXPERIMENTAL DBIx::C...
|
74 |
$self->dbh->$dbh_method(@_); |
add feture. all model class ...
|
75 |
} |
76 |
else { |
|
cleanup
|
77 |
croak qq{Can't locate object method "$mname" via "$package" } |
78 |
. _subname; |
|
add feture. all model class ...
|
79 |
} |
added helper method
|
80 |
} |
81 | ||
added DBIx::Custom result_fi...
|
82 |
sub apply_filter { shift->_apply_filter(@_) } |
83 | ||
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 |
|
cleanup
|
93 |
# Usage |
many changed
|
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}, ...)"; |
|
cleanup
|
97 |
|
98 |
# Apply filter |
|
many changed
|
99 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
added auto_filter method
|
100 |
|
many changed
|
101 |
# Column |
102 |
my $column = $cinfos[$i]; |
|
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 |
|
|
cleanup
|
110 |
# Filter infomation |
fix bug : filter can't over...
|
111 |
my $finfo = $cinfos[$i + 1] || {}; |
cleanup
|
112 |
croak "$usage (table: $table) " . _subname |
improved error messages
|
113 |
unless ref $finfo eq 'HASH'; |
fix bug : filter can't over...
|
114 |
foreach my $ftype (keys %$finfo) { |
cleanup
|
115 |
croak "$usage (table: $table) " . _subname |
improved error messages
|
116 |
unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; |
many changed
|
117 |
} |
118 |
|
|
cleanup
|
119 |
# Set filters |
fix bug : filter can't over...
|
120 |
foreach my $way (qw/in out end/) { |
cleanup
|
121 |
|
122 |
# Filter |
|
fix bug : filter can't over...
|
123 |
my $filter = $finfo->{$way}; |
cleanup
|
124 |
|
cleanup
|
125 |
# Filter state |
fix bug : filter can't over...
|
126 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
127 |
: !defined $filter ? 'not_defined' |
|
128 |
: ref $filter eq 'CODE' ? 'code' |
|
129 |
: 'name'; |
|
130 |
|
|
cleanup
|
131 |
# Filter is not exists |
fix bug : filter can't over...
|
132 |
next if $state eq 'not_exists'; |
133 |
|
|
cleanup
|
134 |
# Check filter name |
cleanup
|
135 |
croak qq{Filter "$filter" is not registered } . _subname |
fix bug : filter can't over...
|
136 |
if $state eq 'name' |
137 |
&& ! exists $self->filters->{$filter}; |
|
138 |
|
|
cleanup
|
139 |
# Set filter |
fix bug : filter can't over...
|
140 |
my $f = $state eq 'not_defined' ? undef |
141 |
: $state eq 'code' ? $filter |
|
142 |
: $self->filters->{$filter}; |
|
143 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
144 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
145 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
many changed
|
146 |
} |
added auto_filter method
|
147 |
} |
148 |
|
|
many changed
|
149 |
return $self; |
added auto_filter method
|
150 |
} |
151 | ||
- update_param_tag is DEPREC...
|
152 |
sub assign_param { |
added EXPERIMENTAL assign_ta...
|
153 |
my ($self, $param) = @_; |
154 |
|
|
155 |
# Create set tag |
|
156 |
my @params; |
|
157 |
my $safety = $self->safety_character; |
|
158 |
my $q = $self->reserved_word_quote; |
|
159 |
foreach my $column (keys %$param) { |
|
160 |
croak qq{"$column" is not safety column name } . _subname |
|
161 |
unless $column =~ /^[$safety\.]+$/; |
|
- update_param_tag is DEPREC...
|
162 |
my $column_quote = "$q$column$q"; |
163 |
$column_quote =~ s/\./$q.$q/; |
|
164 |
push @params, "$column_quote = :$column"; |
|
added EXPERIMENTAL assign_ta...
|
165 |
} |
166 |
my $tag = join(', ', @params); |
|
167 |
|
|
168 |
return $tag; |
|
169 |
} |
|
170 | ||
added EXPERIMENTAL col metho...
|
171 |
sub col { |
172 |
my ($self, $table, $columns) = @_; |
|
173 |
|
|
174 |
# Reserved word quote |
|
175 |
my $q = $self->reserved_word_quote; |
|
176 |
|
|
177 |
# Column clause |
|
178 |
my @column; |
|
179 |
$columns ||= []; |
|
180 |
push @column, "$q$table$q.$q$_$q as $q${table}.$_$q" for @$columns; |
|
181 |
|
|
182 |
return join (', ', @column); |
|
183 |
} |
|
184 | ||
cleanup
|
185 |
sub column { |
186 |
my ($self, $table, $columns) = @_; |
|
added helper method
|
187 |
|
cleanup
|
188 |
# Reserved word quote |
added EXPERIMENTAL reserved_...
|
189 |
my $q = $self->reserved_word_quote; |
190 |
|
|
cleanup
|
191 |
# Column clause |
cleanup
|
192 |
my @column; |
cleanup
|
193 |
$columns ||= []; |
set reserved_word_quote auto...
|
194 |
push @column, "$q$table$q.$q$_$q as $q${table}__$_$q" for @$columns; |
cleanup
|
195 |
|
196 |
return join (', ', @column); |
|
added helper method
|
197 |
} |
198 | ||
packaging one directory
|
199 |
sub connect { |
cleanup
|
200 |
my $self = ref $_[0] ? shift : shift->new(@_);; |
removed register_format()
|
201 |
|
- removed EXPERIMENTAL Prefo...
|
202 |
# Connect |
203 |
$self->dbh; |
|
update document
|
204 |
|
packaging one directory
|
205 |
return $self; |
206 |
} |
|
207 | ||
cleanup
|
208 |
sub create_query { |
209 |
my ($self, $source) = @_; |
|
update document
|
210 |
|
cleanup
|
211 |
# Cache |
212 |
my $cache = $self->cache; |
|
update document
|
213 |
|
cleanup
|
214 |
# Query |
cleanup
|
215 |
my $query; |
cleanup
|
216 |
|
217 |
# Get cached query |
|
cleanup
|
218 |
if ($cache) { |
219 |
|
|
220 |
# Get query |
|
221 |
my $q = $self->cache_method->($self, $source); |
|
222 |
|
|
223 |
# Create query |
|
add table tag
|
224 |
if ($q) { |
225 |
$query = DBIx::Custom::Query->new($q); |
|
226 |
$query->filters($self->filters); |
|
227 |
} |
|
cleanup
|
228 |
} |
229 |
|
|
cleanup
|
230 |
# Create query |
cleanup
|
231 |
unless ($query) { |
cleanup insert
|
232 | |
cleanup
|
233 |
# Create query |
cleanup
|
234 |
my $builder = $self->query_builder; |
cleanup
|
235 |
$query = $builder->build_query($source); |
removed register_format()
|
236 | |
cleanup
|
237 |
# Remove reserved word quote |
added EXPERIMENTAL reserved_...
|
238 |
if (my $q = $self->reserved_word_quote) { |
cleanup
|
239 |
$_ =~ s/$q//g for @{$query->columns} |
added EXPERIMENTAL reserved_...
|
240 |
} |
241 | ||
cleanup
|
242 |
# Save query to cache |
243 |
$self->cache_method->( |
|
244 |
$self, $source, |
|
245 |
{ |
|
246 |
sql => $query->sql, |
|
247 |
columns => $query->columns, |
|
248 |
tables => $query->tables |
|
249 |
} |
|
250 |
) if $cache; |
|
cleanup insert
|
251 |
} |
252 |
|
|
cleanup
|
253 |
# Prepare statement handle |
254 |
my $sth; |
|
255 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
improved error messages
|
256 |
|
257 |
if ($@) { |
|
258 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
|
cleanup
|
259 |
. qq{$query->{sql}\n} . _subname); |
improved error messages
|
260 |
} |
packaging one directory
|
261 |
|
cleanup
|
262 |
# Set statement handle |
263 |
$query->sth($sth); |
|
packaging one directory
|
264 |
|
cleanup
|
265 |
# Set filters |
266 |
$query->filters($self->filters); |
|
267 |
|
|
cleanup
|
268 |
return $query; |
packaging one directory
|
269 |
} |
270 | ||
update pod
|
271 |
sub dbh { |
272 |
my $self = shift; |
|
cleanup
|
273 |
|
fixed dbh() method bug:wq
|
274 |
# Set |
275 |
if (@_) { |
|
276 |
$self->{dbh} = $_[0]; |
|
277 |
|
|
278 |
return $self; |
|
279 |
} |
|
280 |
|
|
281 |
# Get |
|
282 |
else { |
|
283 |
# From Connction manager |
|
284 |
if (my $connector = $self->connector) { |
|
cleanup
|
285 |
croak "connector must have dbh() method " . _subname |
fixed dbh() method bug:wq
|
286 |
unless ref $connector && $connector->can('dbh'); |
287 |
|
|
set reserved_word_quote auto...
|
288 |
$self->{dbh} = $connector->dbh; |
fixed dbh() method bug:wq
|
289 |
} |
290 |
|
|
set reserved_word_quote auto...
|
291 |
# Connect |
292 |
$self->{dbh} ||= $self->_connect; |
|
293 |
|
|
294 |
# Quote |
|
295 |
unless ($self->reserved_word_quote) { |
|
296 |
my $driver = $self->{dbh}->{Driver}->{Name}; |
|
297 |
my $quote = $driver eq 'mysql' ? '`' : '"'; |
|
298 |
$self->reserved_word_quote($quote); |
|
299 |
} |
|
300 | ||
301 |
return $self->{dbh}; |
|
update pod
|
302 |
} |
303 |
} |
|
304 | ||
cleanup
|
305 |
our %DELETE_ARGS |
DEPRECATED select() param op...
|
306 |
= map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all where_param/; |
cleanup update and update_al...
|
307 | |
cleanup
|
308 |
sub delete { |
select, insert, update, upda...
|
309 |
my ($self, %args) = @_; |
added EXPERIMENTAL reserved_...
|
310 | |
cleanup
|
311 |
# Check arguments |
select, insert, update, upda...
|
312 |
foreach my $name (keys %args) { |
cleanup
|
313 |
croak qq{"$name" is wrong option } . _subname |
cleanup
|
314 |
unless $DELETE_ARGS{$name}; |
cleanup update and update_al...
|
315 |
} |
316 |
|
|
317 |
# Arguments |
|
cleanup
|
318 |
my $table = $args{table} || ''; |
cleanup
|
319 |
croak qq{"table" option must be specified. } . _subname |
improved error messages
|
320 |
unless $table; |
cleanup
|
321 |
my $where = delete $args{where} || {}; |
322 |
my $append = delete $args{append}; |
|
323 |
my $allow_delete_all = delete $args{allow_delete_all}; |
|
DEPRECATED select() param op...
|
324 |
my $where_param = delete $args{where_param} || {}; |
delete_at is DEPRECATED! use...
|
325 |
my $id = delete $args{id}; |
326 |
my $primary_key = delete $args{primary_key}; |
|
327 |
croak "update method primary_key option " . |
|
328 |
"must be specified when id is specified " . _subname |
|
329 |
if defined $id && !defined $primary_key; |
|
330 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
331 |
|
|
make delete() using where ob...
|
332 |
# Where |
delete_at is DEPRECATED! use...
|
333 |
$where = $self->_create_param_from_id($id, $primary_key) if $id; |
select, update, and delete w...
|
334 |
my $where_clause = ''; |
335 |
if (ref $where) { |
|
336 |
$where = $self->_where_to_obj($where); |
|
DEPRECATED select() param op...
|
337 |
$where_param = keys %$where_param |
338 |
? $self->merge_param($where_param, $where->param) |
|
339 |
: $where->param; |
|
select, update, and delete w...
|
340 |
|
341 |
# String where |
|
342 |
$where_clause = $where->to_string; |
|
343 |
} |
|
344 |
elsif ($where) { $where_clause = "where $where" } |
|
cleanup
|
345 |
croak qq{"where" must be specified } . _subname |
cleanup
|
346 |
if $where_clause eq '' && !$allow_delete_all; |
make delete() using where ob...
|
347 | |
cleanup
|
348 |
# Delete statement |
cleanup
|
349 |
my @sql; |
cleanup
|
350 |
my $q = $self->reserved_word_quote; |
351 |
push @sql, "delete from $q$table$q $where_clause"; |
|
cleanup
|
352 |
push @sql, $append if $append; |
353 |
my $sql = join(' ', @sql); |
|
packaging one directory
|
354 |
|
355 |
# Execute query |
|
cleanup
|
356 |
return $self->execute( |
cleanup
|
357 |
$sql, |
DEPRECATED select() param op...
|
358 |
param => $where_param, |
cleanup
|
359 |
table => $table, |
360 |
%args |
|
361 |
); |
|
packaging one directory
|
362 |
} |
363 | ||
cleanup
|
364 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
365 | |
added helper method
|
366 |
sub DESTROY { } |
367 | ||
removed EXPERIMETNAL flag fr...
|
368 |
sub create_model { |
369 |
my $self = shift; |
|
370 |
|
|
cleanup
|
371 |
# Arguments |
removed EXPERIMETNAL flag fr...
|
372 |
my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
373 |
$args->{dbi} = $self; |
|
374 |
my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model'; |
|
375 |
my $model_name = delete $args->{name}; |
|
376 |
my $model_table = delete $args->{table}; |
|
377 |
$model_name ||= $model_table; |
|
378 |
|
|
cleanup
|
379 |
# Create model |
removed EXPERIMETNAL flag fr...
|
380 |
my $model = $model_class->new($args); |
381 |
$model->name($model_name) unless $model->name; |
|
382 |
$model->table($model_table) unless $model->table; |
|
383 |
|
|
384 |
# Apply filter |
|
DBIx::Custom::Model filter a...
|
385 |
my $filter = ref $model->filter eq 'HASH' |
386 |
? [%{$model->filter}] |
|
387 |
: $model->filter; |
|
388 |
$self->apply_filter($model->table, @$filter); |
|
added DBIx::Custom result_fi...
|
389 |
my $result_filter = ref $model->result_filter eq 'HASH' |
390 |
? [%{$model->result_filter}] |
|
391 |
: $model->result_filter; |
|
392 |
for (my $i = 1; $i < @$result_filter; $i += 2) { |
|
393 |
$result_filter->[$i] = {in => $result_filter->[$i]}; |
|
394 |
} |
|
395 |
$self->apply_filter($model->table, @$result_filter); |
|
removed EXPERIMETNAL flag fr...
|
396 |
|
cleanup
|
397 |
# Associate table with model |
cleanup
|
398 |
croak "Table name is duplicated " . _subname |
removed EXPERIMETNAL flag fr...
|
399 |
if exists $self->{_model_from}->{$model->table}; |
400 |
$self->{_model_from}->{$model->table} = $model->name; |
|
401 | ||
402 |
# Table alias |
|
403 |
$self->{_table_alias} ||= {}; |
|
404 |
$self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}}; |
|
405 |
|
|
406 |
# Set model |
|
407 |
$self->model($model->name, $model); |
|
408 |
|
|
create_model() return model
|
409 |
return $self->model($model->name); |
removed EXPERIMETNAL flag fr...
|
410 |
} |
411 | ||
412 |
sub each_column { |
|
413 |
my ($self, $cb) = @_; |
|
414 |
|
|
415 |
# Iterate all tables |
|
416 |
my $sth_tables = $self->dbh->table_info; |
|
417 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
418 |
|
|
419 |
# Table |
|
420 |
my $table = $table_info->{TABLE_NAME}; |
|
421 |
|
|
422 |
# Iterate all columns |
|
423 |
my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%'); |
|
424 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
425 |
my $column = $column_info->{COLUMN_NAME}; |
|
426 |
$self->$cb($table, $column, $column_info); |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 | ||
cleanup
|
431 |
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param'; |
432 | ||
433 |
sub execute { |
|
execute method can second ar...
|
434 |
my $self = shift; |
435 |
my $query = shift; |
|
436 |
my $param; |
|
437 |
$param = shift if @_ % 2; |
|
438 |
my %args = @_; |
|
refactoring delete and delet...
|
439 |
|
cleanup
|
440 |
# Arguments |
execute method can second ar...
|
441 |
my $p = delete $args{param} || {}; |
442 |
$param ||= $p; |
|
cleanup
|
443 |
my $tables = delete $args{table} || []; |
444 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
|
cleanup
|
445 |
my $filter = delete $args{filter}; |
cleanup
|
446 |
$filter = _array_to_hash($filter); |
cleanup
|
447 |
my $type = delete $args{type}; |
cleanup
|
448 |
$type = _array_to_hash($type); |
added EXPERIMENTAL execute()...
|
449 |
my $type_rule_off = delete $args{type_rule_off}; |
cleanup
|
450 |
my $query_return = delete $args{query}; |
added EXPERIMENTAL reserved_...
|
451 |
|
cleanup
|
452 |
# Check argument names |
select, insert, update, upda...
|
453 |
foreach my $name (keys %args) { |
cleanup
|
454 |
croak qq{"$name" is wrong option } . _subname |
cleanup
|
455 |
unless $EXECUTE_ARGS{$name}; |
refactoring delete and delet...
|
456 |
} |
457 |
|
|
cleanup
|
458 |
# Create query |
459 |
$query = $self->create_query($query) unless ref $query; |
|
cleanup
|
460 |
return $query if $query_return; |
cleanup
|
461 |
$filter ||= $query->filter; |
all filter can receive array...
|
462 |
|
cleanup
|
463 |
# Tables |
464 |
unshift @$tables, @{$query->tables}; |
|
cleanup
|
465 |
my $main_table = pop @$tables; |
cleanup
|
466 |
$tables = $self->_remove_duplicate_table($tables, $main_table); |
467 |
if (my $q = $self->reserved_word_quote) { |
|
468 |
$_ =~ s/$q//g for @$tables; |
|
469 |
} |
|
cleanup
|
470 |
|
471 |
# Table alias |
|
cleanup
|
472 |
foreach my $table (@$tables) { |
- added EXPERIMENTAL DBIx::C...
|
473 |
|
cleanup
|
474 |
# No need |
475 |
next unless my $alias = $self->{_table_alias}->{$table}; |
|
476 |
$self->{filter} ||= {}; |
|
477 |
next if $self->{filter}{out}{$table}; |
|
478 |
|
|
479 |
# Filter |
|
480 |
$self->{filter}{out} ||= {}; |
|
481 |
$self->{filter}{in} ||= {}; |
|
482 |
$self->{filter}{end} ||= {}; |
|
483 |
|
|
484 |
# Create alias filter |
|
485 |
foreach my $type (qw/out in end/) { |
|
486 |
my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}}; |
|
487 |
foreach my $filter_name (@filter_names) { |
|
488 |
my $filter_name_alias = $filter_name; |
|
489 |
$filter_name_alias =~ s/^$alias\./$table\./; |
|
490 |
$filter_name_alias =~ s/^${alias}__/${table}__/; |
|
491 |
$self->{filter}{$type}{$table}{$filter_name_alias} |
|
492 |
= $self->{filter}{$type}{$alias}{$filter_name} |
|
- added EXPERIMENTAL DBIx::C...
|
493 |
} |
494 |
} |
|
495 |
} |
|
added type_rule into logic
|
496 | |
497 |
# Type rule |
|
498 |
my $applied_filter = {}; |
|
added EXPERIMENTAL execute()...
|
499 |
unless ($type_rule_off) { |
500 |
foreach my $name (keys %$param) { |
|
501 |
my $table; |
|
502 |
my $column; |
|
503 |
if ($name =~ /(?:(.+)\.)?(.+)/) { |
|
504 |
$table = $1; |
|
505 |
$column = $2; |
|
506 |
} |
|
507 |
$table ||= $main_table; |
|
508 |
|
|
509 |
my $into = $self->{_into} || {}; |
|
510 |
if (defined $table && $into->{$table} && |
|
511 |
(my $rule = $into->{$table}->{$column})) |
|
512 |
{ |
|
513 |
$applied_filter->{$column} = $rule; |
|
514 |
$applied_filter->{"$table.$column"} = $rule; |
|
515 |
} |
|
added type_rule into logic
|
516 |
} |
517 |
} |
|
cleanup
|
518 |
|
519 |
# Applied filter |
|
renamed auto_filter to apply...
|
520 |
foreach my $table (@$tables) { |
cleanup
|
521 |
$applied_filter = { |
522 |
%$applied_filter, |
|
cleanup
|
523 |
%{$self->{filter}{out}->{$table} || {}} |
added auto_filter method
|
524 |
} |
525 |
} |
|
cleanup
|
526 |
$filter = {%$applied_filter, %$filter}; |
added auto_filter method
|
527 |
|
cleanup
|
528 |
# Replace filter name to code |
529 |
foreach my $column (keys %$filter) { |
|
530 |
my $name = $filter->{$column}; |
|
531 |
if (!defined $name) { |
|
532 |
$filter->{$column} = undef; |
|
renamed auto_filter to apply...
|
533 |
} |
cleanup
|
534 |
elsif (ref $name ne 'CODE') { |
cleanup
|
535 |
croak qq{Filter "$name" is not registered" } . _subname |
cleanup
|
536 |
unless exists $self->filters->{$name}; |
537 |
$filter->{$column} = $self->filters->{$name}; |
|
cleanup
|
538 |
} |
539 |
} |
|
packaging one directory
|
540 |
|
cleanup
|
541 |
# Create bind values |
542 |
my $bind = $self->_create_bind_values( |
|
543 |
$param, |
|
544 |
$query->columns, |
|
545 |
$filter, |
|
546 |
$type |
|
547 |
); |
|
cleanup
|
548 |
|
549 |
# Execute |
|
added experimental not_exist...
|
550 |
my $sth = $query->sth; |
cleanup
|
551 |
my $affected; |
cleanup
|
552 |
eval { |
553 |
for (my $i = 0; $i < @$bind; $i++) { |
|
cleanup
|
554 |
my $type = $bind->[$i]->{type}; |
555 |
$sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ()); |
|
cleanup
|
556 |
} |
557 |
$affected = $sth->execute; |
|
558 |
}; |
|
improved error messages
|
559 |
|
560 |
if ($@) { |
|
561 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
|
cleanup
|
562 |
. qq{$query->{sql}\n} . _subname); |
improved error messages
|
563 |
} |
cleanup
|
564 |
|
improved debug message
|
565 |
# DEBUG message |
566 |
if (DEBUG) { |
|
567 |
print STDERR "SQL:\n" . $query->sql . "\n"; |
|
568 |
my @output; |
|
569 |
foreach my $b (@$bind) { |
|
570 |
my $value = $b->{value}; |
|
571 |
$value = 'undef' unless defined $value; |
|
572 |
$value = encode(DEBUG_ENCODING(), $value) |
|
573 |
if utf8::is_utf8($value); |
|
574 |
push @output, $value; |
|
575 |
} |
|
576 |
print STDERR "Bind values: " . join(', ', @output) . "\n\n"; |
|
577 |
} |
|
added environment variable D...
|
578 |
|
cleanup
|
579 |
# Select statement |
cleanup
|
580 |
if ($sth->{NUM_OF_FIELDS}) { |
581 |
|
|
cleanup
|
582 |
# Filter |
583 |
my $filter = {}; |
|
584 |
$filter->{in} = {}; |
|
585 |
$filter->{end} = {}; |
|
added DBIx::Custom result_fi...
|
586 |
push @$tables, $main_table if $main_table; |
cleanup
|
587 |
foreach my $table (@$tables) { |
cleanup
|
588 |
foreach my $way (qw/in end/) { |
589 |
$filter->{$way} = { |
|
590 |
%{$filter->{$way}}, |
|
591 |
%{$self->{filter}{$way}{$table} || {}} |
|
592 |
}; |
|
593 |
} |
|
cleanup
|
594 |
} |
595 |
|
|
596 |
# Result |
|
597 |
my $result = $self->result_class->new( |
|
added type_rule method and f...
|
598 |
sth => $sth, |
599 |
filters => $self->filters, |
|
cleanup
|
600 |
default_filter => $self->{default_in_filter}, |
added type_rule method and f...
|
601 |
filter => $filter->{in} || {}, |
602 |
end_filter => $filter->{end} || {}, |
|
603 |
type_rule => $self->type_rule, |
|
added EXPERIMENTAL execute()...
|
604 |
type_rule_off => $type_rule_off |
cleanup
|
605 |
); |
606 | ||
607 |
return $result; |
|
608 |
} |
|
cleanup
|
609 |
|
610 |
# Not select statement |
|
611 |
else { return $affected } |
|
cleanup
|
612 |
} |
613 | ||
insert_at is DEPRECATED! add...
|
614 |
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param/; |
update pod
|
615 | |
cleanup
|
616 |
sub insert { |
- insert, insert_at, update,...
|
617 |
my $self = shift; |
added EXPERIMENTAL reserved_...
|
618 |
|
cleanup
|
619 |
# Arguments |
- insert, insert_at, update,...
|
620 |
my $param; |
621 |
$param = shift if @_ % 2; |
|
622 |
my %args = @_; |
|
cleanup
|
623 |
my $table = delete $args{table}; |
cleanup
|
624 |
croak qq{"table" option must be specified } . _subname |
improved error messages
|
625 |
unless $table; |
- insert, insert_at, update,...
|
626 |
my $p = delete $args{param} || {}; |
627 |
$param ||= $p; |
|
cleanup
|
628 |
my $append = delete $args{append} || ''; |
insert_at is DEPRECATED! add...
|
629 |
my $id = delete $args{id}; |
630 |
my $primary_key = delete $args{primary_key}; |
|
cleanup
|
631 |
croak "insert method primary_key option " . |
added tests
|
632 |
"must be specified when id is specified " . _subname |
633 |
if defined $id && !defined $primary_key; |
|
insert_at is DEPRECATED! add...
|
634 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
cleanup
|
635 | |
636 |
# Check arguments |
|
637 |
foreach my $name (keys %args) { |
|
cleanup
|
638 |
croak qq{"$name" is wrong option } . _subname |
cleanup
|
639 |
unless $INSERT_ARGS{$name}; |
640 |
} |
|
641 | ||
insert_at is DEPRECATED! add...
|
642 |
# Merge parameter |
643 |
if ($id) { |
|
cleanup
|
644 |
my $id_param = $self->_create_param_from_id($id, $primary_key); |
insert_at is DEPRECATED! add...
|
645 |
$param = $self->merge_param($id_param, $param); |
646 |
} |
|
647 | ||
cleanup
|
648 |
# Reserved word quote |
649 |
my $q = $self->reserved_word_quote; |
|
cleanup
|
650 |
|
cleanup
|
651 |
# Insert statement |
cleanup
|
652 |
my @sql; |
- update_param_tag is DEPREC...
|
653 |
push @sql, "insert into $q$table$q " . $self->insert_param($param); |
cleanup
|
654 |
push @sql, $append if $append; |
655 |
my $sql = join (' ', @sql); |
|
packaging one directory
|
656 |
|
657 |
# Execute query |
|
cleanup
|
658 |
return $self->execute( |
cleanup
|
659 |
$sql, |
cleanup
|
660 |
param => $param, |
cleanup
|
661 |
table => $table, |
662 |
%args |
|
added auto_filter method
|
663 |
); |
packaging one directory
|
664 |
} |
665 | ||
- update_param_tag is DEPREC...
|
666 |
sub insert_param { |
remove experimental DBIx::Cu...
|
667 |
my ($self, $param) = @_; |
668 |
|
|
cleanup
|
669 |
# Create insert parameter tag |
- remaned experimental safty...
|
670 |
my $safety = $self->safety_character; |
added EXPERIMENTAL updat_par...
|
671 |
my $q = $self->reserved_word_quote; |
cleanup
|
672 |
my @columns; |
673 |
my @placeholders; |
|
remove experimental DBIx::Cu...
|
674 |
foreach my $column (keys %$param) { |
cleanup
|
675 |
croak qq{"$column" is not safety column name } . _subname |
- remaned experimental safty...
|
676 |
unless $column =~ /^[$safety\.]+$/; |
- update_param_tag is DEPREC...
|
677 |
my $column_quote = "$q$column$q"; |
678 |
$column_quote =~ s/\./$q.$q/; |
|
679 |
push @columns, $column_quote; |
|
680 |
push @placeholders, ":$column"; |
|
remove experimental DBIx::Cu...
|
681 |
} |
682 |
|
|
cleanup
|
683 |
return '(' . join(', ', @columns) . ') ' . 'values ' . |
684 |
'(' . join(', ', @placeholders) . ')' |
|
remove experimental DBIx::Cu...
|
685 |
} |
686 | ||
- added EXPERIMENTAL DBIx::C...
|
687 |
sub include_model { |
688 |
my ($self, $name_space, $model_infos) = @_; |
|
689 |
|
|
cleanup
|
690 |
# Name space |
- added EXPERIMENTAL DBIx::C...
|
691 |
$name_space ||= ''; |
cleanup
|
692 |
|
693 |
# Get Model infomations |
|
- added EXPERIMENTAL DBIx::C...
|
694 |
unless ($model_infos) { |
cleanup
|
695 | |
- added EXPERIMENTAL DBIx::C...
|
696 |
# Load name space module |
cleanup
|
697 |
croak qq{"$name_space" is invalid class name } . _subname |
- added EXPERIMENTAL DBIx::C...
|
698 |
if $name_space =~ /[^\w:]/; |
699 |
eval "use $name_space"; |
|
cleanup
|
700 |
croak qq{Name space module "$name_space.pm" is needed. $@ } |
701 |
. _subname |
|
improved error messages
|
702 |
if $@; |
- added EXPERIMENTAL DBIx::C...
|
703 |
|
704 |
# Search model modules |
|
705 |
my $path = $INC{"$name_space.pm"}; |
|
706 |
$path =~ s/\.pm$//; |
|
707 |
opendir my $dh, $path |
|
cleanup
|
708 |
or croak qq{Can't open directory "$path": $! } . _subname |
- added EXPERIMENTAL DBIx::C...
|
709 |
$model_infos = []; |
710 |
while (my $module = readdir $dh) { |
|
711 |
push @$model_infos, $module |
|
712 |
if $module =~ s/\.pm$//; |
|
713 |
} |
|
714 |
close $dh; |
|
715 |
} |
|
716 |
|
|
cleanup
|
717 |
# Include models |
- added EXPERIMENTAL DBIx::C...
|
718 |
foreach my $model_info (@$model_infos) { |
719 |
|
|
cleanup
|
720 |
# Load model |
- added EXPERIMENTAL DBIx::C...
|
721 |
my $model_class; |
722 |
my $model_name; |
|
723 |
my $model_table; |
|
724 |
if (ref $model_info eq 'HASH') { |
|
725 |
$model_class = $model_info->{class}; |
|
726 |
$model_name = $model_info->{name}; |
|
727 |
$model_table = $model_info->{table}; |
|
728 |
|
|
729 |
$model_name ||= $model_class; |
|
730 |
$model_table ||= $model_name; |
|
731 |
} |
|
removed EXPERIMETNAL flag fr...
|
732 |
else { $model_class = $model_name = $model_table = $model_info } |
- added EXPERIMENTAL DBIx::C...
|
733 |
my $mclass = "${name_space}::$model_class"; |
cleanup
|
734 |
croak qq{"$mclass" is invalid class name } . _subname |
- added EXPERIMENTAL DBIx::C...
|
735 |
if $mclass =~ /[^\w:]/; |
736 |
unless ($mclass->can('isa')) { |
|
737 |
eval "use $mclass"; |
|
cleanup
|
738 |
croak "$@ " . _subname if $@; |
- added EXPERIMENTAL DBIx::C...
|
739 |
} |
740 |
|
|
cleanup
|
741 |
# Create model |
removed EXPERIMETNAL flag fr...
|
742 |
my $args = {}; |
743 |
$args->{model_class} = $mclass if $mclass; |
|
744 |
$args->{name} = $model_name if $model_name; |
|
745 |
$args->{table} = $model_table if $model_table; |
|
746 |
$self->create_model($args); |
|
- added EXPERIMENTAL DBIx::C...
|
747 |
} |
748 |
|
|
749 |
return $self; |
|
750 |
} |
|
751 | ||
added EXPERIMENTAL updat_par...
|
752 |
sub merge_param { |
753 |
my ($self, @params) = @_; |
|
754 |
|
|
cleanup
|
755 |
# Merge parameters |
fixed merge_param bug
|
756 |
my $merge = {}; |
757 |
foreach my $param (@params) { |
|
758 |
foreach my $column (keys %$param) { |
|
759 |
my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0; |
|
760 |
|
|
761 |
if (exists $merge->{$column}) { |
|
762 |
$merge->{$column} = [$merge->{$column}] |
|
763 |
unless ref $merge->{$column} eq 'ARRAY'; |
|
764 |
push @{$merge->{$column}}, |
|
765 |
ref $param->{$column} ? @{$param->{$column}} : $param->{$column}; |
|
added EXPERIMENTAL updat_par...
|
766 |
} |
767 |
else { |
|
fixed merge_param bug
|
768 |
$merge->{$column} = $param->{$column}; |
added EXPERIMENTAL updat_par...
|
769 |
} |
770 |
} |
|
771 |
} |
|
772 |
|
|
fixed merge_param bug
|
773 |
return $merge; |
added EXPERIMENTAL updat_par...
|
774 |
} |
775 | ||
cleanup
|
776 |
sub method { |
777 |
my $self = shift; |
|
778 |
|
|
cleanup
|
779 |
# Register method |
cleanup
|
780 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
781 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
782 |
|
|
783 |
return $self; |
|
784 |
} |
|
785 | ||
- added EXPERIMENTAL DBIx::C...
|
786 |
sub model { |
787 |
my ($self, $name, $model) = @_; |
|
788 |
|
|
cleanup
|
789 |
# Set model |
- added EXPERIMENTAL DBIx::C...
|
790 |
if ($model) { |
791 |
$self->models->{$name} = $model; |
|
792 |
return $self; |
|
793 |
} |
|
794 |
|
|
795 |
# Check model existance |
|
cleanup
|
796 |
croak qq{Model "$name" is not included } . _subname |
- added EXPERIMENTAL DBIx::C...
|
797 |
unless $self->models->{$name}; |
798 |
|
|
cleanup
|
799 |
# Get model |
- added EXPERIMENTAL DBIx::C...
|
800 |
return $self->models->{$name}; |
801 |
} |
|
802 | ||
cleanup
|
803 |
sub mycolumn { |
804 |
my ($self, $table, $columns) = @_; |
|
805 |
|
|
cleanup
|
806 |
# Create column clause |
807 |
my @column; |
|
added EXPERIMENTAL reserved_...
|
808 |
my $q = $self->reserved_word_quote; |
cleanup
|
809 |
$columns ||= []; |
added EXPERIMENTAL reserved_...
|
810 |
push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns; |
cleanup
|
811 |
|
812 |
return join (', ', @column); |
|
813 |
} |
|
814 | ||
added dbi_options attribute
|
815 |
sub new { |
816 |
my $self = shift->SUPER::new(@_); |
|
817 |
|
|
cleanup
|
818 |
# Check attributes |
added dbi_options attribute
|
819 |
my @attrs = keys %$self; |
820 |
foreach my $attr (@attrs) { |
|
cleanup
|
821 |
croak qq{"$attr" is wrong name } . _subname |
added dbi_options attribute
|
822 |
unless $self->can($attr); |
823 |
} |
|
cleanup
|
824 |
|
set reserved_word_quote auto...
|
825 |
# DEPRECATED! |
fixed DEPRECATED messages
|
826 |
$self->query_builder->{tags} = { |
cleanup
|
827 |
'?' => \&DBIx::Custom::Tag::placeholder, |
828 |
'=' => \&DBIx::Custom::Tag::equal, |
|
829 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
830 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
831 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
832 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
833 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
834 |
'like' => \&DBIx::Custom::Tag::like, |
|
835 |
'in' => \&DBIx::Custom::Tag::in, |
|
836 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
837 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
fixed DEPRECATED messages
|
838 |
}; |
added dbi_options attribute
|
839 |
|
840 |
return $self; |
|
841 |
} |
|
842 | ||
added experimental not_exist...
|
843 |
sub not_exists { bless {}, 'DBIx::Custom::NotExists' } |
844 | ||
cleanup
|
845 |
sub register_filter { |
cleanup
|
846 |
my $self = shift; |
cleanup
|
847 |
|
848 |
# Register filter |
|
849 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
cleanup
|
850 |
$self->filters({%{$self->filters}, %$filters}); |
cleanup
|
851 |
|
cleanup
|
852 |
return $self; |
cleanup
|
853 |
} |
packaging one directory
|
854 | |
cleanup
|
855 |
our %SELECT_ARGS |
added EXPERIMENTAL select() ...
|
856 |
= map { $_ => 1 } @COMMON_ARGS, |
insert_at is DEPRECATED! add...
|
857 |
qw/column where relation join param where_param wrap/; |
refactoring select
|
858 | |
packaging one directory
|
859 |
sub select { |
select, insert, update, upda...
|
860 |
my ($self, %args) = @_; |
added EXPERIMENTAL reserved_...
|
861 | |
refactoring select
|
862 |
# Arguments |
cleanup
|
863 |
my $table = delete $args{table}; |
added table not specified ex...
|
864 |
my $tables = ref $table eq 'ARRAY' ? $table |
865 |
: defined $table ? [$table] |
|
866 |
: []; |
|
cleanup
|
867 |
my $columns = delete $args{column}; |
868 |
my $where = delete $args{where} || {}; |
|
869 |
my $append = delete $args{append}; |
|
870 |
my $join = delete $args{join} || []; |
|
cleanup
|
871 |
croak qq{"join" must be array reference } . _subname |
- added experimental DBIx::C...
|
872 |
unless ref $join eq 'ARRAY'; |
cleanup
|
873 |
my $relation = delete $args{relation}; |
added warnings
|
874 |
warn "select() relation option is DEPRECATED! use join option instead" |
875 |
if $relation; |
|
DEPRECATED select() param op...
|
876 |
my $param = delete $args{param} || {}; # DEPRECATED! |
added warnings
|
877 |
warn "select() param option is DEPRECATED! use where_param option instead" |
DEPRECATED select() param op...
|
878 |
if keys %$param; |
879 |
my $where_param = delete $args{where_param} || $param || {}; |
|
added EXPERIMENTAL select() ...
|
880 |
my $wrap = delete $args{wrap}; |
select_at is DEPRECATED! use...
|
881 |
my $id = delete $args{id}; |
882 |
my $primary_key = delete $args{primary_key}; |
|
883 |
croak "update method primary_key option " . |
|
884 |
"must be specified when id is specified " . _subname |
|
885 |
if defined $id && !defined $primary_key; |
|
886 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
887 |
|
|
cleanup
|
888 |
# Check arguments |
889 |
foreach my $name (keys %args) { |
|
cleanup
|
890 |
croak qq{"$name" is wrong option } . _subname |
cleanup
|
891 |
unless $SELECT_ARGS{$name}; |
892 |
} |
|
remove experimental DBIx::Cu...
|
893 |
|
cleanup
|
894 |
# Add relation tables(DEPRECATED!); |
cleanup
|
895 |
$self->_add_relation_table($tables, $relation); |
packaging one directory
|
896 |
|
cleanup
|
897 |
# Select statement |
cleanup
|
898 |
my @sql; |
899 |
push @sql, 'select'; |
|
packaging one directory
|
900 |
|
- select() column option can...
|
901 |
# Reserved word quote |
902 |
my $q = $self->reserved_word_quote; |
|
903 |
|
|
removed EXPERIMETNAL select(...
|
904 |
# Column clause |
cleanup
|
905 |
if ($columns) { |
- select() column option can...
|
906 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
removed EXPERIMETNAL select(...
|
907 |
foreach my $column (@$columns) { |
- select() column option can...
|
908 |
if (ref $column eq 'HASH') { |
909 |
$column = $self->col(%$column) if ref $column eq 'HASH'; |
|
910 |
} |
|
911 |
elsif (ref $column eq 'ARRAY') { |
|
912 |
croak "Format must be [COLUMN, as => ALIAS] " . _subname |
|
913 |
unless @$column == 3 && $column->[1] eq 'as'; |
|
914 |
$column = join(' ', $column->[0], 'as', $q . $column->[2] . $q); |
|
915 |
} |
|
cleanup
|
916 |
unshift @$tables, @{$self->_search_tables($column)}; |
removed EXPERIMETNAL select(...
|
917 |
push @sql, ($column, ','); |
added select() all_column op...
|
918 |
} |
removed EXPERIMETNAL select(...
|
919 |
pop @sql if $sql[-1] eq ','; |
added select() all_column op...
|
920 |
} |
921 |
else { push @sql, '*' } |
|
922 |
|
|
923 |
# Table |
|
cleanup
|
924 |
push @sql, 'from'; |
925 |
if ($relation) { |
|
926 |
my $found = {}; |
|
927 |
foreach my $table (@$tables) { |
|
added EXPERIMENTAL reserved_...
|
928 |
push @sql, ("$q$table$q", ',') unless $found->{$table}; |
cleanup
|
929 |
$found->{$table} = 1; |
- added EXPERIMENTAL DBIx::C...
|
930 |
} |
packaging one directory
|
931 |
} |
cleanup
|
932 |
else { |
933 |
my $main_table = $tables->[-1] || ''; |
|
added EXPERIMENTAL reserved_...
|
934 |
push @sql, "$q$main_table$q"; |
cleanup
|
935 |
} |
936 |
pop @sql if ($sql[-1] || '') eq ','; |
|
cleanup
|
937 |
croak "Not found table name " . _subname |
improved error messages
|
938 |
unless $tables->[-1]; |
cleanup
|
939 | |
cleanup
|
940 |
# Add tables in parameter |
DEPRECATED select() param op...
|
941 |
unshift @$tables, |
942 |
@{$self->_search_tables(join(' ', keys %$where_param) || '')}; |
|
fixed some select() join opi...
|
943 |
|
select() where can't receive...
|
944 |
# Where |
select, update, and delete w...
|
945 |
my $where_clause = ''; |
select_at is DEPRECATED! use...
|
946 |
$where = $self->_create_param_from_id($id, $primary_key) if $id; |
cleanup
|
947 |
if (ref $where) { |
948 |
$where = $self->_where_to_obj($where); |
|
DEPRECATED select() param op...
|
949 |
$where_param = keys %$where_param |
950 |
? $self->merge_param($where_param, $where->param) |
|
951 |
: $where->param; |
|
cleanup
|
952 |
|
953 |
# String where |
|
954 |
$where_clause = $where->to_string; |
|
955 |
} |
|
select, update, and delete w...
|
956 |
elsif ($where) { $where_clause = "where $where" } |
remove experimental DBIx::Cu...
|
957 |
|
fixed some select() join opi...
|
958 |
# Add table names in where clause |
cleanup
|
959 |
unshift @$tables, @{$self->_search_tables($where_clause)}; |
remove experimental DBIx::Cu...
|
960 |
|
fixed some select() join opi...
|
961 |
# Push join |
962 |
$self->_push_join(\@sql, $join, $tables); |
|
remove experimental DBIx::Cu...
|
963 |
|
cleanup
|
964 |
# Add where clause |
cleanup
|
965 |
push @sql, $where_clause; |
select() where can't receive...
|
966 |
|
cleanup
|
967 |
# Relation(DEPRECATED!); |
cleanup
|
968 |
$self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0); |
cleanup
|
969 |
|
cleanup
|
970 |
# Append |
cleanup
|
971 |
push @sql, $append if $append; |
972 |
|
|
added EXPERIMENTAL select() ...
|
973 |
# Wrap |
974 |
if ($wrap) { |
|
cleanup
|
975 |
croak "wrap option must be array refrence " . _subname |
added EXPERIMENTAL select() ...
|
976 |
unless ref $wrap eq 'ARRAY'; |
977 |
unshift @sql, $wrap->[0]; |
|
978 |
push @sql, $wrap->[1]; |
|
979 |
} |
|
980 |
|
|
cleanup
|
981 |
# SQL |
982 |
my $sql = join (' ', @sql); |
|
packaging one directory
|
983 |
|
984 |
# Execute query |
|
added auto_filter method
|
985 |
my $result = $self->execute( |
cleanup
|
986 |
$sql, |
DEPRECATED select() param op...
|
987 |
param => $where_param, |
cleanup
|
988 |
table => $tables, |
989 |
%args |
|
990 |
); |
|
packaging one directory
|
991 |
|
992 |
return $result; |
|
993 |
} |
|
994 | ||
add experimental setup_model...
|
995 |
sub setup_model { |
996 |
my $self = shift; |
|
997 |
|
|
cleanup
|
998 |
# Setup model |
add experimental setup_model...
|
999 |
$self->each_column( |
1000 |
sub { |
|
1001 |
my ($self, $table, $column, $column_info) = @_; |
|
1002 |
if (my $model = $self->models->{$table}) { |
|
1003 |
push @{$model->columns}, $column; |
|
1004 |
} |
|
1005 |
} |
|
1006 |
); |
|
add experimental DBIx::Custo...
|
1007 |
return $self; |
add experimental setup_model...
|
1008 |
} |
1009 | ||
simplify type_rule
|
1010 |
sub available_data_type { |
1011 |
my $self = shift; |
|
1012 |
|
|
changed type_rule arguments ...
|
1013 |
my $data_types = ''; |
simplify type_rule
|
1014 |
foreach my $i (-1000 .. 1000) { |
1015 |
my $type_info = $self->dbh->type_info($i); |
|
1016 |
my $data_type = $type_info->{DATA_TYPE}; |
|
1017 |
my $type_name = $type_info->{TYPE_NAME}; |
|
1018 |
$data_types .= "$data_type ($type_name)\n" |
|
1019 |
if defined $data_type; |
|
1020 |
} |
|
changed type_rule arguments ...
|
1021 |
return "Data Type maybe equal to Type Name" unless $data_types; |
1022 |
$data_types = "Data Type (Type name)\n" . $data_types; |
|
simplify type_rule
|
1023 |
return $data_types; |
1024 |
} |
|
1025 | ||
added type_rule method and f...
|
1026 |
sub type_rule { |
1027 |
my $self = shift; |
|
1028 |
|
|
1029 |
if (@_) { |
|
changed type_rule arguments ...
|
1030 |
my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
fixed bug that type_rule fro...
|
1031 |
|
1032 |
# Into |
|
changed type_rule arguments ...
|
1033 |
$type_rule->{into} = _array_to_hash($type_rule->{into}); |
added type_rule method and f...
|
1034 |
$self->{type_rule} = $type_rule; |
added type_rule into logic
|
1035 |
$self->{_into} ||= {}; |
1036 |
$self->each_column(sub { |
|
1037 |
my ($dbi, $table, $column, $column_info) = @_; |
|
1038 |
|
|
fixed bug that type_rule fro...
|
1039 |
my $type_name = $column_info->{TYPE_NAME}; |
changed type_rule arguments ...
|
1040 |
if ($type_rule->{into} && |
fixed bug that type_rule fro...
|
1041 |
(my $filter = $type_rule->{into}->{$type_name})) |
added type_rule into logic
|
1042 |
{ |
fixed bug that type_rule fro...
|
1043 |
return unless exists $type_rule->{into}->{$type_name}; |
type_rule can receive filter...
|
1044 |
if (defined $filter && ref $filter ne 'CODE') |
1045 |
{ |
|
1046 |
my $fname = $filter; |
|
1047 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
1048 |
unless exists $self->filters->{$fname}; |
|
1049 |
|
|
1050 |
$filter = $self->filters->{$fname}; |
|
1051 |
} |
|
1052 | ||
1053 |
$self->{_into}{$table}{$column} = $filter; |
|
added type_rule into logic
|
1054 |
} |
1055 |
}); |
|
added type_rule method and f...
|
1056 |
|
fixed bug that type_rule fro...
|
1057 | |
1058 |
# From |
|
1059 |
$type_rule->{from} = _array_to_hash($type_rule->{from}); |
|
1060 |
foreach my $data_type (keys %{$type_rule->{from} || {}}) { |
|
1061 |
my $fname = $type_rule->{from}{$data_type}; |
|
1062 |
if (defined $fname && ref $fname ne 'CODE') { |
|
1063 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
1064 |
unless exists $self->filters->{$fname}; |
|
1065 |
|
|
1066 |
$type_rule->{from}{$data_type} = $self->filters->{$fname}; |
|
1067 |
} |
|
1068 |
} |
|
1069 |
|
|
added type_rule method and f...
|
1070 |
return $self; |
1071 |
} |
|
1072 |
|
|
1073 |
return $self->{type_rule} || {}; |
|
1074 |
} |
|
1075 | ||
cleanup
|
1076 |
our %UPDATE_ARGS |
insert_at is DEPRECATED! add...
|
1077 |
= map { $_ => 1 } @COMMON_ARGS, qw/param where allow_update_all where_param/; |
cleanup
|
1078 | |
1079 |
sub update { |
|
- insert, insert_at, update,...
|
1080 |
my $self = shift; |
added EXPERIMENTAL reserved_...
|
1081 | |
cleanup
|
1082 |
# Arguments |
- insert, insert_at, update,...
|
1083 |
my $param; |
1084 |
$param = shift if @_ % 2; |
|
1085 |
my %args = @_; |
|
cleanup
|
1086 |
my $table = delete $args{table} || ''; |
cleanup
|
1087 |
croak qq{"table" option must be specified } . _subname |
improved error messages
|
1088 |
unless $table; |
- insert, insert_at, update,...
|
1089 |
my $p = delete $args{param} || {}; |
1090 |
$param ||= $p; |
|
cleanup
|
1091 |
my $where = delete $args{where} || {}; |
DEPRECATED select() param op...
|
1092 |
my $where_param = delete $args{where_param} || {}; |
cleanup
|
1093 |
my $append = delete $args{append} || ''; |
1094 |
my $allow_update_all = delete $args{allow_update_all}; |
|
cleanup
|
1095 |
my $id = delete $args{id}; |
1096 |
my $primary_key = delete $args{primary_key}; |
|
1097 |
croak "update method primary_key option " . |
|
1098 |
"must be specified when id is specified " . _subname |
|
1099 |
if defined $id && !defined $primary_key; |
|
1100 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
version 0.0901
|
1101 |
|
cleanup
|
1102 |
# Check argument names |
1103 |
foreach my $name (keys %args) { |
|
cleanup
|
1104 |
croak qq{"$name" is wrong option } . _subname |
cleanup
|
1105 |
unless $UPDATE_ARGS{$name}; |
1106 |
} |
|
update_at is DEPRECATED! use...
|
1107 | |
cleanup
|
1108 |
# Update clause |
- update_param_tag is DEPREC...
|
1109 |
my $update_clause = $self->update_param($param); |
improved delete() and update...
|
1110 | |
1111 |
# Where |
|
update_at is DEPRECATED! use...
|
1112 |
$where = $self->_create_param_from_id($id, $primary_key) if $id; |
select, update, and delete w...
|
1113 |
my $where_clause = ''; |
1114 |
if (ref $where) { |
|
1115 |
$where = $self->_where_to_obj($where); |
|
DEPRECATED select() param op...
|
1116 |
$where_param = keys %$where_param |
1117 |
? $self->merge_param($where_param, $where->param) |
|
1118 |
: $where->param; |
|
select, update, and delete w...
|
1119 |
|
1120 |
# String where |
|
1121 |
$where_clause = $where->to_string; |
|
1122 |
} |
|
1123 |
elsif ($where) { $where_clause = "where $where" } |
|
cleanup
|
1124 |
croak qq{"where" must be specified } . _subname |
cleanup
|
1125 |
if "$where_clause" eq '' && !$allow_update_all; |
removed reconnect method
|
1126 |
|
DEPRECATED select() param op...
|
1127 |
# Merge param |
1128 |
$param = $self->merge_param($param, $where_param) if keys %$where_param; |
|
1129 |
|
|
cleanup
|
1130 |
# Update statement |
cleanup
|
1131 |
my @sql; |
- update_param_tag is DEPREC...
|
1132 |
my $q = $self->reserved_word_quote; |
cleanup
|
1133 |
push @sql, "update $q$table$q $update_clause $where_clause"; |
cleanup
|
1134 |
push @sql, $append if $append; |
removed reconnect method
|
1135 |
|
cleanup
|
1136 |
# SQL |
1137 |
my $sql = join(' ', @sql); |
|
1138 |
|
|
cleanup
|
1139 |
# Execute query |
cleanup
|
1140 |
my $ret_val = $self->execute( |
cleanup
|
1141 |
$sql, |
cleanup
|
1142 |
param => $param, |
1143 |
table => $table, |
|
1144 |
%args |
|
1145 |
); |
|
cleanup
|
1146 |
|
1147 |
return $ret_val; |
|
removed reconnect method
|
1148 |
} |
1149 | ||
cleanup
|
1150 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
1151 | ||
- update_param_tag is DEPREC...
|
1152 |
sub update_param { |
added EXPERIMENTAL updat_par...
|
1153 |
my ($self, $param, $opt) = @_; |
1154 |
|
|
cleanup
|
1155 |
# Create update parameter tag |
- update_param_tag is DEPREC...
|
1156 |
my $tag = $self->assign_param($param); |
added EXPERIMENTAL assign_ta...
|
1157 |
$tag = "set $tag" unless $opt->{no_set}; |
1158 | ||
cleanup
|
1159 |
return $tag; |
remove experimental DBIx::Cu...
|
1160 |
} |
1161 | ||
cleanup
|
1162 |
sub where { |
select() where can't receive...
|
1163 |
my $self = shift; |
cleanup
|
1164 |
|
1165 |
# Create where |
|
select() where can't receive...
|
1166 |
return DBIx::Custom::Where->new( |
1167 |
query_builder => $self->query_builder, |
|
- remaned experimental safty...
|
1168 |
safety_character => $self->safety_character, |
added EXPERIMENTAL reserved_...
|
1169 |
reserved_word_quote => $self->reserved_word_quote, |
cleanup
|
1170 |
@_ |
select() where can't receive...
|
1171 |
); |
cleanup
|
1172 |
} |
added experimental DBIx::Cus...
|
1173 | |
cleanup
|
1174 |
sub _create_bind_values { |
- added EXPERIMENTAL type() ...
|
1175 |
my ($self, $params, $columns, $filter, $type) = @_; |
removed reconnect method
|
1176 |
|
cleanup
|
1177 |
# Create bind values |
- added EXPERIMENTAL type() ...
|
1178 |
my $bind = []; |
removed reconnect method
|
1179 |
my $count = {}; |
added experimental not_exist...
|
1180 |
my $not_exists = {}; |
cleanup
|
1181 |
foreach my $column (@$columns) { |
removed reconnect method
|
1182 |
|
1183 |
# Value |
|
added experimental not_exist...
|
1184 |
my $value; |
1185 |
if(ref $params->{$column} eq 'ARRAY') { |
|
1186 |
my $i = $count->{$column} || 0; |
|
1187 |
$i += $not_exists->{$column} || 0; |
|
1188 |
my $found; |
|
1189 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
1190 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
1191 |
$not_exists->{$column}++; |
|
1192 |
} |
|
1193 |
else { |
|
1194 |
$value = $params->{$column}->[$k]; |
|
1195 |
$found = 1; |
|
1196 |
last |
|
1197 |
} |
|
1198 |
} |
|
1199 |
next unless $found; |
|
1200 |
} |
|
1201 |
else { $value = $params->{$column} } |
|
removed reconnect method
|
1202 |
|
cleanup
|
1203 |
# Filter |
1204 |
my $f = $filter->{$column} || $self->{default_out_filter} || ''; |
|
cleanup
|
1205 |
|
- added EXPERIMENTAL type() ...
|
1206 |
# Type |
1207 |
push @$bind, { |
|
1208 |
value => $f ? $f->($value) : $value, |
|
1209 |
type => $type->{$column} |
|
1210 |
}; |
|
removed reconnect method
|
1211 |
|
1212 |
# Count up |
|
1213 |
$count->{$column}++; |
|
1214 |
} |
|
1215 |
|
|
- added EXPERIMENTAL type() ...
|
1216 |
return $bind; |
removed reconnect method
|
1217 |
} |
1218 | ||
cleanup
|
1219 |
sub _create_param_from_id { |
1220 |
my ($self, $id, $primary_keys) = @_; |
|
improved error messages
|
1221 |
|
cleanup
|
1222 |
# Create parameter |
1223 |
my $param = {}; |
|
1224 |
if ($id) { |
|
1225 |
$id = [$id] unless ref $id; |
|
1226 |
croak qq{"id" must be constant value or array reference} |
|
improved error messages
|
1227 |
. " (" . (caller 1)[3] . ")" |
cleanup
|
1228 |
unless !ref $id || ref $id eq 'ARRAY'; |
1229 |
croak qq{"id" must contain values same count as primary key} |
|
improved error messages
|
1230 |
. " (" . (caller 1)[3] . ")" |
cleanup
|
1231 |
unless @$primary_keys eq @$id; |
improved error messages
|
1232 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
cleanup
|
1233 |
$param->{$primary_keys->[$i]} = $id->[$i]; |
improved error messages
|
1234 |
} |
1235 |
} |
|
1236 |
|
|
cleanup
|
1237 |
return $param; |
improved error messages
|
1238 |
} |
1239 | ||
EXPERIMETAL fork safety impl...
|
1240 |
sub _connect { |
1241 |
my $self = shift; |
|
1242 |
|
|
1243 |
# Attributes |
|
added warnings
|
1244 |
my $dsn = $self->data_source; |
1245 |
warn "data_source is DEPRECATED! use dsn instead\n"; |
|
1246 |
$dsn ||= $self->dsn; |
|
data_source is DEPRECATED! I...
|
1247 |
croak qq{"dsn" must be specified } . _subname |
1248 |
unless $dsn; |
|
EXPERIMETAL fork safety impl...
|
1249 |
my $user = $self->user; |
1250 |
my $password = $self->password; |
|
1251 |
my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}}; |
|
added warnings
|
1252 |
warn "dbi_options is DEPRECATED! use dbi_option instead\n" |
1253 |
if keys %{$self->dbi_options}; |
|
EXPERIMETAL fork safety impl...
|
1254 |
|
1255 |
# Connect |
|
1256 |
my $dbh = eval {DBI->connect( |
|
data_source is DEPRECATED! I...
|
1257 |
$dsn, |
EXPERIMETAL fork safety impl...
|
1258 |
$user, |
1259 |
$password, |
|
1260 |
{ |
|
1261 |
%{$self->default_dbi_option}, |
|
1262 |
%$dbi_option |
|
1263 |
} |
|
1264 |
)}; |
|
1265 |
|
|
1266 |
# Connect error |
|
cleanup
|
1267 |
croak "$@ " . _subname if $@; |
EXPERIMETAL fork safety impl...
|
1268 |
|
1269 |
return $dbh; |
|
1270 |
} |
|
1271 | ||
cleanup
|
1272 |
sub _croak { |
1273 |
my ($self, $error, $append) = @_; |
|
cleanup
|
1274 |
|
1275 |
# Append |
|
cleanup
|
1276 |
$append ||= ""; |
1277 |
|
|
1278 |
# Verbose |
|
1279 |
if ($Carp::Verbose) { croak $error } |
|
1280 |
|
|
1281 |
# Not verbose |
|
1282 |
else { |
|
1283 |
|
|
1284 |
# Remove line and module infromation |
|
1285 |
my $at_pos = rindex($error, ' at '); |
|
1286 |
$error = substr($error, 0, $at_pos); |
|
1287 |
$error =~ s/\s+$//; |
|
1288 |
croak "$error$append"; |
|
1289 |
} |
|
1290 |
} |
|
1291 | ||
added select() all_column op...
|
1292 |
sub _need_tables { |
1293 |
my ($self, $tree, $need_tables, $tables) = @_; |
|
1294 |
|
|
cleanup
|
1295 |
# Get needed tables |
added select() all_column op...
|
1296 |
foreach my $table (@$tables) { |
1297 |
if ($tree->{$table}) { |
|
1298 |
$need_tables->{$table} = 1; |
|
1299 |
$self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}]) |
|
1300 |
} |
|
1301 |
} |
|
1302 |
} |
|
1303 | ||
fixed some select() join opi...
|
1304 |
sub _push_join { |
1305 |
my ($self, $sql, $join, $join_tables) = @_; |
|
1306 |
|
|
cleanup
|
1307 |
# No join |
fixed some select() join opi...
|
1308 |
return unless @$join; |
1309 |
|
|
cleanup
|
1310 |
# Push join clause |
fixed some select() join opi...
|
1311 |
my $tree = {}; |
cleanup
|
1312 |
my $q = $self->reserved_word_quote; |
fixed some select() join opi...
|
1313 |
for (my $i = 0; $i < @$join; $i++) { |
1314 |
|
|
cleanup
|
1315 |
# Search table in join clause |
fixed some select() join opi...
|
1316 |
my $join_clause = $join->[$i]; |
added EXPERIMENTAL reserved_...
|
1317 |
my $q_re = quotemeta($q); |
cleanup
|
1318 |
my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/ |
1319 |
: qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/; |
|
added EXPERIMENTAL reserved_...
|
1320 |
if ($join_clause =~ $join_re) { |
fixed some select() join opi...
|
1321 |
my $table1 = $1; |
1322 |
my $table2 = $2; |
|
cleanup
|
1323 |
croak qq{right side table of "$join_clause" must be unique } |
1324 |
. _subname |
|
fixed some select() join opi...
|
1325 |
if exists $tree->{$table2}; |
1326 |
$tree->{$table2} |
|
1327 |
= {position => $i, parent => $table1, join => $join_clause}; |
|
1328 |
} |
|
1329 |
else { |
|
cleanup
|
1330 |
croak qq{join "$join_clause" must be two table name } . _subname |
fixed some select() join opi...
|
1331 |
} |
1332 |
} |
|
1333 |
|
|
cleanup
|
1334 |
# Search need tables |
fixed some select() join opi...
|
1335 |
my $need_tables = {}; |
1336 |
$self->_need_tables($tree, $need_tables, $join_tables); |
|
1337 |
my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables; |
|
cleanup
|
1338 |
|
1339 |
# Add join clause |
|
fixed some select() join opi...
|
1340 |
foreach my $need_table (@need_tables) { |
1341 |
push @$sql, $tree->{$need_table}{join}; |
|
1342 |
} |
|
1343 |
} |
|
cleanup
|
1344 | |
cleanup
|
1345 |
sub _remove_duplicate_table { |
1346 |
my ($self, $tables, $main_table) = @_; |
|
1347 |
|
|
1348 |
# Remove duplicate table |
|
1349 |
my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables; |
|
1350 |
delete $tables{$main_table} if $main_table; |
|
1351 |
|
|
1352 |
return [keys %tables, $main_table ? $main_table : ()]; |
|
1353 |
} |
|
1354 | ||
cleanup
|
1355 |
sub _search_tables { |
cleanup
|
1356 |
my ($self, $source) = @_; |
1357 |
|
|
cleanup
|
1358 |
# Search tables |
cleanup
|
1359 |
my $tables = []; |
1360 |
my $safety_character = $self->safety_character; |
|
1361 |
my $q = $self->reserved_word_quote; |
|
1362 |
my $q_re = quotemeta($q); |
|
improved table search in col...
|
1363 |
my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./ |
1364 |
: qr/(?:^|[^$safety_character])([$safety_character]+)\./; |
|
cleanup
|
1365 |
while ($source =~ /$table_re/g) { |
1366 |
push @$tables, $1; |
|
1367 |
} |
|
1368 |
|
|
1369 |
return $tables; |
|
1370 |
} |
|
1371 | ||
cleanup
|
1372 |
sub _where_to_obj { |
where can recieve array refr...
|
1373 |
my ($self, $where) = @_; |
1374 |
|
|
cleanup
|
1375 |
my $obj; |
1376 |
|
|
1377 |
# Hash |
|
where can recieve array refr...
|
1378 |
if (ref $where eq 'HASH') { |
1379 |
my $clause = ['and']; |
|
added EXPERIMENTAL reserved_...
|
1380 |
my $q = $self->reserved_word_quote; |
1381 |
foreach my $column (keys %$where) { |
|
- update_param_tag is DEPREC...
|
1382 |
my $column_quote = "$q$column$q"; |
1383 |
$column_quote =~ s/\./$q.$q/; |
|
1384 |
push @$clause, "$column_quote = :$column" for keys %$where; |
|
added EXPERIMENTAL reserved_...
|
1385 |
} |
cleanup
|
1386 |
$obj = $self->where(clause => $clause, param => $where); |
where can recieve array refr...
|
1387 |
} |
cleanup
|
1388 |
|
1389 |
# DBIx::Custom::Where object |
|
where can recieve array refr...
|
1390 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
cleanup
|
1391 |
$obj = $where; |
where can recieve array refr...
|
1392 |
} |
cleanup
|
1393 |
|
1394 |
# Array(DEPRECATED!) |
|
where can recieve array refr...
|
1395 |
elsif (ref $where eq 'ARRAY') { |
removed EXPERIMETNAL select(...
|
1396 |
warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." . |
1397 |
"use \$dbi->select(where => \$dbi->where(clause => " . |
|
added warnings
|
1398 |
"CLAUSE, where_param => PARAMETER));"; |
cleanup
|
1399 |
$obj = $self->where( |
where can recieve array refr...
|
1400 |
clause => $where->[0], |
1401 |
param => $where->[1] |
|
1402 |
); |
|
1403 |
} |
|
1404 |
|
|
cleanup
|
1405 |
# Check where argument |
improved error messages
|
1406 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} |
1407 |
. qq{or array reference, which contains where clause and paramter} |
|
cleanup
|
1408 |
. _subname |
cleanup
|
1409 |
unless ref $obj eq 'DBIx::Custom::Where'; |
where can recieve array refr...
|
1410 |
|
cleanup
|
1411 |
return $obj; |
where can recieve array refr...
|
1412 |
} |
1413 | ||
select_at is DEPRECATED! use...
|
1414 |
# DEPRECATED! |
1415 |
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1); |
|
1416 |
sub select_at { |
|
1417 |
my ($self, %args) = @_; |
|
1418 | ||
updated pod
|
1419 |
warn "select_at is DEPRECATED! use update and id option instead"; |
1420 | ||
select_at is DEPRECATED! use...
|
1421 |
# Arguments |
1422 |
my $primary_keys = delete $args{primary_key}; |
|
1423 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
1424 |
my $where = delete $args{where}; |
|
1425 |
my $param = delete $args{param}; |
|
1426 |
|
|
1427 |
# Check arguments |
|
1428 |
foreach my $name (keys %args) { |
|
1429 |
croak qq{"$name" is wrong option } . _subname |
|
1430 |
unless $SELECT_AT_ARGS{$name}; |
|
1431 |
} |
|
1432 |
|
|
1433 |
# Table |
|
1434 |
croak qq{"table" option must be specified } . _subname |
|
1435 |
unless $args{table}; |
|
1436 |
my $table = ref $args{table} ? $args{table}->[-1] : $args{table}; |
|
1437 |
|
|
1438 |
# Create where parameter |
|
1439 |
my $where_param = $self->_create_param_from_id($where, $primary_keys); |
|
1440 |
|
|
1441 |
return $self->select(where => $where_param, %args); |
|
1442 |
} |
|
1443 | ||
delete_at is DEPRECATED! use...
|
1444 |
# DEPRECATED! |
1445 |
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1); |
|
1446 |
sub delete_at { |
|
1447 |
my ($self, %args) = @_; |
|
updated pod
|
1448 | |
1449 |
warn "delete_at is DEPRECATED! use update and id option instead"; |
|
delete_at is DEPRECATED! use...
|
1450 |
|
1451 |
# Arguments |
|
1452 |
my $primary_keys = delete $args{primary_key}; |
|
1453 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
1454 |
my $where = delete $args{where}; |
|
1455 |
|
|
1456 |
# Check arguments |
|
1457 |
foreach my $name (keys %args) { |
|
1458 |
croak qq{"$name" is wrong option } . _subname |
|
1459 |
unless $DELETE_AT_ARGS{$name}; |
|
1460 |
} |
|
1461 |
|
|
1462 |
# Create where parameter |
|
1463 |
my $where_param = $self->_create_param_from_id($where, $primary_keys); |
|
1464 |
|
|
1465 |
return $self->delete(where => $where_param, %args); |
|
1466 |
} |
|
1467 | ||
cleanup
|
1468 |
# DEPRECATED! |
1469 |
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1); |
|
1470 |
sub update_at { |
|
1471 |
my $self = shift; |
|
1472 | ||
1473 |
warn "update_at is DEPRECATED! use update and id option instead"; |
|
1474 |
|
|
1475 |
# Arguments |
|
1476 |
my $param; |
|
1477 |
$param = shift if @_ % 2; |
|
1478 |
my %args = @_; |
|
1479 |
my $primary_keys = delete $args{primary_key}; |
|
1480 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
1481 |
my $where = delete $args{where}; |
|
1482 |
my $p = delete $args{param} || {}; |
|
1483 |
$param ||= $p; |
|
1484 |
|
|
1485 |
# Check arguments |
|
1486 |
foreach my $name (keys %args) { |
|
1487 |
croak qq{"$name" is wrong option } . _subname |
|
1488 |
unless $UPDATE_AT_ARGS{$name}; |
|
1489 |
} |
|
1490 |
|
|
1491 |
# Create where parameter |
|
1492 |
my $where_param = $self->_create_param_from_id($where, $primary_keys); |
|
1493 |
|
|
1494 |
return $self->update(where => $where_param, param => $param, %args); |
|
1495 |
} |
|
1496 | ||
insert_at is DEPRECATED! add...
|
1497 |
# DEPRECATED! |
1498 |
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1); |
|
1499 |
sub insert_at { |
|
1500 |
my $self = shift; |
|
1501 |
|
|
1502 |
warn "insert_at is DEPRECATED! use insert and id option instead"; |
|
1503 |
|
|
1504 |
# Arguments |
|
1505 |
my $param; |
|
1506 |
$param = shift if @_ % 2; |
|
1507 |
my %args = @_; |
|
1508 |
my $primary_key = delete $args{primary_key}; |
|
1509 |
$primary_key = [$primary_key] unless ref $primary_key; |
|
1510 |
my $where = delete $args{where}; |
|
1511 |
my $p = delete $args{param} || {}; |
|
1512 |
$param ||= $p; |
|
1513 |
|
|
1514 |
# Check arguments |
|
1515 |
foreach my $name (keys %args) { |
|
1516 |
croak qq{"$name" is wrong option } . _subname |
|
1517 |
unless $INSERT_AT_ARGS{$name}; |
|
1518 |
} |
|
1519 |
|
|
1520 |
# Create where parameter |
|
cleanup
|
1521 |
my $where_param = $self->_create_param_from_id($where, $primary_key); |
insert_at is DEPRECATED! add...
|
1522 |
$param = $self->merge_param($where_param, $param); |
1523 |
|
|
1524 |
return $self->insert(param => $param, %args); |
|
1525 |
} |
|
1526 | ||
added warnings
|
1527 |
# DEPRECATED! |
1528 |
sub register_tag { |
|
1529 |
warn "register_tag is DEPRECATED!"; |
|
1530 |
shift->query_builder->register_tag(@_) |
|
1531 |
} |
|
1532 | ||
data_source is DEPRECATED! I...
|
1533 |
# DEPRECATED! |
1534 |
__PACKAGE__->attr('data_source'); |
|
1535 | ||
cleanup
|
1536 |
# DEPRECATED! |
cleanup
|
1537 |
__PACKAGE__->attr( |
1538 |
dbi_options => sub { {} }, |
|
1539 |
filter_check => 1 |
|
1540 |
); |
|
renamed dbi_options to dbi_o...
|
1541 | |
cleanup
|
1542 |
# DEPRECATED! |
cleanup
|
1543 |
sub default_bind_filter { |
1544 |
my $self = shift; |
|
1545 |
|
|
added warnings
|
1546 |
warn "default_bind_filter is DEPRECATED! use apply_filter instead\n"; |
1547 |
|
|
cleanup
|
1548 |
if (@_) { |
1549 |
my $fname = $_[0]; |
|
1550 |
|
|
1551 |
if (@_ && !$fname) { |
|
1552 |
$self->{default_out_filter} = undef; |
|
1553 |
} |
|
1554 |
else { |
|
many changed
|
1555 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1556 |
unless exists $self->filters->{$fname}; |
1557 |
|
|
1558 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
1559 |
} |
|
1560 |
return $self; |
|
1561 |
} |
|
1562 |
|
|
1563 |
return $self->{default_out_filter}; |
|
1564 |
} |
|
1565 | ||
cleanup
|
1566 |
# DEPRECATED! |
cleanup
|
1567 |
sub default_fetch_filter { |
1568 |
my $self = shift; |
|
added warnings
|
1569 | |
1570 |
warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n"; |
|
cleanup
|
1571 |
|
1572 |
if (@_) { |
|
many changed
|
1573 |
my $fname = $_[0]; |
1574 | ||
cleanup
|
1575 |
if (@_ && !$fname) { |
1576 |
$self->{default_in_filter} = undef; |
|
1577 |
} |
|
1578 |
else { |
|
many changed
|
1579 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1580 |
unless exists $self->filters->{$fname}; |
1581 |
|
|
1582 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
1583 |
} |
|
1584 |
|
|
1585 |
return $self; |
|
1586 |
} |
|
1587 |
|
|
many changed
|
1588 |
return $self->{default_in_filter}; |
cleanup
|
1589 |
} |
1590 | ||
- renamed update_param to up...
|
1591 |
# DEPRECATED! |
- update_param_tag is DEPREC...
|
1592 |
sub insert_param_tag { |
1593 |
warn "insert_param_tag is DEPRECATED! " . |
|
1594 |
"use insert_param instead!"; |
|
1595 |
return shift->insert_param(@_); |
|
- renamed update_param to up...
|
1596 |
} |
1597 | ||
cleanup
|
1598 |
# DEPRECATED! |
renamed DBIx::Custom::TagPro...
|
1599 |
sub register_tag_processor { |
added warnings
|
1600 |
warn "register_tag_processor is DEPRECATED!"; |
renamed DBIx::Custom::TagPro...
|
1601 |
return shift->query_builder->register_tag_processor(@_); |
1602 |
} |
|
1603 | ||
- renamed update_param to up...
|
1604 |
# DEPRECATED! |
- update_param_tag is DEPREC...
|
1605 |
sub update_param_tag { |
fixed DEPRECATED message bug
|
1606 |
warn "update_param_tag is DEPRECATED! " . |
- update_param_tag is DEPREC...
|
1607 |
"use update_param instead"; |
1608 |
return shift->update_param(@_); |
|
- renamed update_param to up...
|
1609 |
} |
cleanup
|
1610 |
# DEPRECATED! |
1611 |
sub _push_relation { |
|
1612 |
my ($self, $sql, $tables, $relation, $need_where) = @_; |
|
1613 |
|
|
1614 |
if (keys %{$relation || {}}) { |
|
1615 |
push @$sql, $need_where ? 'where' : 'and'; |
|
1616 |
foreach my $rcolumn (keys %$relation) { |
|
1617 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1618 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1619 |
push @$tables, ($table1, $table2); |
|
1620 |
push @$sql, ("$rcolumn = " . $relation->{$rcolumn}, 'and'); |
|
1621 |
} |
|
1622 |
} |
|
1623 |
pop @$sql if $sql->[-1] eq 'and'; |
|
1624 |
} |
|
1625 | ||
1626 |
# DEPRECATED! |
|
1627 |
sub _add_relation_table { |
|
cleanup
|
1628 |
my ($self, $tables, $relation) = @_; |
cleanup
|
1629 |
|
1630 |
if (keys %{$relation || {}}) { |
|
1631 |
foreach my $rcolumn (keys %$relation) { |
|
1632 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1633 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1634 |
my $table1_exists; |
|
1635 |
my $table2_exists; |
|
1636 |
foreach my $table (@$tables) { |
|
1637 |
$table1_exists = 1 if $table eq $table1; |
|
1638 |
$table2_exists = 1 if $table eq $table2; |
|
1639 |
} |
|
1640 |
unshift @$tables, $table1 unless $table1_exists; |
|
1641 |
unshift @$tables, $table2 unless $table2_exists; |
|
1642 |
} |
|
1643 |
} |
|
1644 |
} |
|
1645 | ||
fixed DBIx::Custom::QueryBui...
|
1646 |
1; |
1647 | ||
removed reconnect method
|
1648 |
=head1 NAME |
1649 | ||
- remaned experimental safty...
|
1650 |
DBIx::Custom - Useful database access, respecting SQL! |
removed reconnect method
|
1651 | |
1652 |
=head1 SYNOPSYS |
|
cleanup
|
1653 | |
renamed build_query to creat...
|
1654 |
use DBIx::Custom; |
- remaned experimental safty...
|
1655 |
|
1656 |
# Connect |
|
1657 |
my $dbi = DBIx::Custom->connect( |
|
data_source is DEPRECATED! I...
|
1658 |
dsn => "dbi:mysql:database=dbname", |
- remaned experimental safty...
|
1659 |
user => 'ken', |
1660 |
password => '!LFKD%$&', |
|
1661 |
dbi_option => {mysql_enable_utf8 => 1} |
|
1662 |
); |
|
cleanup
|
1663 | |
removed reconnect method
|
1664 |
# Insert |
- remaned experimental safty...
|
1665 |
$dbi->insert( |
1666 |
table => 'book', |
|
1667 |
param => {title => 'Perl', author => 'Ken'} |
|
1668 |
); |
|
removed reconnect method
|
1669 |
|
1670 |
# Update |
|
- remaned experimental safty...
|
1671 |
$dbi->update( |
1672 |
table => 'book', |
|
1673 |
param => {title => 'Perl', author => 'Ken'}, |
|
1674 |
where => {id => 5}, |
|
1675 |
); |
|
removed reconnect method
|
1676 |
|
1677 |
# Delete |
|
- remaned experimental safty...
|
1678 |
$dbi->delete( |
1679 |
table => 'book', |
|
1680 |
where => {author => 'Ken'}, |
|
1681 |
); |
|
cleanup
|
1682 | |
removed reconnect method
|
1683 |
# Select |
renamed fetch_rows to fetch_...
|
1684 |
my $result = $dbi->select( |
added insert, update, update...
|
1685 |
table => 'book', |
update document
|
1686 |
where => {author => 'Ken'}, |
added commit method
|
1687 |
); |
cleanup
|
1688 | |
- remaned experimental safty...
|
1689 |
# Select, more complex |
1690 |
my $result = $dbi->select( |
|
1691 |
table => 'book', |
|
1692 |
column => [ |
|
1693 |
'book.author as book__author', |
|
1694 |
'company.name as company__name' |
|
1695 |
], |
|
1696 |
where => {'book.author' => 'Ken'}, |
|
1697 |
join => ['left outer join company on book.company_id = company.id'], |
|
1698 |
append => 'order by id limit 5' |
|
removed reconnect method
|
1699 |
); |
- remaned experimental safty...
|
1700 |
|
removed register_format()
|
1701 |
# Fetch |
1702 |
while (my $row = $result->fetch) { |
|
- remaned experimental safty...
|
1703 |
|
removed register_format()
|
1704 |
} |
1705 |
|
|
- remaned experimental safty...
|
1706 |
# Fetch as hash |
removed register_format()
|
1707 |
while (my $row = $result->fetch_hash) { |
1708 |
|
|
1709 |
} |
|
1710 |
|
|
- remaned experimental safty...
|
1711 |
# Execute SQL with parameter. |
1712 |
$dbi->execute( |
|
- update_param_tag is DEPREC...
|
1713 |
"select id from book where author = :author and title like :title", |
- remaned experimental safty...
|
1714 |
param => {author => 'ken', title => '%Perl%'} |
1715 |
); |
|
1716 |
|
|
renamed update tag to update...
|
1717 |
=head1 DESCRIPTIONS |
removed reconnect method
|
1718 | |
- remaned experimental safty...
|
1719 |
L<DBIx::Custom> is L<DBI> wrapper module. |
1720 | ||
1721 |
=head1 FEATURES |
|
removed reconnect method
|
1722 | |
- remaned experimental safty...
|
1723 |
=over 4 |
removed reconnect method
|
1724 | |
- remaned experimental safty...
|
1725 |
=item * |
removed reconnect method
|
1726 | |
- remaned experimental safty...
|
1727 |
There are many basic methods to execute various queries. |
1728 |
C<insert()>, C<update()>, C<update_all()>,C<delete()>, |
|
1729 |
C<delete_all()>, C<select()>, |
|
- select() column option can...
|
1730 |
C<execute()> |
removed reconnect method
|
1731 | |
- remaned experimental safty...
|
1732 |
=item * |
1733 | ||
1734 |
Filter when data is send or receive. |
|
1735 | ||
1736 |
=item * |
|
1737 | ||
1738 |
Data filtering system |
|
1739 | ||
1740 |
=item * |
|
1741 | ||
1742 |
Model support. |
|
1743 | ||
1744 |
=item * |
|
1745 | ||
1746 |
Generate where clause dinamically. |
|
1747 | ||
1748 |
=item * |
|
1749 | ||
1750 |
Generate join clause dinamically. |
|
1751 | ||
1752 |
=back |
|
pod fix
|
1753 | |
1754 |
=head1 GUIDE |
|
1755 | ||
- remaned experimental safty...
|
1756 |
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide |
pod fix
|
1757 | |
- remaned experimental safty...
|
1758 |
=head1 Wiki |
pod fix
|
1759 | |
- remaned experimental safty...
|
1760 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> |
updated document
|
1761 | |
update document
|
1762 |
=head1 ATTRIBUTES |
packaging one directory
|
1763 | |
- removed DEPRECATED DBIx::C...
|
1764 |
=head2 C<connector> |
- removed EXPERIMENTAL Prefo...
|
1765 | |
1766 |
my $connector = $dbi->connector; |
|
1767 |
$dbi = $dbi->connector(DBIx::Connector->new(...)); |
|
1768 | ||
1769 |
Connection manager object. if connector is set, you can get C<dbh()> |
|
1770 |
from connection manager. conection manager object must have dbh() mehtod. |
|
1771 | ||
1772 |
This is L<DBIx::Connector> example. Please pass |
|
1773 |
C<default_dbi_option> to L<DBIx::Connector>. |
|
1774 | ||
1775 |
my $connector = DBIx::Connector->new( |
|
1776 |
"dbi:mysql:database=$DATABASE", |
|
1777 |
$USER, |
|
1778 |
$PASSWORD, |
|
1779 |
DBIx::Custom->new->default_dbi_option |
|
1780 |
); |
|
1781 |
|
|
1782 |
my $dbi = DBIx::Custom->new(connector => $connector); |
|
1783 | ||
data_source is DEPRECATED! I...
|
1784 |
=head2 C<dsn> |
1785 | ||
1786 |
my $dsn = $dbi->dsn; |
|
1787 |
$dbi = $dbi->dsn("DBI:mysql:database=dbname"); |
|
packaging one directory
|
1788 | |
data_source is DEPRECATED! I...
|
1789 |
Data source name, used when C<connect()> is executed. |
removed DESTROY method(not b...
|
1790 | |
data_source is DEPRECATED! I...
|
1791 |
C<data_source> is DEPRECATED! It is renamed to C<dsn>. |
removed DESTROY method(not b...
|
1792 | |
renamed dbi_options to dbi_o...
|
1793 |
=head2 C<dbi_option> |
added dbi_options attribute
|
1794 | |
renamed dbi_options to dbi_o...
|
1795 |
my $dbi_option = $dbi->dbi_option; |
- remaned experimental safty...
|
1796 |
$dbi = $dbi->dbi_option($dbi_option); |
add default_dbi_option()
|
1797 | |
- remaned experimental safty...
|
1798 |
L<DBI> option, used when C<connect()> is executed. |
1799 |
Each value in option override the value of C<default_dbi_option>. |
|
add default_dbi_option()
|
1800 | |
1801 |
=head2 C<default_dbi_option> |
|
1802 | ||
1803 |
my $default_dbi_option = $dbi->default_dbi_option; |
|
1804 |
$dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1805 | ||
- remaned experimental safty...
|
1806 |
L<DBI> default option, used when C<connect()> is executed, |
1807 |
default to the following values. |
|
add default_dbi_option()
|
1808 | |
- remaned experimental safty...
|
1809 |
{ |
1810 |
RaiseError => 1, |
|
1811 |
PrintError => 0, |
|
1812 |
AutoCommit => 1, |
|
1813 |
} |
|
packaging one directory
|
1814 | |
update pod
|
1815 |
You should not change C<AutoCommit> value directly, |
1816 |
the value is used to check if the process is in transaction. |
|
EXPERIMETAL fork safety impl...
|
1817 | |
cleanup
|
1818 |
=head2 C<filters> |
bind_filter argument is chan...
|
1819 | |
cleanup
|
1820 |
my $filters = $dbi->filters; |
1821 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
1822 | |
- remaned experimental safty...
|
1823 |
Filters, registered by C<register_filter()>. |
add models() attribute
|
1824 | |
- removed DEPRECATED DBIx::C...
|
1825 |
=head2 C<models> |
add models() attribute
|
1826 | |
1827 |
my $models = $dbi->models; |
|
1828 |
$dbi = $dbi->models(\%models); |
|
1829 | ||
- remaned experimental safty...
|
1830 |
Models, included by C<include_model()>. |
add models() attribute
|
1831 | |
cleanup
|
1832 |
=head2 C<password> |
1833 | ||
1834 |
my $password = $dbi->password; |
|
1835 |
$dbi = $dbi->password('lkj&le`@s'); |
|
1836 | ||
- remaned experimental safty...
|
1837 |
Password, used when C<connect()> is executed. |
update document
|
1838 | |
renamed update tag to update...
|
1839 |
=head2 C<query_builder> |
added commit method
|
1840 | |
renamed update tag to update...
|
1841 |
my $sql_class = $dbi->query_builder; |
1842 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1843 | |
- remaned experimental safty...
|
1844 |
Query builder, default to L<DBIx::Custom::QueryBuilder> object. |
cleanup
|
1845 | |
- removed DEPRECATED DBIx::C...
|
1846 |
=head2 C<reserved_word_quote> |
added EXPERIMENTAL reserved_...
|
1847 | |
1848 |
my reserved_word_quote = $dbi->reserved_word_quote; |
|
1849 |
$dbi = $dbi->reserved_word_quote('"'); |
|
1850 | ||
cleanup
|
1851 |
Reserved word quote, default to empty string. |
added EXPERIMENTAL reserved_...
|
1852 | |
cleanup
|
1853 |
=head2 C<result_class> |
cleanup
|
1854 | |
cleanup
|
1855 |
my $result_class = $dbi->result_class; |
1856 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
1857 | |
- remaned experimental safty...
|
1858 |
Result class, default to L<DBIx::Custom::Result>. |
cleanup
|
1859 | |
removed EXPERIMETNAL flag fr...
|
1860 |
=head2 C<safety_character> |
update pod
|
1861 | |
- remaned experimental safty...
|
1862 |
my $safety_character = $self->safety_character; |
cleanup
|
1863 |
$dbi = $self->safety_character($character); |
update pod
|
1864 | |
update pod
|
1865 |
Regex of safety character for table and column name, default to '\w'. |
cleanup
|
1866 |
Note that you don't have to specify like '[\w]'. |
update pod
|
1867 | |
cleanup
|
1868 |
=head2 C<user> |
cleanup
|
1869 | |
cleanup
|
1870 |
my $user = $dbi->user; |
1871 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
1872 | |
cleanup
|
1873 |
User name, used when C<connect()> is executed. |
update pod
|
1874 | |
cleanup
|
1875 |
=head1 METHODS |
added commit method
|
1876 | |
cleanup
|
1877 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
cleanup
|
1878 |
and use all methods of L<DBI> |
cleanup
|
1879 |
and implements the following new ones. |
added check_filter attribute
|
1880 | |
changed type_rule arguments ...
|
1881 |
=head2 C<available_data_type> EXPERIMENTAL |
1882 | ||
1883 |
print $dbi->available_data_type; |
|
1884 | ||
1885 |
Get available data type. |
|
1886 | ||
- removed DEPRECATED DBIx::C...
|
1887 |
=head2 C<apply_filter> |
added auto_filter method
|
1888 | |
renamed auto_filter to apply...
|
1889 |
$dbi->apply_filter( |
cleanup
|
1890 |
'book', |
update pod
|
1891 |
'issue_date' => { |
1892 |
out => 'tp_to_date', |
|
1893 |
in => 'date_to_tp', |
|
1894 |
end => 'tp_to_displaydate' |
|
1895 |
}, |
|
1896 |
'write_date' => { |
|
1897 |
out => 'tp_to_date', |
|
1898 |
in => 'date_to_tp', |
|
1899 |
end => 'tp_to_displaydate' |
|
1900 |
} |
|
added auto_filter method
|
1901 |
); |
1902 | ||
update pod
|
1903 |
Apply filter to columns. |
1904 |
C<out> filter is executed before data is send to database. |
|
1905 |
C<in> filter is executed after a row is fetch. |
|
1906 |
C<end> filter is execute after C<in> filter is executed. |
|
1907 | ||
1908 |
Filter is applied to the follwoing tree column name pattern. |
|
cleanup
|
1909 | |
update pod
|
1910 |
PETTERN EXAMPLE |
1911 |
1. Column : author |
|
1912 |
2. Table.Column : book.author |
|
1913 |
3. Table__Column : book__author |
|
fix bug : filter can't over...
|
1914 | |
update pod
|
1915 |
If column name is duplicate with other table, |
1916 |
Main filter specified by C<table> option is used. |
|
1917 | ||
1918 |
You can set multiple filters at once. |
|
1919 | ||
1920 |
$dbi->apply_filter( |
|
1921 |
'book', |
|
1922 |
[qw/issue_date write_date/] => { |
|
1923 |
out => 'tp_to_date', |
|
1924 |
in => 'date_to_tp', |
|
1925 |
end => 'tp_to_displaydate' |
|
1926 |
} |
|
1927 |
); |
|
fix bug : filter can't over...
|
1928 | |
- update_param_tag is DEPREC...
|
1929 |
=head2 C<assign_param> EXPERIMENTAL |
added EXPERIMENTAL assign_ta...
|
1930 | |
- update_param_tag is DEPREC...
|
1931 |
my $assign_param = $dbi->assign_param({title => 'a', age => 2}); |
added EXPERIMENTAL assign_ta...
|
1932 | |
updated pod
|
1933 |
Create assign parameter. |
added EXPERIMENTAL assign_ta...
|
1934 | |
- update_param_tag is DEPREC...
|
1935 |
title = :title, author = :author |
added EXPERIMENTAL assign_ta...
|
1936 | |
- update_param_tag is DEPREC...
|
1937 |
This is equal to C<update_param> exept that set is not added. |
added EXPERIMENTAL assign_ta...
|
1938 | |
- select() EXPERIMETNAL colu...
|
1939 |
=head2 C<col> EXPERIMETNAL |
1940 | ||
1941 |
my $column = $model->col(book => ['author', 'title']); |
|
1942 | ||
1943 |
Create column clause. The follwoing column clause is created. |
|
1944 | ||
1945 |
book.author as "book.author", |
|
1946 |
book.title as "book.title" |
|
1947 | ||
1948 |
=head2 C<column> EXPERIMETNAL |
|
1949 | ||
1950 |
my $column = $dbi->column(book => ['author', 'title']); |
|
1951 | ||
1952 |
Create column clause. The follwoing column clause is created. |
|
1953 | ||
1954 |
book.author as book__author, |
|
1955 |
book.title as book__title |
|
1956 | ||
removed DBIx::Custom commit ...
|
1957 |
=head2 C<connect> |
packaging one directory
|
1958 | |
update pod
|
1959 |
my $dbi = DBIx::Custom->connect( |
data_source is DEPRECATED! I...
|
1960 |
dsn => "dbi:mysql:database=dbname", |
update pod
|
1961 |
user => 'ken', |
1962 |
password => '!LFKD%$&', |
|
1963 |
dbi_option => {mysql_enable_utf8 => 1} |
|
1964 |
); |
|
1965 | ||
1966 |
Connect to the database and create a new L<DBIx::Custom> object. |
|
bind_filter argument is chan...
|
1967 | |
renamed build_query to creat...
|
1968 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1969 |
C<AutoCommit> and C<RaiseError> options are true, |
update pod
|
1970 |
and C<PrintError> option is false by default. |
packaging one directory
|
1971 | |
removed EXPERIMETNAL flag fr...
|
1972 |
=head2 create_model |
1973 | ||
adeed EXPERIMENTAL DBIx::Cus...
|
1974 |
my $model = $dbi->create_model( |
removed EXPERIMETNAL flag fr...
|
1975 |
table => 'book', |
1976 |
primary_key => 'id', |
|
1977 |
join => [ |
|
1978 |
'inner join company on book.comparny_id = company.id' |
|
1979 |
], |
|
DBIx::Custom::Model filter a...
|
1980 |
filter => { |
removed EXPERIMETNAL flag fr...
|
1981 |
publish_date => { |
1982 |
out => 'tp_to_date', |
|
1983 |
in => 'date_to_tp', |
|
1984 |
end => 'tp_to_displaydate' |
|
1985 |
} |
|
DBIx::Custom::Model filter a...
|
1986 |
} |
removed EXPERIMETNAL flag fr...
|
1987 |
); |
1988 | ||
1989 |
Create L<DBIx::Custom::Model> object and initialize model. |
|
adeed EXPERIMENTAL DBIx::Cus...
|
1990 |
the module is also used from model() method. |
removed EXPERIMETNAL flag fr...
|
1991 | |
1992 |
$dbi->model('book')->select(...); |
|
1993 | ||
cleanup
|
1994 |
=head2 C<create_query> |
1995 |
|
|
1996 |
my $query = $dbi->create_query( |
|
update pod
|
1997 |
"insert into book {insert_param title author};"; |
cleanup
|
1998 |
); |
update document
|
1999 | |
update pod
|
2000 |
Create L<DBIx::Custom::Query> object. |
2001 | ||
cleanup
|
2002 |
If you want to get high performance, |
update pod
|
2003 |
create L<DBIx::Custom::Query> object and execute the query by C<execute()> |
2004 |
instead of other methods, such as C<insert>, C<update>. |
|
bind_filter argument is chan...
|
2005 | |
cleanup
|
2006 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
version 0.0901
|
2007 | |
EXPERIMETAL fork safety impl...
|
2008 |
=head2 C<dbh> |
2009 | ||
2010 |
my $dbh = $dbi->dbh; |
|
2011 | ||
- removed EXPERIMENTAL Prefo...
|
2012 |
Get L<DBI> database handle. if C<connector> is set, you can get |
2013 |
database handle from C<connector>. |
|
removed EXPERIMETNAL flag fr...
|
2014 | |
2015 |
=head2 C<each_column> |
|
2016 | ||
2017 |
$dbi->each_column( |
|
2018 |
sub { |
|
2019 |
my ($dbi, $table, $column, $column_info) = @_; |
|
2020 |
|
|
2021 |
my $type = $column_info->{TYPE_NAME}; |
|
2022 |
|
|
2023 |
if ($type eq 'DATE') { |
|
2024 |
# ... |
|
2025 |
} |
|
2026 |
} |
|
2027 |
); |
|
2028 | ||
2029 |
Iterate all column informations of all table from database. |
|
2030 |
Argument is callback when one column is found. |
|
2031 |
Callback receive four arguments, dbi object, table name, |
|
2032 |
column name and column information. |
|
EXPERIMETAL fork safety impl...
|
2033 | |
cleanup
|
2034 |
=head2 C<execute> |
packaging one directory
|
2035 | |
update pod
|
2036 |
my $result = $dbi->execute( |
- update_param_tag is DEPREC...
|
2037 |
"select * from book where title = :title and author like :author", |
execute method can second ar...
|
2038 |
{title => 'Perl', author => '%Ken%'} |
update pod
|
2039 |
); |
2040 | ||
updated pod
|
2041 |
Execute SQL. SQL can contain parameter such as :author. |
2042 |
Return value is L<DBIx::Custom::Result> when select statement is executed, |
|
2043 |
or the count of affected rows in insert, update, delete statement is executed. |
|
update pod
|
2044 | |
updated pod
|
2045 |
Parameter is replaced by placeholder C<?>. |
update pod
|
2046 | |
2047 |
select * from where title = ? and author like ?; |
|
2048 | ||
updated pod
|
2049 |
The following opitons are available. |
update pod
|
2050 | |
2051 |
=over 4 |
|
2052 | ||
2053 |
=item C<filter> |
|
updated pod
|
2054 |
|
2055 |
filter => { |
|
2056 |
title => sub { uc $_[0] } |
|
2057 |
author => sub { uc $_[0] } |
|
2058 |
} |
|
update pod
|
2059 | |
updated pod
|
2060 |
# Filter name |
2061 |
filter => { |
|
2062 |
title => 'upper_case', |
|
2063 |
author => 'upper_case' |
|
2064 |
} |
|
2065 |
|
|
2066 |
# At once |
|
2067 |
filter => [ |
|
2068 |
[qw/title author/] => sub { uc $_[0] } |
|
2069 |
] |
|
2070 | ||
2071 |
Filter, executed before data is saved into database. |
|
update pod
|
2072 |
Filter value is code reference or |
2073 |
filter name registerd by C<register_filter()>. |
|
2074 | ||
2075 |
These filters are added to the C<out> filters, set by C<apply_filter()>. |
|
added EXPERIMENTAL execute()...
|
2076 | |
updated document
|
2077 |
=item C<query> |
2078 | ||
2079 |
query => 1 |
|
2080 | ||
2081 |
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL. |
|
2082 | ||
updated pod
|
2083 |
=item C<table> |
2084 |
|
|
2085 |
table => 'author' |
|
2086 |
table => ['author', 'book'] |
|
2087 | ||
2088 |
Table names for filtering. |
|
2089 | ||
2090 |
Filtering by C<apply_filter> is off in C<execute> method, |
|
2091 |
because we don't know what filter is applied. |
|
2092 | ||
added EXPERIMENTAL execute()...
|
2093 |
=item C<type> |
2094 | ||
2095 |
Specify database data type. |
|
2096 | ||
2097 |
type => [image => DBI::SQL_BLOB] |
|
2098 |
type => [[qw/image audio/] => DBI::SQL_BLOB] |
|
2099 | ||
2100 |
This is used to bind paramter by C<bind_param()> of statment handle. |
|
2101 | ||
2102 |
$sth->bind_param($pos, $value, DBI::SQL_BLOB); |
|
2103 | ||
2104 |
C<type> option is also available |
|
2105 |
by C<insert()>, C<update()>, C<delete()>, C<select()>. |
|
2106 | ||
2107 |
=item C<type_rule_off> EXPERIMENTAL |
|
2108 | ||
2109 |
type_rule_off => 1 |
|
2110 | ||
2111 |
Trun type rule off. |
|
update document
|
2112 | |
update pod
|
2113 |
=back |
version 0.0901
|
2114 | |
removed DBIx::Custom commit ...
|
2115 |
=head2 C<delete> |
packaging one directory
|
2116 | |
update pod
|
2117 |
$dbi->delete(table => 'book', where => {title => 'Perl'}); |
2118 | ||
updated document
|
2119 |
Execute delete statement. |
update pod
|
2120 | |
updated document
|
2121 |
The following opitons are available. |
update pod
|
2122 | |
update pod
|
2123 |
=over 4 |
2124 | ||
update pod
|
2125 |
=item C<append> |
2126 | ||
updated document
|
2127 |
Same as C<select> method's C<append> option. |
update pod
|
2128 | |
2129 |
=item C<filter> |
|
2130 | ||
added EXPERIMENTAL execute()...
|
2131 |
Same as C<execute> method's C<filter> option. |
update pod
|
2132 | |
updated document
|
2133 |
=item C<id> |
update pod
|
2134 | |
updated document
|
2135 |
id => 4 |
2136 |
id => [4, 5] |
|
update pod
|
2137 | |
updated document
|
2138 |
ID corresponding to C<primary_key>. |
2139 |
You can delete rows by C<id> and C<primary_key>. |
|
update pod
|
2140 | |
updated document
|
2141 |
$dbi->delete( |
2142 |
parimary_key => ['id1', 'id2'], |
|
2143 |
id => [4, 5], |
|
2144 |
table => 'book', |
|
2145 |
); |
|
update pod
|
2146 | |
updated document
|
2147 |
The above is same as the followin one. |
renamed build_query to creat...
|
2148 | |
updated document
|
2149 |
$dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book'); |
add experimental update_at()...
|
2150 | |
updated document
|
2151 |
=item C<query> |
add experimental update_at()...
|
2152 | |
updated document
|
2153 |
Same as C<execute> method's C<query> option. |
add experimental update_at()...
|
2154 | |
updated document
|
2155 |
=item C<table> |
update pod
|
2156 | |
updated document
|
2157 |
table => 'book' |
update pod
|
2158 | |
updated document
|
2159 |
=item C<where> |
update pod
|
2160 | |
updated document
|
2161 |
Same as C<select> method's C<where> option. |
update pod
|
2162 | |
updated pod
|
2163 |
=item C<primary_key> |
update pod
|
2164 | |
updated pod
|
2165 |
See C<id> option. |
update pod
|
2166 | |
added EXPERIMENTAL execute()...
|
2167 |
=item C<type> |
2168 | ||
2169 |
Same as C<execute> method's C<type> option. |
|
2170 | ||
2171 |
=item C<type_rule_off> EXPERIMENTAL |
|
2172 | ||
2173 |
Same as C<execute> method's C<type_rule_off> option. |
|
2174 | ||
updated pod
|
2175 |
=back |
update pod
|
2176 | |
updated pod
|
2177 |
=head2 C<delete_all> |
update pod
|
2178 | |
updated pod
|
2179 |
$dbi->delete_all(table => $table); |
add experimental update_at()...
|
2180 | |
updated document
|
2181 |
Execute delete statement for all rows. |
updated pod
|
2182 |
Options is same as C<delete()>. |
update pod
|
2183 | |
cleanup
|
2184 |
=head2 C<insert> |
2185 | ||
cleanup
|
2186 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
update pod
|
2187 | |
cleanup
|
2188 |
Execute insert statement. |
update pod
|
2189 | |
cleanup
|
2190 |
The following opitons are available. |
update pod
|
2191 | |
cleanup
|
2192 |
=over 4 |
- insert, insert_at, update,...
|
2193 | |
update pod
|
2194 |
=item C<append> |
2195 | ||
cleanup
|
2196 |
Same as C<select> method's C<append> option. |
update pod
|
2197 | |
2198 |
=item C<filter> |
|
2199 | ||
added EXPERIMENTAL execute()...
|
2200 |
Same as C<execute> method's C<filter> option. |
2201 | ||
2202 |
=item C<id> |
|
2203 | ||
updated document
|
2204 |
id => 4 |
2205 |
id => [4, 5] |
|
update pod
|
2206 | |
updated document
|
2207 |
ID corresponding to C<primary_key>. |
2208 |
You can insert a row by C<id> and C<primary_key>. |
|
added EXPERIMENTAL execute()...
|
2209 | |
update pod
|
2210 |
$dbi->insert( |
updated document
|
2211 |
{title => 'Perl', author => 'Ken'} |
2212 |
parimary_key => ['id1', 'id2'], |
|
added EXPERIMENTAL execute()...
|
2213 |
id => [4, 5], |
updated document
|
2214 |
table => 'book' |
update pod
|
2215 |
); |
added EXPERIMENTAL execute()...
|
2216 | |
updated document
|
2217 |
The above is same as the followin one. |
update pod
|
2218 | |
added EXPERIMENTAL execute()...
|
2219 |
$dbi->insert( |
updated document
|
2220 |
{id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'}, |
2221 |
table => 'book' |
|
added EXPERIMENTAL execute()...
|
2222 |
); |
update pod
|
2223 | |
added EXPERIMENTAL execute()...
|
2224 |
=item C<primary_key> |
update pod
|
2225 | |
updated document
|
2226 |
primary_key => 'id' |
2227 |
primary_key => ['id1', 'id2'] |
|
update pod
|
2228 | |
updated document
|
2229 |
Primary key. This is used by C<id> option. |
cleanup
|
2230 | |
2231 |
=item C<param> |
|
2232 | ||
2233 |
param => {title => 'Perl', author => 'Ken'} |
|
2234 | ||
2235 |
Insert data. |
|
2236 | ||
2237 |
If C<insert> method's arguments is odd numbers, |
|
2238 |
first argument is received as C<param>. |
|
2239 | ||
2240 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
|
2241 | ||
updated document
|
2242 |
=item C<query> |
2243 | ||
2244 |
Same as C<execute> method's C<query> option. |
|
2245 | ||
2246 |
=item C<table> |
|
2247 | ||
2248 |
table => 'book' |
|
2249 | ||
2250 |
Table name. |
|
2251 | ||
added EXPERIMENTAL execute()...
|
2252 |
=item C<type> |
cleanup
|
2253 | |
added EXPERIMENTAL execute()...
|
2254 |
Same as C<execute> method's C<type> option. |
cleanup
|
2255 | |
added EXPERIMENTAL execute()...
|
2256 |
=item C<type_rule_off> EXPERIMENTAL |
2257 | ||
updated document
|
2258 |
Same as C<execute> method's C<type_rule_off> option. |
update pod
|
2259 | |
update pod
|
2260 |
=back |
2261 | ||
2262 |
=over 4 |
|
2263 | ||
- update_param_tag is DEPREC...
|
2264 |
=head2 C<insert_param> |
added experimental update_pa...
|
2265 | |
- update_param_tag is DEPREC...
|
2266 |
my $insert_param = $dbi->insert_param({title => 'a', age => 2}); |
added experimental update_pa...
|
2267 | |
- update_param_tag is DEPREC...
|
2268 |
Create insert parameters. |
added experimental update_pa...
|
2269 | |
- update_param_tag is DEPREC...
|
2270 |
(title, author) values (title = :title, age = :age); |
added experimental update_pa...
|
2271 | |
- removed DEPRECATED DBIx::C...
|
2272 |
=head2 C<include_model> |
removed experimental base_ta...
|
2273 | |
update pod
|
2274 |
$dbi->include_model('MyModel'); |
removed experimental base_ta...
|
2275 | |
update pod
|
2276 |
Include models from specified namespace, |
2277 |
the following layout is needed to include models. |
|
removed experimental base_ta...
|
2278 | |
update pod
|
2279 |
lib / MyModel.pm |
2280 |
/ MyModel / book.pm |
|
2281 |
/ company.pm |
|
add feture. all model class ...
|
2282 | |
update pod
|
2283 |
Name space module, extending L<DBIx::Custom::Model>. |
add feture. all model class ...
|
2284 | |
update pod
|
2285 |
B<MyModel.pm> |
add feture. all model class ...
|
2286 | |
2287 |
package MyModel; |
|
2288 |
|
|
2289 |
use base 'DBIx::Custom::Model'; |
|
update pod
|
2290 |
|
2291 |
1; |
|
add feture. all model class ...
|
2292 | |
update pod
|
2293 |
Model modules, extending name space module. |
removed experimental base_ta...
|
2294 | |
update pod
|
2295 |
B<MyModel/book.pm> |
removed experimental base_ta...
|
2296 | |
update pod
|
2297 |
package MyModel::book; |
2298 |
|
|
2299 |
use base 'MyModel'; |
|
2300 |
|
|
2301 |
1; |
|
removed experimental base_ta...
|
2302 | |
update pod
|
2303 |
B<MyModel/company.pm> |
removed experimental base_ta...
|
2304 | |
update pod
|
2305 |
package MyModel::company; |
2306 |
|
|
2307 |
use base 'MyModel'; |
|
2308 |
|
|
2309 |
1; |
|
2310 |
|
|
2311 |
MyModel::book and MyModel::company is included by C<include_model()>. |
|
removed experimental base_ta...
|
2312 | |
update pod
|
2313 |
You can get model object by C<model()>. |
2314 | ||
2315 |
my $book_model = $dbi->model('book'); |
|
2316 |
my $company_model = $dbi->model('company'); |
|
removed experimental base_ta...
|
2317 | |
update pod
|
2318 |
See L<DBIx::Custom::Model> to know model features. |
2319 | ||
- removed DEPRECATED DBIx::C...
|
2320 |
=head2 C<merge_param> |
added EXPERIMENTAL updat_par...
|
2321 | |
2322 |
my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2}); |
|
2323 | ||
2324 |
Merge paramters. |
|
2325 | ||
2326 |
$param: |
|
2327 | ||
2328 |
{key1 => [1, 1], key2 => 2} |
|
2329 | ||
- removed DEPRECATED DBIx::C...
|
2330 |
=head2 C<method> |
added experimental not_exist...
|
2331 | |
2332 |
$dbi->method( |
|
2333 |
update_or_insert => sub { |
|
2334 |
my $self = shift; |
|
update pod
|
2335 |
|
2336 |
# Process |
|
added experimental not_exist...
|
2337 |
}, |
2338 |
find_or_create => sub { |
|
2339 |
my $self = shift; |
|
update pod
|
2340 |
|
2341 |
# Process |
|
added experimental not_exist...
|
2342 |
} |
2343 |
); |
|
2344 | ||
update pod
|
2345 |
Register method. These method is called directly from L<DBIx::Custom> object. |
added experimental not_exist...
|
2346 | |
2347 |
$dbi->update_or_insert; |
|
2348 |
$dbi->find_or_create; |
|
2349 | ||
- removed DEPRECATED DBIx::C...
|
2350 |
=head2 C<model> |
update pod
|
2351 | |
2352 |
$dbi->model('book')->method( |
|
2353 |
insert => sub { ... }, |
|
2354 |
update => sub { ... } |
|
2355 |
); |
|
2356 |
|
|
2357 |
my $model = $dbi->model('book'); |
|
2358 | ||
2359 |
Set and get a L<DBIx::Custom::Model> object, |
|
2360 | ||
- removed DEPRECATED DBIx::C...
|
2361 |
=head2 C<mycolumn> |
cleanup
|
2362 | |
2363 |
my $column = $self->mycolumn(book => ['author', 'title']); |
|
2364 | ||
2365 |
Create column clause for myself. The follwoing column clause is created. |
|
2366 | ||
2367 |
book.author as author, |
|
2368 |
book.title as title |
|
2369 | ||
added experimental not_exist...
|
2370 |
=head2 C<new> |
2371 | ||
update pod
|
2372 |
my $dbi = DBIx::Custom->new( |
data_source is DEPRECATED! I...
|
2373 |
dsn => "dbi:mysql:database=dbname", |
update pod
|
2374 |
user => 'ken', |
2375 |
password => '!LFKD%$&', |
|
2376 |
dbi_option => {mysql_enable_utf8 => 1} |
|
2377 |
); |
|
added experimental not_exist...
|
2378 | |
2379 |
Create a new L<DBIx::Custom> object. |
|
2380 | ||
removed EXPERIMETNAL flag fr...
|
2381 |
=head2 C<not_exists> |
added experimental not_exist...
|
2382 | |
2383 |
my $not_exists = $dbi->not_exists; |
|
2384 | ||
update pod
|
2385 |
DBIx::Custom::NotExists object, indicating the column is not exists. |
2386 |
This is used by C<clause> of L<DBIx::Custom::Where> . |
|
experimental extended select...
|
2387 | |
cleanup
|
2388 |
=head2 C<register_filter> |
2389 | ||
update pod
|
2390 |
$dbi->register_filter( |
2391 |
# Time::Piece object to database DATE format |
|
2392 |
tp_to_date => sub { |
|
2393 |
my $tp = shift; |
|
2394 |
return $tp->strftime('%Y-%m-%d'); |
|
2395 |
}, |
|
2396 |
# database DATE format to Time::Piece object |
|
2397 |
date_to_tp => sub { |
|
2398 |
my $date = shift; |
|
2399 |
return Time::Piece->strptime($date, '%Y-%m-%d'); |
|
2400 |
} |
|
2401 |
); |
|
cleanup
|
2402 |
|
update pod
|
2403 |
Register filters, used by C<filter> option of many methods. |
cleanup
|
2404 | |
added type_rule into logic
|
2405 |
=head2 C<type_rule> EXPERIMENTAL |
2406 | ||
2407 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2408 |
into => { |
2409 |
DATE => sub { ... }, |
|
2410 |
DATETIME => sub { ... } |
|
added type_rule into logic
|
2411 |
}, |
changed type_rule arguments ...
|
2412 |
from => { |
2413 |
# DATE |
|
2414 |
9 => sub { ... }, |
|
2415 |
|
|
2416 |
# DATETIME or TIMESTAMP |
|
2417 |
11 => sub { ... }, |
|
added type_rule into logic
|
2418 |
} |
2419 |
); |
|
2420 | ||
changed type_rule arguments ...
|
2421 |
Filtering rule when data is send into and get from database. |
2422 |
This has a little complex problem. |
|
2423 |
In C<into> you can specify type name as same as type name defined |
|
2424 |
by create table, such as C<DATETIME> or C<DATE>. |
|
2425 |
but in C<from> you can't specify type name defined by create table. |
|
2426 |
You must specify data type, this is internal one. |
|
2427 |
You get all data type by C<available_data_type>. |
|
2428 | ||
2429 |
print $dbi->available_data_type; |
|
2430 | ||
2431 |
You can also specify multiple types |
|
2432 | ||
2433 |
$dbi->type_rule( |
|
2434 |
into => [ |
|
2435 |
[qw/DATE DATETIME/] => sub { ... }, |
|
2436 |
], |
|
2437 |
from => { |
|
2438 |
# DATE |
|
2439 |
[qw/9 11/] => sub { ... }, |
|
2440 |
} |
|
2441 |
); |
|
added type_rule into logic
|
2442 | |
removed DBIx::Custom commit ...
|
2443 |
=head2 C<select> |
added select() all_column op...
|
2444 | |
select method column option ...
|
2445 |
my $result = $dbi->select( |
added select() all_column op...
|
2446 |
table => 'book', |
2447 |
column => ['author', 'title'], |
|
2448 |
where => {author => 'Ken'}, |
|
select method column option ...
|
2449 |
); |
added select() all_column op...
|
2450 |
|
updated document
|
2451 |
Execute select statement. |
added select() all_column op...
|
2452 | |
updated document
|
2453 |
The following opitons are available. |
added select() all_column op...
|
2454 | |
2455 |
=over 4 |
|
2456 | ||
updated document
|
2457 |
=item C<append> |
added select() all_column op...
|
2458 | |
updated document
|
2459 |
append => 'order by title' |
added select() all_column op...
|
2460 | |
updated document
|
2461 |
Append statement to last of SQL. |
2462 |
|
|
added select() all_column op...
|
2463 |
=item C<column> |
2464 |
|
|
updated document
|
2465 |
column => 'author' |
2466 |
column => ['author', 'title'] |
|
2467 | ||
2468 |
Column clause. |
|
updated pod
|
2469 |
|
updated document
|
2470 |
if C<column> is not specified, '*' is set. |
added select() all_column op...
|
2471 | |
updated document
|
2472 |
column => '*' |
added select() all_column op...
|
2473 | |
updated document
|
2474 |
You can specify hash reference in array reference. This is EXPERIMENTAL. |
updated pod
|
2475 | |
updated document
|
2476 |
column => [ |
updated pod
|
2477 |
{book => [qw/author title/]}, |
2478 |
{person => [qw/name age/]} |
|
updated document
|
2479 |
] |
updated pod
|
2480 | |
updated document
|
2481 |
This is expanded to the following one by using C<col> method. |
- select() column option can...
|
2482 | |
2483 |
book.author as "book.author", |
|
2484 |
book.title as "book.title", |
|
2485 |
person.name as "person.name", |
|
2486 |
person.age as "person.age" |
|
2487 | ||
updated document
|
2488 |
You can specify array reference in array reference. |
- select() column option can...
|
2489 | |
updated document
|
2490 |
column => [ |
- select() column option can...
|
2491 |
['date(book.register_datetime)', as => 'book.register_date'] |
updated document
|
2492 |
]; |
- select() column option can...
|
2493 | |
updated document
|
2494 |
Alias is quoted and joined. |
- select() column option can...
|
2495 | |
2496 |
date(book.register_datetime) as "book.register_date" |
|
updated pod
|
2497 | |
updated document
|
2498 |
=item C<filter> |
added select() all_column op...
|
2499 | |
updated document
|
2500 |
Same as C<execute> method's C<filter> option. |
2501 | ||
2502 |
=item C<id> |
|
2503 | ||
2504 |
id => 4 |
|
2505 |
id => [4, 5] |
|
2506 | ||
2507 |
ID corresponding to C<primary_key>. |
|
2508 |
You can select rows by C<id> and C<primary_key>. |
|
2509 | ||
2510 |
$dbi->select( |
|
2511 |
parimary_key => ['id1', 'id2'], |
|
2512 |
id => [4, 5], |
|
2513 |
table => 'book' |
|
added select() all_column op...
|
2514 |
); |
2515 | ||
updated document
|
2516 |
The above is same as the followin one. |
2517 | ||
updated pod
|
2518 |
$dbi->select( |
updated document
|
2519 |
where => {id1 => 4, id2 => 5}, |
2520 |
table => 'book' |
|
where can recieve array refr...
|
2521 |
); |
2522 |
|
|
updated document
|
2523 |
=item C<param> EXPERIMETNAL |
added select() all_column op...
|
2524 | |
updated document
|
2525 |
param => {'table2.key3' => 5} |
update pod
|
2526 | |
updated document
|
2527 |
Parameter shown before where clause. |
2528 |
|
|
2529 |
For example, if you want to contain tag in join clause, |
|
2530 |
you can pass parameter by C<param> option. |
|
update pod
|
2531 | |
updated document
|
2532 |
join => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . |
2533 |
' as table2 on table1.key1 = table2.key1'] |
|
2534 | ||
2535 |
=item C<join> |
|
2536 | ||
2537 |
join => [ |
|
2538 |
'left outer join company on book.company_id = company_id', |
|
2539 |
'left outer join location on company.location_id = location.id' |
|
2540 |
] |
|
2541 |
|
|
2542 |
Join clause. If column cluase or where clause contain table name like "company.name", |
|
2543 |
join clausees needed when SQL is created is used automatically. |
|
update pod
|
2544 | |
2545 |
$dbi->select( |
|
2546 |
table => 'book', |
|
2547 |
column => ['company.location_id as company__location_id'], |
|
2548 |
where => {'company.name' => 'Orange'}, |
|
2549 |
join => [ |
|
2550 |
'left outer join company on book.company_id = company.id', |
|
2551 |
'left outer join location on company.location_id = location.id' |
|
2552 |
] |
|
2553 |
); |
|
2554 | ||
updated document
|
2555 |
In above select, column and where clause contain "company" table, |
2556 |
the following SQL is created |
|
update pod
|
2557 | |
2558 |
select company.location_id as company__location_id |
|
2559 |
from book |
|
2560 |
left outer join company on book.company_id = company.id |
|
2561 |
where company.name = Orange |
|
2562 | ||
updated document
|
2563 |
=item C<primary_key> |
added EXPERIMENTAL replace()...
|
2564 | |
updated document
|
2565 |
primary_key => 'id' |
2566 |
primary_key => ['id1', 'id2'] |
|
added EXPERIMENTAL replace()...
|
2567 | |
updated document
|
2568 |
Primary key. This is used by C<id> option. |
added EXPERIMENTAL replace()...
|
2569 | |
updated document
|
2570 |
=item C<query> |
update pod
|
2571 | |
updated document
|
2572 |
Same as C<execute> method's C<query> option. |
update pod
|
2573 | |
updated document
|
2574 |
=item C<type> |
updated pod
|
2575 | |
updated document
|
2576 |
Same as C<execute> method's C<type> option. |
updated pod
|
2577 | |
updated document
|
2578 |
=item C<table> |
updated pod
|
2579 | |
updated document
|
2580 |
table => 'book' |
updated pod
|
2581 | |
updated document
|
2582 |
Table name. |
updated pod
|
2583 | |
updated document
|
2584 |
=item C<type_rule_off> EXPERIMENTAL |
updated pod
|
2585 | |
updated document
|
2586 |
Same as C<execute> method's C<type_rule_off> option. |
updated pod
|
2587 | |
updated document
|
2588 |
=item C<where> |
2589 |
|
|
2590 |
# Hash refrence |
|
2591 |
where => {author => 'Ken', 'title' => 'Perl'} |
|
2592 |
|
|
2593 |
# DBIx::Custom::Where object |
|
2594 |
where => $dbi->where( |
|
2595 |
clause => ['and', 'author = :author', 'title like :title'], |
|
2596 |
param => {author => 'Ken', title => '%Perl%'} |
|
2597 |
); |
|
updated pod
|
2598 | |
updated document
|
2599 |
# String(with where_param option) |
2600 |
where => 'title like :title', |
|
2601 |
where_param => {title => '%Perl%'} |
|
update pod
|
2602 | |
updated document
|
2603 |
Where clause. |
2604 |
|
|
improved pod
|
2605 |
=item C<wrap> EXPERIMENTAL |
2606 | ||
2607 |
Wrap statement. This is array reference. |
|
2608 | ||
2609 |
$dbi->select(wrap => ['select * from (', ') as t where ROWNUM < 10']); |
|
2610 | ||
2611 |
This option is for Oracle and SQL Server paging process. |
|
2612 | ||
update pod
|
2613 |
=back |
cleanup
|
2614 | |
cleanup
|
2615 |
=head2 C<update> |
removed reconnect method
|
2616 | |
updated document
|
2617 |
$dbi->update({title => 'Perl'}, table => 'book', where => {id => 4}); |
removed reconnect method
|
2618 | |
updated document
|
2619 |
Execute update statement. |
added experimental update_pa...
|
2620 | |
updated document
|
2621 |
The following opitons are available. |
added experimental update_pa...
|
2622 | |
update pod
|
2623 |
=over 4 |
2624 | ||
updated document
|
2625 |
=item C<append> |
update pod
|
2626 | |
updated document
|
2627 |
Same as C<select> method's C<append> option. |
- insert, insert_at, update,...
|
2628 | |
updated document
|
2629 |
=item C<filter> |
- insert, insert_at, update,...
|
2630 | |
updated document
|
2631 |
Same as C<execute> method's C<filter> option. |
- insert, insert_at, update,...
|
2632 | |
updated document
|
2633 |
=item C<id> |
- insert, insert_at, update,...
|
2634 | |
updated document
|
2635 |
id => 4 |
2636 |
id => [4, 5] |
|
- insert, insert_at, update,...
|
2637 | |
updated document
|
2638 |
ID corresponding to C<primary_key>. |
2639 |
You can update rows by C<id> and C<primary_key>. |
|
update pod
|
2640 | |
DEPRECATED select() param op...
|
2641 |
$dbi->update( |
updated document
|
2642 |
{title => 'Perl', author => 'Ken'} |
2643 |
parimary_key => ['id1', 'id2'], |
|
2644 |
id => [4, 5], |
|
2645 |
table => 'book' |
|
where can recieve array refr...
|
2646 |
); |
update pod
|
2647 | |
updated document
|
2648 |
The above is same as the followin one. |
update pod
|
2649 | |
updated document
|
2650 |
$dbi->update( |
2651 |
{title => 'Perl', author => 'Ken'} |
|
2652 |
where => {id1 => 4, id2 => 5}, |
|
2653 |
table => 'book' |
|
2654 |
); |
|
update pod
|
2655 | |
updated document
|
2656 |
=item C<param> |
added experimental update_pa...
|
2657 | |
updated document
|
2658 |
param => {title => 'Perl'} |
add experimental setup_model...
|
2659 | |
updated document
|
2660 |
Update data. |
add experimental setup_model...
|
2661 | |
updated document
|
2662 |
If C<update> method's arguments is odd numbers, first argument is received as C<param>. |
update pod
|
2663 | |
updated document
|
2664 |
$dbi->update({title => 'Perl'}, table => 'book', where => {id => 2}); |
update pod
|
2665 | |
updated document
|
2666 |
=item C<primary_key> |
add experimental setup_model...
|
2667 | |
updated document
|
2668 |
primary_key => 'id' |
2669 |
primary_key => ['id1', 'id2'] |
|
update pod
|
2670 | |
updated document
|
2671 |
Primary key. This is used by C<id> option. |
update pod
|
2672 | |
updated document
|
2673 |
=item C<query> |
update pod
|
2674 | |
updated document
|
2675 |
Same as C<execute> method's C<query> option. |
update pod
|
2676 | |
updated document
|
2677 |
=item C<table> |
update pod
|
2678 | |
updated document
|
2679 |
table => 'book' |
update pod
|
2680 | |
updated document
|
2681 |
Table name. |
update pod
|
2682 | |
updated document
|
2683 |
=item C<where> |
update pod
|
2684 | |
updated document
|
2685 |
Same as C<select> method's C<where> option. |
update pod
|
2686 | |
added EXPERIMENTAL execute()...
|
2687 |
=item C<type> |
2688 | ||
2689 |
Same as C<execute> method's C<type> option. |
|
2690 | ||
2691 |
=item C<type_rule_off> EXPERIMENTAL |
|
2692 | ||
2693 |
Turn type rule off. |
|
2694 | ||
updated pod
|
2695 |
=back |
update pod
|
2696 | |
updated pod
|
2697 |
=head2 C<update_all> |
update pod
|
2698 | |
updated pod
|
2699 |
$dbi->update_all(table => 'book', param => {title => 'Perl'}); |
update pod
|
2700 | |
updated document
|
2701 |
Execute update statement for all rows. |
updated pod
|
2702 |
Options is same as C<update()>. |
update pod
|
2703 | |
- update_param_tag is DEPREC...
|
2704 |
=head2 C<update_param> |
update pod
|
2705 | |
- update_param_tag is DEPREC...
|
2706 |
my $update_param = $dbi->update_param({title => 'a', age => 2}); |
update pod
|
2707 | |
2708 |
Create update parameter tag. |
|
2709 | ||
- update_param_tag is DEPREC...
|
2710 |
set title = :title, author = :author |
added EXPERIMENTAL updat_par...
|
2711 | |
- update_param_tag is DEPREC...
|
2712 |
C<no_set> option is DEPRECATED! use C<assing_param> instead. |
add experimental update_at()...
|
2713 | |
removed EXPERIMETNAL flag fr...
|
2714 |
=head2 C<where> |
fix tests
|
2715 | |
cleanup
|
2716 |
my $where = $dbi->where( |
- update_param_tag is DEPREC...
|
2717 |
clause => ['and', 'title = :title', 'author = :author'], |
cleanup
|
2718 |
param => {title => 'Perl', author => 'Ken'} |
2719 |
); |
|
fix tests
|
2720 | |
2721 |
Create a new L<DBIx::Custom::Where> object. |
|
2722 | ||
- removed DEPRECATED DBIx::C...
|
2723 |
=head2 C<setup_model> |
cleanup
|
2724 | |
update pod
|
2725 |
$dbi->setup_model; |
cleanup
|
2726 | |
update pod
|
2727 |
Setup all model objects. |
update pod
|
2728 |
C<columns> of model object is automatically set, parsing database information. |
cleanup
|
2729 | |
updated pod
|
2730 |
=head2 C<update_at()> DEPRECATED! |
2731 | ||
2732 |
Update statement, using primary key. |
|
2733 | ||
2734 |
$dbi->update_at( |
|
2735 |
table => 'book', |
|
2736 |
primary_key => 'id', |
|
2737 |
where => '5', |
|
2738 |
param => {title => 'Perl'} |
|
2739 |
); |
|
2740 | ||
2741 |
This method is same as C<update()> exept that |
|
2742 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
2743 |
all option of C<update()> is available. |
|
2744 | ||
2745 |
=head2 C<delete_at()> DEPRECATED! |
|
2746 | ||
2747 |
Delete statement, using primary key. |
|
2748 | ||
2749 |
$dbi->delete_at( |
|
2750 |
table => 'book', |
|
2751 |
primary_key => 'id', |
|
2752 |
where => '5' |
|
2753 |
); |
|
2754 | ||
2755 |
This method is same as C<delete()> exept that |
|
2756 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
2757 |
all option of C<delete()> is available. |
|
2758 | ||
2759 |
=head2 C<select_at()> DEPRECATED! |
|
2760 | ||
2761 |
Select statement, using primary key. |
|
2762 | ||
2763 |
$dbi->select_at( |
|
2764 |
table => 'book', |
|
2765 |
primary_key => 'id', |
|
2766 |
where => '5' |
|
2767 |
); |
|
2768 | ||
2769 |
This method is same as C<select()> exept that |
|
2770 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
2771 |
all option of C<select()> is available. |
|
2772 | ||
2773 |
=head2 C<register_tag> DEPRECATED! |
|
2774 | ||
2775 |
$dbi->register_tag( |
|
2776 |
update => sub { |
|
2777 |
my @columns = @_; |
|
2778 |
|
|
2779 |
# Update parameters |
|
2780 |
my $s = 'set '; |
|
2781 |
$s .= "$_ = ?, " for @columns; |
|
2782 |
$s =~ s/, $//; |
|
2783 |
|
|
2784 |
return [$s, \@columns]; |
|
2785 |
} |
|
2786 |
); |
|
2787 | ||
2788 |
Register tag, used by C<execute()>. |
|
2789 | ||
2790 |
See also L<Tags/Tags> about tag registered by default. |
|
2791 | ||
2792 |
Tag parser receive arguments specified in tag. |
|
2793 |
In the following tag, 'title' and 'author' is parser arguments |
|
2794 | ||
2795 |
{update_param title author} |
|
2796 | ||
2797 |
Tag parser must return array refrence, |
|
2798 |
first element is the result statement, |
|
2799 |
second element is column names corresponding to place holders. |
|
2800 | ||
2801 |
In this example, result statement is |
|
2802 | ||
2803 |
set title = ?, author = ? |
|
2804 | ||
2805 |
Column names is |
|
2806 | ||
2807 |
['title', 'author'] |
|
2808 | ||
- update_param_tag is DEPREC...
|
2809 |
=head1 Parameter |
2810 | ||
2811 |
Parameter start at ':'. This is replaced to place holoder |
|
2812 | ||
2813 |
$dbi->execute( |
|
2814 |
"select * from book where title = :title and author = :author" |
|
2815 |
param => {title => 'Perl', author => 'Ken'} |
|
2816 |
); |
|
2817 | ||
2818 |
"select * from book where title = ? and author = ?" |
|
2819 | ||
2820 |
=head1 Tags DEPRECATED! |
|
2821 | ||
2822 |
B<Tag> system is DEPRECATED! use parameter system :name instead. |
|
2823 |
Parameter is simple and readable. |
|
2824 | ||
2825 |
Note that you can't use both tag and paramter at same time. |
|
cleanup
|
2826 | |
2827 |
The following tags is available. |
|
2828 | ||
- update_param_tag is DEPREC...
|
2829 |
=head2 C<?> DEPRECATED! |
cleanup
|
2830 | |
2831 |
Placeholder tag. |
|
2832 | ||
2833 |
{? NAME} -> ? |
|
2834 | ||
- update_param_tag is DEPREC...
|
2835 |
=head2 C<=> DEPRECATED! |
cleanup
|
2836 | |
2837 |
Equal tag. |
|
2838 | ||
2839 |
{= NAME} -> NAME = ? |
|
2840 | ||
- update_param_tag is DEPREC...
|
2841 |
=head2 C<E<lt>E<gt>> DEPRECATED! |
cleanup
|
2842 | |
2843 |
Not equal tag. |
|
2844 | ||
2845 |
{<> NAME} -> NAME <> ? |
|
2846 | ||
- update_param_tag is DEPREC...
|
2847 |
=head2 C<E<lt>> DEPRECATED! |
cleanup
|
2848 | |
2849 |
Lower than tag |
|
2850 | ||
2851 |
{< NAME} -> NAME < ? |
|
2852 | ||
- update_param_tag is DEPREC...
|
2853 |
=head2 C<E<gt>> DEPRECATED! |
cleanup
|
2854 | |
2855 |
Greater than tag |
|
2856 | ||
2857 |
{> NAME} -> NAME > ? |
|
2858 | ||
- update_param_tag is DEPREC...
|
2859 |
=head2 C<E<gt>=> DEPRECATED! |
cleanup
|
2860 | |
2861 |
Greater than or equal tag |
|
2862 | ||
2863 |
{>= NAME} -> NAME >= ? |
|
2864 | ||
- update_param_tag is DEPREC...
|
2865 |
=head2 C<E<lt>=> DEPRECATED! |
cleanup
|
2866 | |
2867 |
Lower than or equal tag |
|
2868 | ||
2869 |
{<= NAME} -> NAME <= ? |
|
2870 | ||
- update_param_tag is DEPREC...
|
2871 |
=head2 C<like> DEPRECATED! |
cleanup
|
2872 | |
2873 |
Like tag |
|
2874 | ||
2875 |
{like NAME} -> NAME like ? |
|
2876 | ||
- update_param_tag is DEPREC...
|
2877 |
=head2 C<in> DEPRECATED! |
cleanup
|
2878 | |
2879 |
In tag. |
|
2880 | ||
2881 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
2882 | ||
- update_param_tag is DEPREC...
|
2883 |
=head2 C<insert_param> DEPRECATED! |
cleanup
|
2884 | |
2885 |
Insert parameter tag. |
|
2886 | ||
2887 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
2888 | ||
- update_param_tag is DEPREC...
|
2889 |
=head2 C<update_param> DEPRECATED! |
cleanup
|
2890 | |
2891 |
Updata parameter tag. |
|
2892 | ||
2893 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
2894 | ||
updated pod
|
2895 |
=head2 C<insert_at()> DEPRECATED! |
2896 | ||
2897 |
Insert statement, using primary key. |
|
2898 | ||
2899 |
$dbi->insert_at( |
|
2900 |
table => 'book', |
|
2901 |
primary_key => 'id', |
|
2902 |
where => '5', |
|
2903 |
param => {title => 'Perl'} |
|
2904 |
); |
|
2905 | ||
2906 |
This method is same as C<insert()> exept that |
|
2907 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
2908 |
all option of C<insert()> is available. |
|
2909 | ||
added environment variable D...
|
2910 |
=head1 ENVIRONMENT VARIABLE |
2911 | ||
2912 |
=head2 C<DBIX_CUSTOM_DEBUG> |
|
2913 | ||
2914 |
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true, |
|
improved debug message
|
2915 |
executed SQL and bind values are printed to STDERR. |
2916 | ||
2917 |
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING> |
|
2918 | ||
2919 |
DEBUG output encoding. Default to UTF-8. |
|
added environment variable D...
|
2920 | |
DBIx::Custom is now stable
|
2921 |
=head1 STABILITY |
2922 | ||
cleanup
|
2923 |
L<DBIx::Custom> is stable. APIs keep backword compatible |
added select() all_column op...
|
2924 |
except EXPERIMENTAL one in the feature. |
DBIx::Custom is now stable
|
2925 | |
removed DESTROY method(not b...
|
2926 |
=head1 BUGS |
2927 | ||
renamed build_query to creat...
|
2928 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
2929 | |
2930 |
C<< <kimoto.yuki at gmail.com> >> |
|
2931 | ||
2932 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
2933 | ||
removed reconnect method
|
2934 |
=head1 AUTHOR |
2935 | ||
2936 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
2937 | |
packaging one directory
|
2938 |
=head1 COPYRIGHT & LICENSE |
2939 | ||
cleanup
|
2940 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
2941 | |
2942 |
This program is free software; you can redistribute it and/or modify it |
|
2943 |
under the same terms as Perl itself. |
|
2944 | ||
2945 |
=cut |