DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
907 lines | 23.032kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
2

            
3
use strict;
4
use warnings;
5

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
6
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
7

            
packaging one directory
yuki-kimoto authored on 2009-11-16
8
use Carp 'croak';
9
use DBI;
10
use DBIx::Custom::Result;
many many changes
yuki-kimoto authored on 2010-04-30
11
use DBIx::Custom::SQLTemplate;
cleanup
yuki-kimoto authored on 2010-02-11
12
use DBIx::Custom::Query;
update document
yuki-kimoto authored on 2010-05-27
13
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
14

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
15
__PACKAGE__->attr('dbh');
cleanup
yuki-kimoto authored on 2010-04-28
16
__PACKAGE__->attr([qw/user password data_source/]);
update document
yuki-kimoto authored on 2010-05-27
17
__PACKAGE__->attr([qw/default_query_filter default_fetch_filter/]);
packaging one directory
yuki-kimoto authored on 2009-11-16
18

            
removed register_format()
yuki-kimoto authored on 2010-05-26
19
__PACKAGE__->dual_attr('filters', default => sub { {} },
20
                                  inherit => 'hash_copy');
21
__PACKAGE__->register_filter(
update document
yuki-kimoto authored on 2010-05-27
22
    encode_utf8 => sub { encode_utf8($_[0]) },
23
    decode_utf8 => sub { decode_utf8($_[0]) }
removed register_format()
yuki-kimoto authored on 2010-05-26
24
);
packaging one directory
yuki-kimoto authored on 2009-11-16
25

            
cleanup
yuki-kimoto authored on 2010-04-28
26
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result');
removed register_format()
yuki-kimoto authored on 2010-05-26
27
__PACKAGE__->attr(sql_template => sub { DBIx::Custom::SQLTemplate->new });
added cache_method attribute
yuki-kimoto authored on 2010-06-25
28

            
add cache attribute
yuki-kimoto authored on 2010-06-14
29
__PACKAGE__->attr(cache => 1);
added cache_method attribute
yuki-kimoto authored on 2010-06-25
30
__PACKAGE__->attr(cache_method => sub {
31
    sub {
32
        my $self = shift;
33
        
34
        $self->{_cached} ||= {};
35
        
36
        if (@_ > 1) {
37
            $self->{_cached}{$_[0]} = $_[1] 
38
        }
39
        else {
40
            return $self->{_cached}{$_[0]}
41
        }
42
    }
43
});
removed register_format()
yuki-kimoto authored on 2010-05-26
44

            
packaging one directory
yuki-kimoto authored on 2009-11-16
45
sub connect {
removed register_format()
yuki-kimoto authored on 2010-05-26
46
    my $proto = shift;
47
    
48
    # Create
49
    my $self = ref $proto ? $proto : $proto->new(@_);
update document
yuki-kimoto authored on 2010-01-30
50
    
51
    # Information
packaging one directory
yuki-kimoto authored on 2009-11-16
52
    my $data_source = $self->data_source;
53
    my $user        = $self->user;
54
    my $password    = $self->password;
55
    
update document
yuki-kimoto authored on 2010-01-30
56
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
57
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
58
        $data_source,
59
        $user,
60
        $password,
61
        {
62
            RaiseError => 1,
63
            PrintError => 0,
64
            AutoCommit => 1,
65
        }
66
    )};
67
    
update document
yuki-kimoto authored on 2010-01-30
68
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
69
    croak $@ if $@;
70
    
update document
yuki-kimoto authored on 2010-01-30
71
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
72
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
73
    
packaging one directory
yuki-kimoto authored on 2009-11-16
74
    return $self;
75
}
76

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
77
sub register_filter {
78
    my $invocant = shift;
update document
yuki-kimoto authored on 2010-01-30
79
    
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
80
    # Add filter
81
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
82
    $invocant->filters({%{$invocant->filters}, %$filters});
update document
yuki-kimoto authored on 2010-01-30
83
    
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
84
    return $invocant;
packaging one directory
yuki-kimoto authored on 2009-11-16
85
}
86

            
removed register_format()
yuki-kimoto authored on 2010-05-26
87
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append filter/;
cleanup insert
yuki-kimoto authored on 2010-04-28
88

            
packaging one directory
yuki-kimoto authored on 2009-11-16
89
sub insert {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
90
    my ($self, %args) = @_;
removed register_format()
yuki-kimoto authored on 2010-05-26
91

            
cleanup insert
yuki-kimoto authored on 2010-04-28
92
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
93
    foreach my $name (keys %args) {
cleanup insert
yuki-kimoto authored on 2010-04-28
94
        croak "\"$name\" is invalid name"
95
          unless $VALID_INSERT_ARGS{$name};
96
    }
97
    
removed register_format()
yuki-kimoto authored on 2010-05-26
98
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
99
    my $table  = $args{table} || '';
100
    my $param  = $args{param} || {};
101
    my $append = $args{append} || '';
102
    my $filter = $args{filter};
packaging one directory
yuki-kimoto authored on 2009-11-16
103
    
104
    # Insert keys
removed register_format()
yuki-kimoto authored on 2010-05-26
105
    my @insert_keys = keys %$param;
packaging one directory
yuki-kimoto authored on 2009-11-16
106
    
107
    # Not exists insert keys
108
    croak("Key-value pairs for insert must be specified to 'insert' second argument")
109
      unless @insert_keys;
110
    
111
    # Templte for insert
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
112
    my $template = "insert into $table {insert "
113
                   . join(' ', @insert_keys) . '}';
removed register_format()
yuki-kimoto authored on 2010-05-26
114
    $template .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
115
    
116
    # Execute query
removed register_format()
yuki-kimoto authored on 2010-05-26
117
    my $ret_val = $self->execute($template, param  => $param, 
118
                                            filter => $filter);
packaging one directory
yuki-kimoto authored on 2009-11-16
119
    
120
    return $ret_val;
121
}
122

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
123
our %VALID_UPDATE_ARGS
removed register_format()
yuki-kimoto authored on 2010-05-26
124
  = map { $_ => 1 } qw/table param where append filter allow_update_all/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
125

            
packaging one directory
yuki-kimoto authored on 2009-11-16
126
sub update {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
127
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
128
    
129
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
130
    foreach my $name (keys %args) {
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
131
        croak "\"$name\" is invalid name"
132
          unless $VALID_UPDATE_ARGS{$name};
133
    }
134
    
135
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
136
    my $table            = $args{table} || '';
137
    my $param            = $args{param} || {};
138
    my $where            = $args{where} || {};
139
    my $append_statement = $args{append} || '';
140
    my $filter           = $args{filter};
141
    my $allow_update_all = $args{allow_update_all};
packaging one directory
yuki-kimoto authored on 2009-11-16
142
    
143
    # Update keys
removed register_format()
yuki-kimoto authored on 2010-05-26
144
    my @update_keys = keys %$param;
packaging one directory
yuki-kimoto authored on 2009-11-16
145
    
146
    # Not exists update kyes
147
    croak("Key-value pairs for update must be specified to 'update' second argument")
148
      unless @update_keys;
149
    
150
    # Where keys
removed register_format()
yuki-kimoto authored on 2010-05-26
151
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
152
    
153
    # Not exists where keys
154
    croak("Key-value pairs for where clause must be specified to 'update' third argument")
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
155
      if !@where_keys && !$allow_update_all;
packaging one directory
yuki-kimoto authored on 2009-11-16
156
    
157
    # Update clause
158
    my $update_clause = '{update ' . join(' ', @update_keys) . '}';
159
    
160
    # Where clause
161
    my $where_clause = '';
simplify filtering system
yuki-kimoto authored on 2010-05-01
162
    my $new_where = {};
many change
yuki-kimoto authored on 2010-04-30
163
    
packaging one directory
yuki-kimoto authored on 2009-11-16
164
    if (@where_keys) {
165
        $where_clause = 'where ';
166
        foreach my $where_key (@where_keys) {
simplify filtering system
yuki-kimoto authored on 2010-05-01
167
            
168
            $where_clause .= "{= $where_key} and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
169
        }
170
        $where_clause =~ s/ and $//;
171
    }
172
    
173
    # Template for update
174
    my $template = "update $table $update_clause $where_clause";
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
175
    $template .= " $append_statement" if $append_statement;
packaging one directory
yuki-kimoto authored on 2009-11-16
176
    
177
    # Rearrange parammeters
removed register_format()
yuki-kimoto authored on 2010-05-26
178
    foreach my $wkey (@where_keys) {
simplify filtering system
yuki-kimoto authored on 2010-05-01
179
        
removed register_format()
yuki-kimoto authored on 2010-05-26
180
        if (exists $param->{$wkey}) {
181
            $param->{$wkey} = [$param->{$wkey}]
182
              unless ref $param->{$wkey} eq 'ARRAY';
simplify filtering system
yuki-kimoto authored on 2010-05-01
183
            
removed register_format()
yuki-kimoto authored on 2010-05-26
184
            push @{$param->{$wkey}}, $where->{$wkey};
simplify filtering system
yuki-kimoto authored on 2010-05-01
185
        }
add tests
yuki-kimoto authored on 2010-05-01
186
        else {
removed register_format()
yuki-kimoto authored on 2010-05-26
187
            $param->{$wkey} = $where->{$wkey};
add tests
yuki-kimoto authored on 2010-05-01
188
        }
simplify filtering system
yuki-kimoto authored on 2010-05-01
189
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
190
    
191
    # Execute query
removed register_format()
yuki-kimoto authored on 2010-05-26
192
    my $ret_val = $self->execute($template, param  => $param, 
193
                                            filter => $filter);
packaging one directory
yuki-kimoto authored on 2009-11-16
194
    
195
    return $ret_val;
196
}
197

            
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
198
sub update_all { shift->update(allow_update_all => 1, @_) };
packaging one directory
yuki-kimoto authored on 2009-11-16
199

            
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
200
our %VALID_DELETE_ARGS
removed register_format()
yuki-kimoto authored on 2010-05-26
201
  = map { $_ => 1 } qw/table where append filter allow_delete_all/;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
202

            
packaging one directory
yuki-kimoto authored on 2009-11-16
203
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
204
    my ($self, %args) = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
205
    
206
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
207
    foreach my $name (keys %args) {
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
208
        croak "\"$name\" is invalid name"
209
          unless $VALID_DELETE_ARGS{$name};
210
    }
211
    
212
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
213
    my $table            = $args{table} || '';
214
    my $where            = $args{where} || {};
215
    my $append_statement = $args{append};
216
    my $filter           = $args{filter};
217
    my $allow_delete_all = $args{allow_delete_all};
packaging one directory
yuki-kimoto authored on 2009-11-16
218
    
219
    # Where keys
removed register_format()
yuki-kimoto authored on 2010-05-26
220
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
221
    
222
    # Not exists where keys
223
    croak("Key-value pairs for where clause must be specified to 'delete' second argument")
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
224
      if !@where_keys && !$allow_delete_all;
packaging one directory
yuki-kimoto authored on 2009-11-16
225
    
226
    # Where clause
227
    my $where_clause = '';
228
    if (@where_keys) {
229
        $where_clause = 'where ';
removed register_format()
yuki-kimoto authored on 2010-05-26
230
        foreach my $wkey (@where_keys) {
231
            $where_clause .= "{= $wkey} and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
232
        }
233
        $where_clause =~ s/ and $//;
234
    }
235
    
236
    # Template for delete
237
    my $template = "delete from $table $where_clause";
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
238
    $template .= " $append_statement" if $append_statement;
packaging one directory
yuki-kimoto authored on 2009-11-16
239
    
240
    # Execute query
removed register_format()
yuki-kimoto authored on 2010-05-26
241
    my $ret_val = $self->execute($template, param  => $where, 
242
                                            filter => $filter);
packaging one directory
yuki-kimoto authored on 2009-11-16
243
    
244
    return $ret_val;
245
}
246

            
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
247
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
248

            
refactoring select
yuki-kimoto authored on 2010-04-28
249
our %VALID_SELECT_ARGS
added commit method
yuki-kimoto authored on 2010-05-27
250
  = map { $_ => 1 } qw/table column where append relation filter param/;
refactoring select
yuki-kimoto authored on 2010-04-28
251

            
packaging one directory
yuki-kimoto authored on 2009-11-16
252
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
253
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
254
    
refactoring select
yuki-kimoto authored on 2010-04-28
255
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
256
    foreach my $name (keys %args) {
refactoring select
yuki-kimoto authored on 2010-04-28
257
        croak "\"$name\" is invalid name"
258
          unless $VALID_SELECT_ARGS{$name};
259
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
260
    
refactoring select
yuki-kimoto authored on 2010-04-28
261
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
262
    my $tables = $args{table} || [];
removed register_format()
yuki-kimoto authored on 2010-05-26
263
    $tables = [$tables] unless ref $tables eq 'ARRAY';
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
264
    my $columns  = $args{column} || [];
265
    my $where    = $args{where} || {};
266
    my $relation = $args{relation};
267
    my $append   = $args{append};
268
    my $filter   = $args{filter};
269
    my $param    = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
270
    
271
    # SQL template for select statement
272
    my $template = 'select ';
273
    
added commit method
yuki-kimoto authored on 2010-05-27
274
    # Column clause
packaging one directory
yuki-kimoto authored on 2009-11-16
275
    if (@$columns) {
276
        foreach my $column (@$columns) {
277
            $template .= "$column, ";
278
        }
279
        $template =~ s/, $/ /;
280
    }
281
    else {
282
        $template .= '* ';
283
    }
284
    
added commit method
yuki-kimoto authored on 2010-05-27
285
    # Table
packaging one directory
yuki-kimoto authored on 2009-11-16
286
    $template .= 'from ';
287
    foreach my $table (@$tables) {
288
        $template .= "$table, ";
289
    }
290
    $template =~ s/, $/ /;
291
    
added commit method
yuki-kimoto authored on 2010-05-27
292
    # Where clause
293
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
294
    if (@where_keys) {
295
        $template .= 'where ';
296
        foreach my $where_key (@where_keys) {
compile success
yuki-kimoto authored on 2010-05-01
297
            $template .= "{= $where_key} and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
298
        }
299
    }
300
    $template =~ s/ and $//;
301
    
added commit method
yuki-kimoto authored on 2010-05-27
302
    # Relation
303
    if ($relation) {
304
        $template .= @where_keys ? "and " : "where ";
305
        foreach my $rkey (keys %$relation) {
306
            $template .= "$rkey = " . $relation->{$rkey} . " and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
307
        }
308
    }
added commit method
yuki-kimoto authored on 2010-05-27
309
    $template =~ s/ and $//;
310
    
311
    # Append some statement
312
    $template .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
313
    
314
    # Execute query
added commit method
yuki-kimoto authored on 2010-05-27
315
    my $result = $self->execute($template, param  => $where, 
removed register_format()
yuki-kimoto authored on 2010-05-26
316
                                           filter => $filter);
packaging one directory
yuki-kimoto authored on 2009-11-16
317
    
318
    return $result;
319
}
320

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
321
sub create_query {
322
    my ($self, $template) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
323
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
324
    # Create query from SQL template
325
    my $sql_template = $self->sql_template;
removed register_format()
yuki-kimoto authored on 2010-05-26
326
    
added cache_method attribute
yuki-kimoto authored on 2010-06-25
327
    my $cache = $self->cache;
version 0.0901
yuki-kimoto authored on 2009-12-17
328
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
329
    # Create query
330
    my $query;
added cache_method attribute
yuki-kimoto authored on 2010-06-25
331
    if ($cache) {
332
        
333
        # Cached query
334
        my $q = $self->cache_method->($self, $template);
335
        
336
        # Create query
337
        $query = DBIx::Custom::Query->new($q) if $q;
removed reconnect method
yuki-kimoto authored on 2010-05-28
338
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
339
    
340
    unless ($query) {
341
        
342
        # Create query
removed reconnect method
yuki-kimoto authored on 2010-05-28
343
        $query = eval{$sql_template->create_query($template)};
344
        croak($@) if $@;
345
        
added cache_method attribute
yuki-kimoto authored on 2010-06-25
346
        # Cache query
347
        $self->cache_method->($self, $template,
348
                             {sql     => $query->sql, 
349
                              columns => $query->columns})
350
          if $cache;
removed reconnect method
yuki-kimoto authored on 2010-05-28
351
    }
version 0.0901
yuki-kimoto authored on 2009-12-17
352
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
353
    # Prepare statement handle
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
354
    my $sth = eval {$self->dbh->prepare($query->{sql})};
355
    croak $@ if $@;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
356
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
357
    # Set statement handle
358
    $query->sth($sth);
359
    
360
    return $query;
361
}
362

            
363
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter/;
364

            
365
sub execute{
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
366
    my ($self, $query, %args)  = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
367
    
368
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
369
    foreach my $name (keys %args) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
370
        croak "\"$name\" is invalid name"
371
          unless $VALID_EXECUTE_ARGS{$name};
372
    }
373
    
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
374
    my $params = $args{param} || {};
removed reconnect method
yuki-kimoto authored on 2010-05-28
375
    
376
    # First argument is SQL template
377
    unless (ref $query eq 'DBIx::Custom::Query') {
378
        my $template;
379
        
380
        if (ref $query eq 'ARRAY') {
381
            $template = $query->[0];
382
        }
383
        else { $template = $query }
384
        
385
        $query = $self->create_query($template);
386
    }
387
    
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
388
    my $filter = $args{filter} || $query->filter || {};
removed reconnect method
yuki-kimoto authored on 2010-05-28
389
    
390
    # Create bind value
391
    my $bind_values = $self->_build_bind_values($query, $params, $filter);
392
    
393
    # Execute
394
    my $sth      = $query->sth;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
395
    my $affected = eval {$sth->execute(@$bind_values)};
396
    croak $@ if $@;
removed reconnect method
yuki-kimoto authored on 2010-05-28
397
    
398
    # Return resultset if select statement is executed
399
    if ($sth->{NUM_OF_FIELDS}) {
400
        
401
        # Get result class
402
        my $result_class = $self->result_class;
403
        
404
        # Create result
405
        my $result = $result_class->new({
406
            sth             => $sth,
407
            default_filter  => $self->default_fetch_filter,
408
            filters         => $self->filters
409
        });
410
        return $result;
411
    }
412
    return $affected;
413
}
414

            
415
sub _build_bind_values {
416
    my ($self, $query, $params, $filter) = @_;
417
    
418
    # binding values
419
    my @bind_values;
420
    
421
    # Build bind values
422
    my $count = {};
423
    foreach my $column (@{$query->columns}) {
424
        
425
        croak "\"$column\" is not exists in params"
426
          unless exists $params->{$column};
427
        
428
        # Value
429
        my $value = ref $params->{$column} eq 'ARRAY'
430
                  ? $params->{$column}->[$count->{$column} || 0]
431
                  : $params->{$column};
432
        
433
        # Filter
434
        $filter ||= {};
435
        
436
        # Filter name
437
        my $fname = $filter->{$column} || $self->default_query_filter || '';
438
        
439
        my $filter_func;
440
        if ($fname) {
441
            
442
            if (ref $fname eq 'CODE') {
443
                $filter_func = $fname;
444
            }
445
            else {
446
                my $filters = $self->filters;
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
447
                croak "Not exists filter \"$fname\""
448
                  unless exists $filters->{$fname};
removed reconnect method
yuki-kimoto authored on 2010-05-28
449
                $filter_func = $filters->{$fname};
450
            }            
451
        }
452
        
453
        push @bind_values, $filter_func
454
                         ? $filter_func->($value)
455
                         : $value;
456
        
457
        # Count up 
458
        $count->{$column}++;
459
    }
460
    
461
    return \@bind_values;
462
}
463

            
464
=head1 NAME
465

            
466
DBIx::Custom - DBI with hash parameter binding and filtering system
467

            
468
=cut
469

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
470
our $VERSION = '0.1604';
removed reconnect method
yuki-kimoto authored on 2010-05-28
471

            
472
=head1 STABILITY
473

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
474
This module is not stable. Method name and implementations will be changed.
removed reconnect method
yuki-kimoto authored on 2010-05-28
475

            
476
=head1 SYNOPSYS
477
    
478
    # Connect
479
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books",
480
                                    user => 'ken', password => '!LFKD%$&');
481
    # Insert 
482
    $dbi->insert(table  => 'books',
483
                 param  => {title => 'perl', author => 'Ken'},
484
                 filter => {title => 'encode_utf8'});
485
    
486
    # Update 
487
    $dbi->update(table  => 'books', 
488
                 param  => {title => 'aaa', author => 'Ken'}, 
489
                 where  => {id => 5},
490
                 filter => {title => 'encode_utf8'});
491
    
492
    # Update all
493
    $dbi->update_all(table  => 'books',
494
                     param  => {title => 'aaa'},
495
                     filter => {title => 'encode_utf8'});
496
    
497
    # Delete
498
    $dbi->delete(table  => 'books',
499
                 where  => {author => 'Ken'},
500
                 filter => {title => 'encode_utf8'});
501
    
502
    # Delete all
503
    $dbi->delete_all(table => 'books');
504
    
505
    # Select
506
    my $result = $dbi->select(table => 'books');
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
507
    
removed register_format()
yuki-kimoto authored on 2010-05-26
508
    # Select(more complex)
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
509
    my $result = $dbi->select(
update document
yuki-kimoto authored on 2010-05-27
510
        table  => 'books',
511
        column => [qw/author title/],
512
        where  => {author => 'Ken'},
513
        append => 'order by id limit 1',
514
        filter => {tilte => 'encode_utf8'}
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
515
    );
added commit method
yuki-kimoto authored on 2010-05-27
516
    
517
    # Select(Join table)
518
    my $result = $dbi->select(
519
        table => ['books', 'rental'],
520
        column => ['books.name as book_name']
521
        relation => {'books.id' => 'rental.book_id'}
522
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
523
    
removed register_format()
yuki-kimoto authored on 2010-05-26
524
    # Execute SQL
525
    $dbi->execute("select title from books");
526
    
527
    # Execute SQL with parameters and filter
528
    $dbi->execute("select id from books where {= author} && {like title}",
529
                  param  => {author => 'ken', title => '%Perl%'},
530
                  filter => {tilte => 'encode_utf8'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
531

            
532
    # Create query and execute it
533
    my $query = $dbi->create_query(
534
        "select id from books where {= author} && {like title}"
535
    );
536
    $dbi->execute($query, param => {author => 'ken', title => '%Perl%'})
removed register_format()
yuki-kimoto authored on 2010-05-26
537
    
538
    # Default filter
539
    $dbi->default_query_filter('encode_utf8');
540
    $dbi->default_fetch_filter('decode_utf8');
541
    
542
    # Fetch
543
    while (my $row = $result->fetch) {
544
        # ...
545
    }
546
    
547
    # Fetch hash
548
    while (my $row = $result->fetch_hash) {
549
        
550
    }
551
    
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
552
    # Get DBI object
update document
yuki-kimoto authored on 2010-05-27
553
    my $dbh = $dbi->dbh;
removed reconnect method
yuki-kimoto authored on 2010-05-28
554

            
555
=head1 DESCRIPTION
556

            
557
L<DBIx::Custom> is useful L<DBI> extention.
558
This module have hash parameter binding and filtering system.
559

            
560
Normally, binding parameter is array.
561
L<DBIx::Custom> enable you to pass binding parameter as hash.
562

            
563
This module also provide filtering system.
564
You can filter the binding parameter
565
or the value of fetching row.
566

            
567
And have useful method such as insert(), update(), delete(), and select().
568

            
569
=head2 Features
570

            
571
=over 4
572

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
573
=item *
removed reconnect method
yuki-kimoto authored on 2010-05-28
574

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
575
Hash parameter binding.
removed reconnect method
yuki-kimoto authored on 2010-05-28
576

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
577
=item *
578

            
579
Value filtering.
580

            
581
=item *
582

            
583
Provide suger methods, such as insert(), update(), delete(), and select().
removed reconnect method
yuki-kimoto authored on 2010-05-28
584

            
585
=back
586

            
update document
yuki-kimoto authored on 2010-01-30
587
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
588

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
589
=head2 C<user>
packaging one directory
yuki-kimoto authored on 2009-11-16
590

            
version 0.0901
yuki-kimoto authored on 2009-12-17
591
    $dbi  = $dbi->user('Ken');
592
    $user = $dbi->user;
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
593

            
594
Database user name.
595
This is used for connect().
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
596
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
597
=head2 C<password>
packaging one directory
yuki-kimoto authored on 2009-11-16
598

            
version 0.0901
yuki-kimoto authored on 2009-12-17
599
    $dbi      = $dbi->password('lkj&le`@s');
600
    $password = $dbi->password;
packaging one directory
yuki-kimoto authored on 2009-11-16
601

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
602
Database password.
603
This is used for connect().
604

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
605
=head2 C<data_source>
packaging one directory
yuki-kimoto authored on 2009-11-16
606

            
version 0.0901
yuki-kimoto authored on 2009-12-17
607
    $dbi         = $dbi->data_source("dbi:mysql:dbname=$database");
608
    $data_source = $dbi->data_source;
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
609

            
610
Database data source.
611
This is used for connect().
612

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
613
=head2 C<dbh>
packaging one directory
yuki-kimoto authored on 2009-11-16
614

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
615
    $dbi = $dbi->dbh($dbh);
616
    $dbh = $dbi->dbh;
packaging one directory
yuki-kimoto authored on 2009-11-16
617

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
618
Database handle. This is a L<DBI> object.
619
You can call all methods of L<DBI>
packaging one directory
yuki-kimoto authored on 2009-11-16
620

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
621
    my $sth    = $dbi->dbh->prepare("...");
622
    my $errstr = $dbi->dbh->errstr;
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
623
    $dbi->dbh->begin_work;
624
    $dbi->dbh->commit;
625
    $dbi->dbh->rollback;
removed reconnect method
yuki-kimoto authored on 2010-05-28
626
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
627
=head2 C<filters>
packaging one directory
yuki-kimoto authored on 2009-11-16
628

            
update document
yuki-kimoto authored on 2010-05-27
629
    $dbi     = $dbi->filters({%filters});
version 0.0901
yuki-kimoto authored on 2009-12-17
630
    $filters = $dbi->filters;
631

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
632
Filter functions.
633
By default, "encode_utf8" and "decode_utf8" is registered.
version 0.0901
yuki-kimoto authored on 2009-12-17
634

            
update document
yuki-kimoto authored on 2010-05-27
635
    $encode_utf8 = $dbi->filters->{encode_utf8};
636
    $decode_utf8 = $dbi->filters->{decode_utf8};
packaging one directory
yuki-kimoto authored on 2009-11-16
637

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
638
=head2 C<default_query_filter>
packaging one directory
yuki-kimoto authored on 2009-11-16
639

            
update document
yuki-kimoto authored on 2010-05-27
640
    $dbi                  = $dbi->default_query_filter('encode_utf8');
rename bind_filter to query_...
yuki-kimoto authored on 2010-04-28
641
    $default_query_filter = $dbi->default_query_filter
packaging one directory
yuki-kimoto authored on 2009-11-16
642

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
643
Default filter for value binding
packaging one directory
yuki-kimoto authored on 2009-11-16
644

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
645
=head2 C<default_fetch_filter>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
646

            
update document
yuki-kimoto authored on 2010-05-27
647
    $dbi                  = $dbi->default_fetch_filter('decode_utf8');
cleanup
yuki-kimoto authored on 2010-04-28
648
    $default_fetch_filter = $dbi->default_fetch_filter;
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
649

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
650
Default filter for fetching.
packaging one directory
yuki-kimoto authored on 2009-11-16
651

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
652
=head2 C<result_class>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
653

            
version 0.0901
yuki-kimoto authored on 2009-12-17
654
    $dbi          = $dbi->result_class('DBIx::Custom::Result');
packaging one directory
yuki-kimoto authored on 2009-11-16
655
    $result_class = $dbi->result_class;
656

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
657
Result class for select statement.
658
Default to L<DBIx::Custom::Result>
update document
yuki-kimoto authored on 2010-01-30
659

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
660
=head2 C<sql_template>
added commit method
yuki-kimoto authored on 2010-05-27
661

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
662
    $dbi          = $dbi->sql_template(DBIx::Cutom::SQLTemplate->new);
663
    $sql_template = $dbi->sql_template;
added commit method
yuki-kimoto authored on 2010-05-27
664

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
665
SQLTemplate instance. sql_template attribute must be 
666
the instance of L<DBIx::Cutom::SQLTemplate> subclass.
667
Default to DBIx::Cutom::SQLTemplate object
added commit method
yuki-kimoto authored on 2010-05-27
668

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
669
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
670

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
671
This class is L<Object::Simple> subclass.
672
You can use all methods of L<Object::Simple>
added commit method
yuki-kimoto authored on 2010-05-27
673

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
674
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
675

            
update document
yuki-kimoto authored on 2010-05-27
676
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books",
677
                                    user => 'ken', password => '!LFKD%$&');
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
678

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
679
Connect to database.
update document
yuki-kimoto authored on 2010-05-27
680
"AutoCommit" and "RaiseError" option is true, 
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
681
and "PrintError" option is false by default.
packaging one directory
yuki-kimoto authored on 2009-11-16
682

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
683
=head2 C<insert>
packaging one directory
yuki-kimoto authored on 2009-11-16
684

            
removed register_format()
yuki-kimoto authored on 2010-05-26
685
    $affected = $dbi->insert(table  => $table, 
686
                             param  => {%param},
687
                             append => $append,
688
                             filter => {%filter});
update document
yuki-kimoto authored on 2009-11-19
689

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
690
Insert row.
691
Retrun value is the count of affected rows.
packaging one directory
yuki-kimoto authored on 2009-11-16
692
    
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
693
B<Example:>
version 0.0901
yuki-kimoto authored on 2009-12-17
694

            
removed register_format()
yuki-kimoto authored on 2010-05-26
695
    $dbi->insert(table  => 'books', 
696
                 param  => {title => 'Perl', author => 'Taro'},
697
                 append => "some statement",
698
                 filter => {title => 'encode_utf8'})
version 0.0901
yuki-kimoto authored on 2009-12-17
699

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
700
=head2 C<update>
packaging one directory
yuki-kimoto authored on 2009-11-16
701

            
removed register_format()
yuki-kimoto authored on 2010-05-26
702
    $affected = $dbi->update(table  => $table, 
703
                             param  => {%params},
704
                             where  => {%where},
705
                             append => $append,
706
                             filter => {%filter})
version 0.0901
yuki-kimoto authored on 2009-12-17
707

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
708
Update rows.
709
Retrun value is the count of affected rows.
update document
yuki-kimoto authored on 2009-11-19
710

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
711
B<Example:>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
712

            
removed register_format()
yuki-kimoto authored on 2010-05-26
713
    $dbi->update(table  => 'books',
714
                 param  => {title => 'Perl', author => 'Taro'},
715
                 where  => {id => 5},
716
                 append => "some statement",
added commit method
yuki-kimoto authored on 2010-05-27
717
                 filter => {title => 'encode_utf8'});
version 0.0901
yuki-kimoto authored on 2009-12-17
718

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
719
=head2 C<update_all>
packaging one directory
yuki-kimoto authored on 2009-11-16
720

            
removed register_format()
yuki-kimoto authored on 2010-05-26
721
    $affected = $dbi->update_all(table  => $table, 
722
                                 param  => {%params},
723
                                 filter => {%filter},
724
                                 append => $append);
update document
yuki-kimoto authored on 2009-11-19
725

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
726
Update all rows.
727
Retrun value is the count of affected rows.
version 0.0901
yuki-kimoto authored on 2009-12-17
728

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
729
B<Example:>
update document
yuki-kimoto authored on 2009-11-19
730

            
removed register_format()
yuki-kimoto authored on 2010-05-26
731
    $dbi->update_all(table  => 'books', 
732
                     param  => {author => 'taro'},
733
                     filter => {author => 'encode_utf8'});
packaging one directory
yuki-kimoto authored on 2009-11-16
734

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
735
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
736

            
removed register_format()
yuki-kimoto authored on 2010-05-26
737
    $affected = $dbi->delete(table  => $table,
738
                             where  => {%where},
added commit method
yuki-kimoto authored on 2010-05-27
739
                             append => $append,
removed register_format()
yuki-kimoto authored on 2010-05-26
740
                             filter => {%filter});
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
741

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
742
Delete rows.
743
Retrun value is the count of affected rows.
packaging one directory
yuki-kimoto authored on 2009-11-16
744
    
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
745
B<Example:>
packaging one directory
yuki-kimoto authored on 2009-11-16
746

            
removed register_format()
yuki-kimoto authored on 2010-05-26
747
    $dbi->delete(table  => 'books',
748
                 where  => {id => 5},
749
                 append => 'some statement',
removed reconnect method
yuki-kimoto authored on 2010-05-28
750
                 filter => {id => 'encode_utf8'});
version 0.0901
yuki-kimoto authored on 2009-12-17
751

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
752
=head2 C<delete_all>
packaging one directory
yuki-kimoto authored on 2009-11-16
753

            
removed register_format()
yuki-kimoto authored on 2010-05-26
754
    $affected = $dbi->delete_all(table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
755

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
756
Delete all rows.
757
Retrun value is the count of affected rows.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
758

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
759
B<Example:>
removed register_format()
yuki-kimoto authored on 2010-05-26
760
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
761
    $dbi->delete_all(table => 'books');
packaging one directory
yuki-kimoto authored on 2009-11-16
762

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
763
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
764
    
added commit method
yuki-kimoto authored on 2010-05-27
765
    $result = $dbi->select(table    => $table,
766
                           column   => [@column],
767
                           where    => {%where},
768
                           append   => $append,
removed reconnect method
yuki-kimoto authored on 2010-05-28
769
                           relation => {%relation},
added commit method
yuki-kimoto authored on 2010-05-27
770
                           filter   => {%filter});
update document
yuki-kimoto authored on 2009-11-19
771

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
772
Select rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
773
Return value is the instance of L<DBIx::Custom::Result>.
update document
yuki-kimoto authored on 2009-11-19
774

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
775
B<Example:>
update document
yuki-kimoto authored on 2009-11-19
776

            
added commit method
yuki-kimoto authored on 2010-05-27
777
    # select * from books;
removed reconnect method
yuki-kimoto authored on 2010-05-28
778
    $result = $dbi->select(table => 'books');
packaging one directory
yuki-kimoto authored on 2009-11-16
779
    
update document
yuki-kimoto authored on 2009-11-19
780
    # select * from books where title = 'Perl';
removed reconnect method
yuki-kimoto authored on 2010-05-28
781
    $result = $dbi->select(table => 'books', where => {title => 1});
update document
yuki-kimoto authored on 2009-11-19
782
    
783
    # select title, author from books where id = 1 for update;
784
    $result = $dbi->select(
removed register_format()
yuki-kimoto authored on 2010-05-26
785
        table  => 'books',
removed reconnect method
yuki-kimoto authored on 2010-05-28
786
        column => ['title', 'author'],
removed register_format()
yuki-kimoto authored on 2010-05-26
787
        where  => {id => 1},
788
        appned => 'for update'
update document
yuki-kimoto authored on 2009-11-19
789
    );
790
    
added commit method
yuki-kimoto authored on 2010-05-27
791
    # select books.name as book_name from books, rental 
792
    # where books.id = rental.book_id;
793
    my $result = $dbi->select(
removed reconnect method
yuki-kimoto authored on 2010-05-28
794
        table    => ['books', 'rental'],
795
        column   => ['books.name as book_name']
added commit method
yuki-kimoto authored on 2010-05-27
796
        relation => {'books.id' => 'rental.book_id'}
update document
yuki-kimoto authored on 2009-11-19
797
    );
798

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
799
=head2 C<create_query>
removed reconnect method
yuki-kimoto authored on 2010-05-28
800
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
801
    my $query = $dbi->create_query(
802
        "select * from authors where {= name} and {= age};"
803
    );
804

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
805
Create the instance of L<DBIx::Custom::Query>. 
806
This receive the string written by SQL template.
packaging one directory
yuki-kimoto authored on 2009-11-16
807

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
808
=head2 C<execute>
removed reconnect method
yuki-kimoto authored on 2010-05-28
809

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
810
    $result = $dbi->execute($query,    param => $params, filter => {%filter});
811
    $result = $dbi->execute($template, param => $params, filter => {%filter});
removed reconnect method
yuki-kimoto authored on 2010-05-28
812

            
813
Execute the instace of L<DBIx::Custom::Query> or
814
the string written by SQL template.
815
Return value is the instance of L<DBIx::Custom::Result>.
816

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
817
B<Example:>
removed reconnect method
yuki-kimoto authored on 2010-05-28
818

            
819
    $result = $dbi->execute("select * from authors where {= name} and {= age}", 
820
                            param => {name => 'taro', age => 19});
821
    
822
    while (my $row = $result->fetch) {
823
        # do something
824
    }
825

            
826
See also L<DBIx::Custom::SQLTemplate> to know how to write SQL template.
827

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
828
=head2 C<register_filter>
removed reconnect method
yuki-kimoto authored on 2010-05-28
829

            
830
    $dbi->register_filter(%filters);
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
831
    $dbi->register_filter(\%filters);
removed reconnect method
yuki-kimoto authored on 2010-05-28
832
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
833
Resister filter.
834

            
835
B<Example:>
packaging one directory
yuki-kimoto authored on 2009-11-16
836

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
837
    $dbi->register_filter(
838
        encode_utf8 => sub {
839
            my $value = shift;
840
            
841
            require Encode;
842
            
843
            return Encode::encode('UTF-8', $value);
844
        },
845
        decode_utf8 => sub {
846
            my $value = shift;
847
            
848
            require Encode;
849
            
850
            return Encode::decode('UTF-8', $value)
851
        }
852
    );
853

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
854
=head2 C<cache>
added cache_method attribute
yuki-kimoto authored on 2010-06-25
855

            
856
    $dbi   = $dbi->cache(1);
857
    $cache = $dbi->cache;
858

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
859
Cache the result of parsing SQL template.
added cache_method attribute
yuki-kimoto authored on 2010-06-25
860
Default to 1.
861

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
862
=head2 C<cache_method>
863

            
864
    $dbi          = $dbi->cache_method(\&cache_method);
865
    $cache_method = $dbi->cache_method
added cache_method attribute
yuki-kimoto authored on 2010-06-25
866

            
867
Method for cache.
868

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
869
B<Example:>
added cache_method attribute
yuki-kimoto authored on 2010-06-25
870

            
871
    $dbi->cache_method(
872
        sub {
873
            my $self = shift;
874
            
875
            $self->{_cached} ||= {};
876
            
877
            if (@_ > 1) {
878
                $self->{_cached}{$_[0]} = $_[1] 
879
            }
880
            else {
881
                return $self->{_cached}{$_[0]}
882
            }
883
        }
884
    );
885

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
886
=head1 BUGS
887

            
888
Please tell me bugs.
889

            
890
C<< <kimoto.yuki at gmail.com> >>
891

            
892
L<http://github.com/yuki-kimoto/DBIx-Custom>
893

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
894
=head1 AUTHOR
895

            
896
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
version 0.0901
yuki-kimoto authored on 2009-12-17
897

            
packaging one directory
yuki-kimoto authored on 2009-11-16
898
=head1 COPYRIGHT & LICENSE
899

            
900
Copyright 2009 Yuki Kimoto, all rights reserved.
901

            
902
This program is free software; you can redistribute it and/or modify it
903
under the same terms as Perl itself.
904

            
905
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
906

            
907