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

            
cleanup
Yuki Kimoto authored on 2010-12-22
3
our $VERSION = '0.1624';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
update document
yuki-kimoto authored on 2010-05-27
16
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
17

            
cleanup
Yuki Kimoto authored on 2010-12-21
18
__PACKAGE__->attr([qw/data_source dbh
19
                      dbi_options password user/]);
added cache_method attribute
yuki-kimoto authored on 2010-06-25
20

            
add cache attribute
yuki-kimoto authored on 2010-06-14
21
__PACKAGE__->attr(cache => 1);
added cache_method attribute
yuki-kimoto authored on 2010-06-25
22
__PACKAGE__->attr(cache_method => sub {
23
    sub {
24
        my $self = shift;
25
        
26
        $self->{_cached} ||= {};
27
        
28
        if (@_ > 1) {
29
            $self->{_cached}{$_[0]} = $_[1] 
30
        }
31
        else {
32
            return $self->{_cached}{$_[0]}
33
        }
34
    }
35
});
removed register_format()
yuki-kimoto authored on 2010-05-26
36

            
cleanup (removed undocumente...
yuki-kimoto authored on 2010-11-10
37
__PACKAGE__->attr(filters => sub {
38
    {
39
        encode_utf8 => sub { encode_utf8($_[0]) },
40
        decode_utf8 => sub { decode_utf8($_[0]) }
41
    }
42
});
added check_filter attribute
yuki-kimoto authored on 2010-08-08
43
__PACKAGE__->attr(filter_check => 1);
cleanup
yuki-kimoto authored on 2010-10-17
44
__PACKAGE__->attr(query_builder  => sub {DBIx::Custom::QueryBuilder->new});
45
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result');
46

            
47
# DBI methods
48
foreach my $method (qw/begin_work commit rollback/) {
49
    my $code = sub {
50
        my $self = shift;
51
        my $ret = eval {$self->dbh->$method};
52
        croak $@ if $@;
53
        return $ret;
54
    };
55
    no strict 'refs';
56
    my $pkg = __PACKAGE__;
57
    *{"${pkg}::$method"} = $code;
58
};
59

            
added helper method
yuki-kimoto authored on 2010-10-17
60
our $AUTOLOAD;
61

            
62
sub AUTOLOAD {
63
    my $self = shift;
64

            
65
    # Method
66
    my ($package, $method) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
67

            
68
    # Helper
69
    $self->{_helpers} ||= {};
70
    croak qq/Can't locate object method "$method" via "$package"/
71
      unless my $helper = $self->{_helpers}->{$method};
72

            
73
    # Run
74
    return $self->$helper(@_);
75
}
76

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
77
sub auto_filter {
78
    my $self = shift;
79
    
cleanup
Yuki Kimoto authored on 2010-12-22
80
    $self->{auto_filter} ||= {};
81
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
82
    # Table
83
    my $table = shift;
84
    
cleanup
Yuki Kimoto authored on 2010-12-22
85
    if (@_) {
86
        # Column infomations
87
        my @cs = @_;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
88
        
cleanup
Yuki Kimoto authored on 2010-12-22
89
        # Initialize filters
90
        $self->{auto_filter}{bind} ||= {};
91
        $self->{auto_filter}{fetch} ||= {};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
92
        
cleanup
Yuki Kimoto authored on 2010-12-22
93
        # Create auto filters
94
        foreach my $c (@cs) {
95
            croak "Usage \$dbi->auto_filter(" .
96
                  "TABLE, [COLUMN, BIND_FILTER, FETCH_FILTER], [...])"
97
              unless ref $c eq 'ARRAY' && @$c == 3;
98
            
99
            # Column
100
            my $column = $c->[0];
101
            
102
            # Bind filter
103
            my $bind_filter  = $c->[1];
104
            if (ref $bind_filter eq 'CODE') {
105
    	        $self->{auto_filter}{bind}{$table}{$column}
106
    	          = $bind_filter;
107
    	        $self->{auto_filter}{bind}{$table}{"$table.$column"}
108
    	          = $bind_filter;
109
            }
110
            else {
111
    	        croak qq{"$bind_filter" is not registered}
112
    	          unless exists $self->filters->{$bind_filter};
113
    	        
114
    	        $self->{auto_filter}{bind}{$table}{$column}
115
    	          = $self->filters->{$bind_filter};
116
    	        $self->{auto_filter}{bind}{$table}{"$table.$column"}
117
    	          = $self->filters->{$bind_filter};
118
    	    }
119
            
120
            # Fetch filter
121
            my $fetch_filter = $c->[2];
122
            if (ref $fetch_filter eq 'CODE') {
123
    	        $self->{auto_filter}{fetch}{$table}{$column}
124
    	          = $fetch_filter;
125
    	        $self->{auto_filter}{fetch}{$table}{"$table.$column"}
126
    	          = $fetch_filter;
127
            }
128
            else {
129
                croak qq{"$fetch_filter" is not registered}
130
                  unless exists $self->filters->{$fetch_filter};
131
                $self->{auto_filter}{fetch}{$table}{$column}
132
                  = $self->filters->{$fetch_filter};
133
                $self->{auto_filter}{fetch}{$table}{"$table.$column"}
134
                  = $self->filters->{$fetch_filter};
135
            }
cleanup
Yuki Kimoto authored on 2010-12-21
136
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
137
        
cleanup
Yuki Kimoto authored on 2010-12-22
138
        return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
139
    }
140
    
cleanup
Yuki Kimoto authored on 2010-12-22
141
    return $self->{auto_filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
142
}
143

            
added helper method
yuki-kimoto authored on 2010-10-17
144
sub helper {
145
    my $self = shift;
146
    
147
    # Merge
148
    my $helpers = ref $_[0] eq 'HASH' ? $_[0] : {@_};
149
    $self->{_helpers} = {%{$self->{_helpers} || {}}, %$helpers};
150
    
151
    return $self;
152
}
153

            
packaging one directory
yuki-kimoto authored on 2009-11-16
154
sub connect {
removed register_format()
yuki-kimoto authored on 2010-05-26
155
    my $proto = shift;
156
    
157
    # Create
158
    my $self = ref $proto ? $proto : $proto->new(@_);
update document
yuki-kimoto authored on 2010-01-30
159
    
160
    # Information
packaging one directory
yuki-kimoto authored on 2009-11-16
161
    my $data_source = $self->data_source;
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
162
    
163
    croak qq{"data_source" must be specfied to connect method"}
164
      unless $data_source;
165
    
packaging one directory
yuki-kimoto authored on 2009-11-16
166
    my $user        = $self->user;
167
    my $password    = $self->password;
added dbi_options attribute
kimoto authored on 2010-12-20
168
    my $dbi_options = $self->dbi_options || {};
169
    
update document
yuki-kimoto authored on 2010-01-30
170
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
171
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
172
        $data_source,
173
        $user,
174
        $password,
175
        {
176
            RaiseError => 1,
177
            PrintError => 0,
178
            AutoCommit => 1,
added dbi_options attribute
kimoto authored on 2010-12-20
179
            %$dbi_options
packaging one directory
yuki-kimoto authored on 2009-11-16
180
        }
181
    )};
182
    
update document
yuki-kimoto authored on 2010-01-30
183
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
184
    croak $@ if $@;
185
    
update document
yuki-kimoto authored on 2010-01-30
186
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
187
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
188
    
packaging one directory
yuki-kimoto authored on 2009-11-16
189
    return $self;
190
}
191

            
cleanup
yuki-kimoto authored on 2010-10-17
192
sub create_query {
193
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
194
    
cleanup
yuki-kimoto authored on 2010-10-17
195
    # Cache
196
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
197
    
cleanup
yuki-kimoto authored on 2010-10-17
198
    # Create query
199
    my $query;
200
    if ($cache) {
201
        
202
        # Get query
203
        my $q = $self->cache_method->($self, $source);
204
        
205
        # Create query
206
        $query = DBIx::Custom::Query->new($q) if $q;
207
    }
208
    
209
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
210

            
cleanup
yuki-kimoto authored on 2010-10-17
211
        # Create SQL object
212
        my $builder = $self->query_builder;
213
        
214
        # Create query
215
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
216

            
cleanup
yuki-kimoto authored on 2010-10-17
217
        # Cache query
218
        $self->cache_method->($self, $source,
219
                             {sql     => $query->sql, 
220
                              columns => $query->columns})
221
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
222
    }
223
    
cleanup
yuki-kimoto authored on 2010-10-17
224
    # Prepare statement handle
225
    my $sth;
226
    eval { $sth = $self->dbh->prepare($query->{sql})};
227
    $self->_croak($@, qq{. SQL: "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
228
    
cleanup
yuki-kimoto authored on 2010-10-17
229
    # Set statement handle
230
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
231
    
cleanup
yuki-kimoto authored on 2010-10-17
232
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
233
}
234

            
cleanup
Yuki Kimoto authored on 2010-12-21
235
sub default_bind_filter {
236
    my $self = shift;
237
    
cleanup
Yuki Kimoto authored on 2010-12-22
238
    if (@_) {
239
        my $fname = $_[0];
240
        
241
        if (@_ && !$fname) {
242
            $self->{default_bind_filter} = undef;
243
        }
244
        else {
245
            croak qq{"$fname" is not registered}
246
              unless exists $self->filters->{$fname};
247
        
248
            $self->{default_bind_filter} = $self->filters->{$fname};
249
        }
250
        return $self;
cleanup
Yuki Kimoto authored on 2010-12-21
251
    }
252
    
cleanup
Yuki Kimoto authored on 2010-12-22
253
    return $self->{default_bind_filter};
cleanup
Yuki Kimoto authored on 2010-12-21
254
}
255

            
256
sub default_fetch_filter {
257
    my $self = shift;
258
    my $fname = $_[0];
259
    
cleanup
Yuki Kimoto authored on 2010-12-22
260
    if (@_) {
261
        if (@_ && !$fname) {
262
            $self->{default_fetch_filter} = undef;
263
        }
264
        else {
265
            croak qq{"$fname" is not registered}
266
              unless exists $self->filters->{$fname};
267
        
268
            $self->{default_fetch_filter} = $self->filters->{$fname};
269
        }
270
        
271
        return $self;
cleanup
Yuki Kimoto authored on 2010-12-21
272
    }
273
    
cleanup
Yuki Kimoto authored on 2010-12-22
274
    return $self->{default_fetch_filter}
cleanup
Yuki Kimoto authored on 2010-12-21
275
}
276

            
cleanup
yuki-kimoto authored on 2010-10-17
277
our %VALID_DELETE_ARGS
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
278
  = map { $_ => 1 } qw/auto_filter_table table where append filter allow_delete_all/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
279

            
cleanup
yuki-kimoto authored on 2010-10-17
280
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
281
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
282
    
283
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
284
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
285
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
286
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
287
    }
288
    
289
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
290
    my $table            = $args{table} || '';
291
    my $where            = $args{where} || {};
cleanup
yuki-kimoto authored on 2010-10-17
292
    my $append = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
293
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
294
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
295

            
296
    my $auto_filter_table = exists $args{auto_filter_table}
297
                          ? $args{auto_filter_table}
298
                          : [$table];
299
    $auto_filter_table ||= [];    
300

            
packaging one directory
yuki-kimoto authored on 2009-11-16
301
    # Where keys
removed register_format()
yuki-kimoto authored on 2010-05-26
302
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
303
    
304
    # Not exists where keys
add tests
yuki-kimoto authored on 2010-08-10
305
    croak qq{"where" argument must be specified and } .
306
          qq{contains the pairs of column name and value}
cleanup
yuki-kimoto authored on 2010-10-17
307
      if !@where_keys && !$allow_delete_all;
packaging one directory
yuki-kimoto authored on 2009-11-16
308
    
309
    # Where clause
310
    my $where_clause = '';
311
    if (@where_keys) {
312
        $where_clause = 'where ';
add tests
yuki-kimoto authored on 2010-08-10
313
        $where_clause .= "{= $_} and " for @where_keys;
packaging one directory
yuki-kimoto authored on 2009-11-16
314
        $where_clause =~ s/ and $//;
315
    }
316
    
add tests
yuki-kimoto authored on 2010-08-10
317
    # Source of SQL
cleanup
yuki-kimoto authored on 2010-10-17
318
    my $source = "delete from $table $where_clause";
add tests
yuki-kimoto authored on 2010-08-10
319
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
320
    
321
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
322
    my $ret_val = $self->execute(
323
        $source, param  => $where, filter => $filter,
324
        auto_filter_table => $auto_filter_table);
packaging one directory
yuki-kimoto authored on 2009-11-16
325
    
326
    return $ret_val;
327
}
328

            
cleanup
yuki-kimoto authored on 2010-10-17
329
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
330

            
added helper method
yuki-kimoto authored on 2010-10-17
331
sub DESTROY { }
332

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
333
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter auto_filter_table/;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
334

            
cleanup
yuki-kimoto authored on 2010-10-17
335
sub execute{
336
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
337
    
338
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
339
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
340
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
341
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
342
    }
343
    
cleanup
yuki-kimoto authored on 2010-10-17
344
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
345
    
cleanup
yuki-kimoto authored on 2010-10-17
346
    # First argument is the soruce of SQL
347
    $query = $self->create_query($query)
348
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
349
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
350
    # Auto filter
351
    my $auto_filter = {};
352
    my $auto_filter_tables = $args{auto_filter_table} || [];
353
    foreach my $table (@$auto_filter_tables) {
354
        $auto_filter = {
355
            %$auto_filter,
cleanup
Yuki Kimoto authored on 2010-12-22
356
            %{$self->{auto_filter}{bind}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
357
        }
358
    }
359
    
360
    # Filter
cleanup
yuki-kimoto authored on 2010-10-17
361
    my $filter = $args{filter} || $query->filter || {};
cleanup
Yuki Kimoto authored on 2010-12-21
362
    foreach my $column (keys %$filter) {
363
        my $fname = $filter->{$column};
364
        unless (ref $fname eq 'CODE') {
365
          croak qq{"$fname" is not registered"}
366
            unless exists $self->filters->{$fname};
367
          
368
          $filter->{$column} = $self->filters->{$fname};
369
        }
370
    }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
371
    $filter = {%$auto_filter, %$filter};
packaging one directory
yuki-kimoto authored on 2009-11-16
372
    
cleanup
yuki-kimoto authored on 2010-10-17
373
    # Create bind value
374
    my $bind_values = $self->_build_bind_values($query, $params, $filter);
375
    
376
    # Execute
377
    my $sth      = $query->sth;
378
    my $affected;
379
    eval {$affected = $sth->execute(@$bind_values)};
380
    $self->_croak($@) if $@;
381
    
382
    # Return resultset if select statement is executed
383
    if ($sth->{NUM_OF_FIELDS}) {
384
        
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
385
        # Auto fetch filter
386
        my $auto_fetch_filter = {};
387
	    foreach my $table (@$auto_filter_tables) {
388
	        $auto_fetch_filter = {
389
	            %$auto_filter,
cleanup
Yuki Kimoto authored on 2010-12-22
390
	            %{$self->{auto_filter}{fetch}{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
391
	        }
392
	    }
393
	    
394
		# Result
395
		my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
396
            sth            => $sth,
397
            filters        => $self->filters,
398
            filter_check   => $self->filter_check,
399
            default_filter => $self->default_fetch_filter,
400
            _auto_filter   => $auto_fetch_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
401
        );
402

            
403
        return $result;
404
    }
405
    return $affected;
406
}
407

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
408
sub expand {
409
    my $self = shift;
410
    my $source = ref $_[0] eq 'HASH' ? $_[0] : {@_};
411
    my $table = (keys %$source)[0];
412
    my $param = $source->{$table};
413
    
414
    # Expand table name
415
    my $expand = {};
416
    foreach my $column (keys %$param) {
417
        $expand->{"$table.$column"} = $param->{$column};
418
    }
419
    
420
    return %$expand;
421
}
422

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
423
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append
424
                                            filter auto_filter_table/;
cleanup
yuki-kimoto authored on 2010-10-17
425
sub insert {
426
    my ($self, %args) = @_;
427

            
428
    # Check arguments
429
    foreach my $name (keys %args) {
430
        croak qq{"$name" is invalid argument}
431
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
432
    }
433
    
cleanup
yuki-kimoto authored on 2010-10-17
434
    # Arguments
435
    my $table  = $args{table} || '';
436
    my $param  = $args{param} || {};
437
    my $append = $args{append} || '';
438
    my $filter = $args{filter};
439
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
440
    my $auto_filter_table = exists $args{auto_filter_table}
441
                          ? $args{auto_filter_table}
442
                          : [$table];
443
    $auto_filter_table ||= [];
444
    
cleanup
yuki-kimoto authored on 2010-10-17
445
    # Insert keys
446
    my @insert_keys = keys %$param;
447
    
448
    # Templte for insert
449
    my $source = "insert into $table {insert_param "
450
               . join(' ', @insert_keys) . '}';
add tests
yuki-kimoto authored on 2010-08-10
451
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
452
    
453
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
454
    my $ret_val = $self->execute(
455
        $source,
456
        param  => $param,
457
        filter => $filter,
458
        auto_filter_table => $auto_filter_table
459
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
460
    
461
    return $ret_val;
462
}
463

            
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
464
sub iterate_all_columns {
465
    my ($self, $cb) = @_;
466
    
467
    # Iterate all tables
468
    my $sth_tables = $self->dbh->table_info;
469
    while (my $table_info = $sth_tables->fetchrow_hashref) {
470
        
471
        # Table
472
        my $table = $table_info->{TABLE_NAME};
473
        
474
        # Iterate all columns
475
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
476
        while (my $column_info = $sth_columns->fetchrow_hashref) {
477
            my $column = $column_info->{COLUMN_NAME};
478
            $cb->($table, $column, $column_info);
479
        }
480
    }
481
}
482

            
added dbi_options attribute
kimoto authored on 2010-12-20
483
sub new {
484
    my $self = shift->SUPER::new(@_);
485
    
486
    # Check attribute names
487
    my @attrs = keys %$self;
488
    foreach my $attr (@attrs) {
489
        croak qq{"$attr" is invalid attribute name}
490
          unless $self->can($attr);
491
    }
492
    
493
    return $self;
494
}
495

            
cleanup
yuki-kimoto authored on 2010-10-17
496
sub register_filter {
497
    my $invocant = shift;
498
    
499
    # Register filter
500
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
501
    $invocant->filters({%{$invocant->filters}, %$filters});
502
    
503
    return $invocant;
504
}
packaging one directory
yuki-kimoto authored on 2009-11-16
505

            
refactoring select
yuki-kimoto authored on 2010-04-28
506
our %VALID_SELECT_ARGS
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
507
  = map { $_ => 1 } qw/auto_filter_table table column where append relation filter param/;
refactoring select
yuki-kimoto authored on 2010-04-28
508

            
packaging one directory
yuki-kimoto authored on 2009-11-16
509
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
510
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
511
    
refactoring select
yuki-kimoto authored on 2010-04-28
512
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
513
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
514
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
515
          unless $VALID_SELECT_ARGS{$name};
516
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
517
    
refactoring select
yuki-kimoto authored on 2010-04-28
518
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
519
    my $tables = $args{table} || [];
removed register_format()
yuki-kimoto authored on 2010-05-26
520
    $tables = [$tables] unless ref $tables eq 'ARRAY';
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
521
    my $columns  = $args{column} || [];
update document
yuki-kimoto authored on 2010-08-07
522
    my $where    = $args{where};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
523
    my $relation = $args{relation};
524
    my $append   = $args{append};
525
    my $filter   = $args{filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
526

            
527
    my $auto_filter_table = exists $args{auto_filter_table}
528
                          ? $args{auto_filter_table}
529
                          : $tables;
packaging one directory
yuki-kimoto authored on 2009-11-16
530
    
add tests
yuki-kimoto authored on 2010-08-10
531
    # Source of SQL
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
532
    my $source = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
533
    
added commit method
yuki-kimoto authored on 2010-05-27
534
    # Column clause
packaging one directory
yuki-kimoto authored on 2009-11-16
535
    if (@$columns) {
536
        foreach my $column (@$columns) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
537
            $source .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
538
        }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
539
        $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
540
    }
541
    else {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
542
        $source .= '* ';
packaging one directory
yuki-kimoto authored on 2009-11-16
543
    }
544
    
added commit method
yuki-kimoto authored on 2010-05-27
545
    # Table
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
546
    $source .= 'from ';
packaging one directory
yuki-kimoto authored on 2009-11-16
547
    foreach my $table (@$tables) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
548
        $source .= "$table, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
549
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
550
    $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
551
    
added commit method
yuki-kimoto authored on 2010-05-27
552
    # Where clause
update document
yuki-kimoto authored on 2010-08-07
553
    my $param;
554
    if (ref $where eq 'HASH') {
555
        $param = $where;
556
        $source .= 'where (';
557
        foreach my $where_key (keys %$where) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
558
            $source .= "{= $where_key} and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
559
        }
update document
yuki-kimoto authored on 2010-08-07
560
        $source =~ s/ and $//;
561
        $source .= ') ';
562
    }
563
    elsif (ref $where eq 'ARRAY') {
564
        my$where_str = $where->[0] || '';
565
        $param = $where->[1];
566
        
567
        $source .= "where ($where_str) ";
packaging one directory
yuki-kimoto authored on 2009-11-16
568
    }
569
    
added commit method
yuki-kimoto authored on 2010-05-27
570
    # Relation
571
    if ($relation) {
update document
yuki-kimoto authored on 2010-08-07
572
        $source .= $where ? "and " : "where ";
added commit method
yuki-kimoto authored on 2010-05-27
573
        foreach my $rkey (keys %$relation) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
574
            $source .= "$rkey = " . $relation->{$rkey} . " and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
575
        }
576
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
577
    $source =~ s/ and $//;
added commit method
yuki-kimoto authored on 2010-05-27
578
    
579
    # Append some statement
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
580
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
581
    
582
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
583
    my $result = $self->execute(
584
        $source, param  => $param, filter => $filter,
585
        auto_filter_table => $auto_filter_table);    
packaging one directory
yuki-kimoto authored on 2009-11-16
586
    
587
    return $result;
588
}
589

            
cleanup
yuki-kimoto authored on 2010-10-17
590
our %VALID_UPDATE_ARGS
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
591
  = map { $_ => 1 } qw/auto_filter_table table param
592
                       where append filter allow_update_all/;
cleanup
yuki-kimoto authored on 2010-10-17
593

            
594
sub update {
595
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
596
    
cleanup
yuki-kimoto authored on 2010-10-17
597
    # Check arguments
598
    foreach my $name (keys %args) {
599
        croak qq{"$name" is invalid argument}
600
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
601
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
602
    
cleanup
yuki-kimoto authored on 2010-10-17
603
    # Arguments
604
    my $table            = $args{table} || '';
605
    my $param            = $args{param} || {};
606
    my $where            = $args{where} || {};
607
    my $append = $args{append} || '';
608
    my $filter           = $args{filter};
609
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
610
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
611
    my $auto_filter_table = exists $args{auto_filter_table}
612
                          ? $args{auto_filter_table}
613
                          : [$table];
614
    $auto_filter_table ||= [];
615
    
cleanup
yuki-kimoto authored on 2010-10-17
616
    # Update keys
617
    my @update_keys = keys %$param;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
618
    
cleanup
yuki-kimoto authored on 2010-10-17
619
    # Where keys
620
    my @where_keys = keys %$where;
removed reconnect method
yuki-kimoto authored on 2010-05-28
621
    
cleanup
yuki-kimoto authored on 2010-10-17
622
    # Not exists where keys
623
    croak qq{"where" argument must be specified and } .
624
          qq{contains the pairs of column name and value}
625
      if !@where_keys && !$allow_update_all;
removed experimental registe...
yuki-kimoto authored on 2010-08-24
626
    
cleanup
yuki-kimoto authored on 2010-10-17
627
    # Update clause
628
    my $update_clause = '{update_param ' . join(' ', @update_keys) . '}';
removed experimental registe...
yuki-kimoto authored on 2010-08-24
629
    
cleanup
yuki-kimoto authored on 2010-10-17
630
    # Where clause
631
    my $where_clause = '';
632
    my $new_where = {};
removed reconnect method
yuki-kimoto authored on 2010-05-28
633
    
cleanup
yuki-kimoto authored on 2010-10-17
634
    if (@where_keys) {
635
        $where_clause = 'where ';
636
        $where_clause .= "{= $_} and " for @where_keys;
637
        $where_clause =~ s/ and $//;
removed reconnect method
yuki-kimoto authored on 2010-05-28
638
    }
639
    
cleanup
yuki-kimoto authored on 2010-10-17
640
    # Source of SQL
641
    my $source = "update $table $update_clause $where_clause";
642
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
643
    
cleanup
yuki-kimoto authored on 2010-10-17
644
    # Rearrange parameters
645
    foreach my $wkey (@where_keys) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
646
        
cleanup
yuki-kimoto authored on 2010-10-17
647
        if (exists $param->{$wkey}) {
648
            $param->{$wkey} = [$param->{$wkey}]
649
              unless ref $param->{$wkey} eq 'ARRAY';
650
            
651
            push @{$param->{$wkey}}, $where->{$wkey};
652
        }
653
        else {
654
            $param->{$wkey} = $where->{$wkey};
655
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
656
    }
cleanup
yuki-kimoto authored on 2010-10-17
657
    
658
    # Execute query
659
    my $ret_val = $self->execute($source, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
660
                                 filter => $filter,
661
                                 auto_filter_table => $auto_filter_table);
cleanup
yuki-kimoto authored on 2010-10-17
662
    
663
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
664
}
665

            
cleanup
yuki-kimoto authored on 2010-10-17
666
sub update_all { shift->update(allow_update_all => 1, @_) };
667

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
668
sub _build_bind_values {
669
    my ($self, $query, $params, $filter) = @_;
670
    
671
    # binding values
672
    my @bind_values;
add tests
yuki-kimoto authored on 2010-08-08
673

            
674
    # Filter
675
    $filter ||= {};
676
    
677
    # Parameter
678
    $params ||= {};
679
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
680
    # Build bind values
681
    my $count = {};
682
    foreach my $column (@{$query->columns}) {
683
        
684
        # Value
685
        my $value = ref $params->{$column} eq 'ARRAY'
686
                  ? $params->{$column}->[$count->{$column} || 0]
687
                  : $params->{$column};
688
        
add tests
yuki-kimoto authored on 2010-08-10
689
        # Filtering
cleanup
Yuki Kimoto authored on 2010-12-22
690
        my $f = $filter->{$column} || $self->{default_bind_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
691
        
cleanup
Yuki Kimoto authored on 2010-12-21
692
        push @bind_values, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
693
        
694
        # Count up 
695
        $count->{$column}++;
696
    }
697
    
698
    return \@bind_values;
699
}
700

            
cleanup
yuki-kimoto authored on 2010-10-17
701
sub _croak {
702
    my ($self, $error, $append) = @_;
703
    $append ||= "";
704
    
705
    # Verbose
706
    if ($Carp::Verbose) { croak $error }
707
    
708
    # Not verbose
709
    else {
710
        
711
        # Remove line and module infromation
712
        my $at_pos = rindex($error, ' at ');
713
        $error = substr($error, 0, $at_pos);
714
        $error =~ s/\s+$//;
715
        
716
        croak "$error$append";
717
    }
718
}
719

            
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
720
1;
721

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
722
=head1 NAME
723

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
724
DBIx::Custom - DBI interface, having hash parameter binding and filtering system
removed reconnect method
yuki-kimoto authored on 2010-05-28
725

            
726
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
727

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
728
Connect to the database.
729
    
730
    use DBIx::Custom;
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
731
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
removed reconnect method
yuki-kimoto authored on 2010-05-28
732
                                    user => 'ken', password => '!LFKD%$&');
cleanup
yuki-kimoto authored on 2010-08-05
733

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
734
Insert, update, and delete
cleanup
yuki-kimoto authored on 2010-08-05
735

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
736
    # Insert 
737
    $dbi->insert(table  => 'books',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
738
                 param  => {title => 'Perl', author => 'Ken'},
removed reconnect method
yuki-kimoto authored on 2010-05-28
739
                 filter => {title => 'encode_utf8'});
740
    
741
    # Update 
742
    $dbi->update(table  => 'books', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
743
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
744
                 where  => {id => 5},
745
                 filter => {title => 'encode_utf8'});
746
    
747
    # Update all
748
    $dbi->update_all(table  => 'books',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
749
                     param  => {title => 'Perl'},
removed reconnect method
yuki-kimoto authored on 2010-05-28
750
                     filter => {title => 'encode_utf8'});
751
    
752
    # Delete
753
    $dbi->delete(table  => 'books',
754
                 where  => {author => 'Ken'},
755
                 filter => {title => 'encode_utf8'});
756
    
757
    # Delete all
758
    $dbi->delete_all(table => 'books');
cleanup
yuki-kimoto authored on 2010-08-05
759

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
760
Select
cleanup
yuki-kimoto authored on 2010-08-05
761

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
762
    # Select
763
    my $result = $dbi->select(table => 'books');
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
764
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
765
    # Select, more complex
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
766
    my $result = $dbi->select(
update document
yuki-kimoto authored on 2010-05-27
767
        table  => 'books',
768
        column => [qw/author title/],
769
        where  => {author => 'Ken'},
updated document
yuki-kimoto authored on 2010-08-08
770
        append => 'order by id limit 5',
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
771
        filter => {title => 'encode_utf8'}
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
772
    );
added commit method
yuki-kimoto authored on 2010-05-27
773
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
774
    # Select, join table
added commit method
yuki-kimoto authored on 2010-05-27
775
    my $result = $dbi->select(
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
776
        table    => ['books', 'rental'],
777
        column   => ['books.name as book_name']
added commit method
yuki-kimoto authored on 2010-05-27
778
        relation => {'books.id' => 'rental.book_id'}
779
    );
updated document
yuki-kimoto authored on 2010-08-08
780
    
781
    # Select, more flexible where
782
    my $result = $dbi->select(
783
        table  => 'books',
784
        where  => ['{= author} and {like title}', 
785
                   {author => 'Ken', title => '%Perl%'}]
786
    );
cleanup
yuki-kimoto authored on 2010-08-05
787

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
788
Execute SQL
cleanup
yuki-kimoto authored on 2010-08-05
789

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
790
    # Execute SQL
removed register_format()
yuki-kimoto authored on 2010-05-26
791
    $dbi->execute("select title from books");
792
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
793
    # Execute SQL with hash binding and filtering
updated document
yuki-kimoto authored on 2010-08-08
794
    $dbi->execute("select id from books where {= author} and {like title}",
removed register_format()
yuki-kimoto authored on 2010-05-26
795
                  param  => {author => 'ken', title => '%Perl%'},
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
796
                  filter => {title => 'encode_utf8'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
797

            
798
    # Create query and execute it
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
799
    my $query = $dbi->create_query(
updated document
yuki-kimoto authored on 2010-08-08
800
        "select id from books where {= author} and {like title}"
removed reconnect method
yuki-kimoto authored on 2010-05-28
801
    );
updated document
yuki-kimoto authored on 2010-08-08
802
    $dbi->execute($query, param => {author => 'Ken', title => '%Perl%'})
cleanup
yuki-kimoto authored on 2010-08-05
803

            
updated document
yuki-kimoto authored on 2010-08-08
804
Other features.
cleanup
yuki-kimoto authored on 2010-08-05
805

            
806
    # Get DBI object
807
    my $dbh = $dbi->dbh;
808

            
809
Fetch row.
810

            
removed register_format()
yuki-kimoto authored on 2010-05-26
811
    # Fetch
812
    while (my $row = $result->fetch) {
813
        # ...
814
    }
815
    
816
    # Fetch hash
817
    while (my $row = $result->fetch_hash) {
818
        
819
    }
820
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
821
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
822

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
823
L<DBIx::Custom> is one of L<DBI> interface modules,
824
such as L<DBIx::Class>, L<DBIx::Simple>.
removed reconnect method
yuki-kimoto authored on 2010-05-28
825

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
826
This module is not O/R mapper. O/R mapper is useful,
827
but you must learn many syntax of the O/R mapper,
updated document
yuki-kimoto authored on 2010-08-08
828
which is almost another language.
829
Created SQL statement is offten not effcient and damage SQL performance.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
830
so you have to execute raw SQL in the end.
removed reconnect method
yuki-kimoto authored on 2010-05-28
831

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
832
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper.
updated document
yuki-kimoto authored on 2010-08-08
833
L<DBIx::Custom> provide flexible hash parameter binding and filtering system,
added experimental expand me...
yuki-kimoto authored on 2010-10-20
834
and suger methods, such as C<insert()>, C<update()>, C<delete()>, C<select()>
updated document
yuki-kimoto authored on 2010-08-08
835
to execute SQL easily.
removed reconnect method
yuki-kimoto authored on 2010-05-28
836

            
updated document
yuki-kimoto authored on 2010-08-08
837
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful,
838
but de-facto standard,
839
so all people learing database know it.
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
840
If you already know SQL,
841
you learn a little thing to use L<DBIx::Custom>.
removed reconnect method
yuki-kimoto authored on 2010-05-28
842

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
843
See L<DBIx::Custom::Guides> for more details.
updated document
yuki-kimoto authored on 2010-08-08
844

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

            
cleanup
yuki-kimoto authored on 2010-10-17
847
=head2 C<cache>
packaging one directory
yuki-kimoto authored on 2009-11-16
848

            
cleanup
yuki-kimoto authored on 2010-10-17
849
    my $cache = $dbi->cache;
850
    $dbi      = $dbi->cache(1);
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
851

            
cleanup
yuki-kimoto authored on 2010-10-17
852
Enable parsed L<DBIx::Custom::Query> object caching.
853
Default to 1.
packaging one directory
yuki-kimoto authored on 2009-11-16
854

            
cleanup
yuki-kimoto authored on 2010-10-17
855
=head2 C<cache_method>
packaging one directory
yuki-kimoto authored on 2009-11-16
856

            
cleanup
yuki-kimoto authored on 2010-10-17
857
    $dbi          = $dbi->cache_method(\&cache_method);
858
    $cache_method = $dbi->cache_method
859

            
860
Method to set and get caches.
861

            
862
B<Example:>
863

            
864
    $dbi->cache_method(
865
        sub {
866
            my $self = shift;
867
            
868
            $self->{_cached} ||= {};
869
            
870
            if (@_ > 1) {
871
                $self->{_cached}{$_[0]} = $_[1] 
872
            }
873
            else {
874
                return $self->{_cached}{$_[0]}
875
            }
876
        }
877
    );
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
878

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

            
cleanup
yuki-kimoto authored on 2010-08-03
881
    my $data_source = $dbi->data_source;
cleanup
yuki-kimoto authored on 2010-08-05
882
    $dbi            = $dbi->data_source("DBI:mysql:database=dbname");
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
883

            
cleanup
yuki-kimoto authored on 2010-08-05
884
Data source.
885
C<connect()> method use this value to connect the database.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
886

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

            
cleanup
yuki-kimoto authored on 2010-08-03
889
    my $dbh = $dbi->dbh;
890
    $dbi    = $dbi->dbh($dbh);
packaging one directory
yuki-kimoto authored on 2009-11-16
891

            
cleanup
yuki-kimoto authored on 2010-08-05
892
L<DBI> object. You can call all methods of L<DBI>.
packaging one directory
yuki-kimoto authored on 2009-11-16
893

            
added dbi_options attribute
kimoto authored on 2010-12-20
894
=head2 C<dbi_options>
895

            
896
    my $dbi_options = $dbi->dbi_options;
897
    $dbi            = $dbi->dbi_options($dbi_options);
898

            
899
DBI options.
900
C<connect()> method use this value to connect the database.
901

            
cleanup
yuki-kimoto authored on 2010-08-05
902
Default filter when row is fetched.
packaging one directory
yuki-kimoto authored on 2009-11-16
903

            
cleanup
yuki-kimoto authored on 2010-10-17
904
=head2 C<filters>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
905

            
cleanup
yuki-kimoto authored on 2010-10-17
906
    my $filters = $dbi->filters;
907
    $dbi        = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
908

            
cleanup
yuki-kimoto authored on 2010-10-17
909
Filter functions.
910
"encode_utf8" and "decode_utf8" is registered by default.
911

            
912
=head2 C<filter_check>
913

            
914
    my $filter_check = $dbi->filter_check;
915
    $dbi             = $dbi->filter_check(0);
916

            
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
917
B<this attribute is now deprecated and has no mean
918
because check is always done>. 
cleanup
yuki-kimoto authored on 2010-10-17
919

            
920
=head2 C<password>
921

            
922
    my $password = $dbi->password;
923
    $dbi         = $dbi->password('lkj&le`@s');
924

            
925
Password.
926
C<connect()> method use this value to connect the database.
update document
yuki-kimoto authored on 2010-01-30
927

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
928
=head2 C<query_builder>
added commit method
yuki-kimoto authored on 2010-05-27
929

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
930
    my $sql_class = $dbi->query_builder;
931
    $dbi          = $dbi->query_builder(DBIx::Custom::QueryBuilder->new);
added commit method
yuki-kimoto authored on 2010-05-27
932

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
933
SQL builder. C<query_builder()> must be 
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
934
the instance of L<DBIx::Custom::QueryBuilder> subclass.
935
Default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
936

            
cleanup
yuki-kimoto authored on 2010-10-17
937
=head2 C<result_class>
cleanup
yuki-kimoto authored on 2010-08-05
938

            
cleanup
yuki-kimoto authored on 2010-10-17
939
    my $result_class = $dbi->result_class;
940
    $dbi             = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
941

            
cleanup
yuki-kimoto authored on 2010-10-17
942
Result class for select statement.
943
Default to L<DBIx::Custom::Result>.
cleanup
yuki-kimoto authored on 2010-08-05
944

            
cleanup
yuki-kimoto authored on 2010-10-17
945
=head2 C<user>
cleanup
yuki-kimoto authored on 2010-08-05
946

            
cleanup
yuki-kimoto authored on 2010-10-17
947
    my $user = $dbi->user;
948
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
949

            
cleanup
yuki-kimoto authored on 2010-10-17
950
User name.
951
C<connect()> method use this value to connect the database.
952
    
953
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
954

            
cleanup
yuki-kimoto authored on 2010-10-17
955
L<DBIx::Custom> inherits all methods from L<Object::Simple>
956
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
957

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
958
=head2 C<(experimental) auto_filter >
959

            
960
    $dbi->auto_filter(
961
        $table,
962
        [$column1, $bind_filter1, $fetch_filter1],
963
        [$column2, $bind_filter2, $fetch_filter2],
964
        [...],
965
    );
966

            
967
C<auto_filter> is automatically filter for columns of table.
968
This have effect C<insert>, C<update>, C<delete>. C<select>
cleanup
Yuki Kimoto authored on 2010-12-21
969
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method.
970

            
971
If you want to have effect <execute< method, use C<auto_filter_table>
972
arguments.
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
973

            
cleanup
Yuki Kimoto authored on 2010-12-21
974
    $result = $dbi->execute(
975
        "select * from table1 where {= key1} and {= key2};",
976
         param => {key1 => 1, key2 => 2},
977
         auto_filter_table => ['table1']
978
    );
979
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
980
B<Example:>
981

            
982
    $dbi->auto_filter('books', 'sale_date', 'to_date', 'date_to');
983

            
984
=head2 C<begin_work>
added check_filter attribute
yuki-kimoto authored on 2010-08-08
985

            
cleanup
yuki-kimoto authored on 2010-10-17
986
    $dbi->begin_work;
added check_filter attribute
yuki-kimoto authored on 2010-08-08
987

            
cleanup
yuki-kimoto authored on 2010-10-17
988
Start transaction.
989
This is same as L<DBI>'s C<begin_work>.
added commit method
yuki-kimoto authored on 2010-05-27
990

            
cleanup
yuki-kimoto authored on 2010-08-05
991
L<DBIx::Custom> inherits all methods from L<Object::Simple>
992
and implements the following new ones.
added commit method
yuki-kimoto authored on 2010-05-27
993

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
994
=head2 C<commit>
cleanup
yuki-kimoto authored on 2010-10-17
995

            
996
    $dbi->commit;
997

            
998
Commit transaction.
999
This is same as L<DBI>'s C<commit>.
1000

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1006
Create a new L<DBIx::Custom> object and connect to the database.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1007
L<DBIx::Custom> is a wrapper of L<DBI>.
cleanup
yuki-kimoto authored on 2010-08-09
1008
C<AutoCommit> and C<RaiseError> options are true, 
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1009
and C<PrintError> option is false by default. 
packaging one directory
yuki-kimoto authored on 2009-11-16
1010

            
cleanup
yuki-kimoto authored on 2010-10-17
1011
=head2 C<create_query>
1012
    
1013
    my $query = $dbi->create_query(
1014
        "select * from books where {= author} and {like title};"
1015
    );
update document
yuki-kimoto authored on 2009-11-19
1016

            
cleanup
yuki-kimoto authored on 2010-10-17
1017
Create the instance of L<DBIx::Custom::Query> from the source of SQL.
1018
If you want to get high performance,
1019
use C<create_query()> method and execute it by C<execute()> method
1020
instead of suger methods.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1021

            
cleanup
yuki-kimoto authored on 2010-10-17
1022
    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
version 0.0901
yuki-kimoto authored on 2009-12-17
1023

            
cleanup
Yuki Kimoto authored on 2010-12-21
1024
=head2 C<(deprecated) default_bind_filter>
1025

            
cleanup
Yuki Kimoto authored on 2010-12-22
1026
    my $default_bind_filter = $dbi->default_bind_filter;
1027
    $dbi                    = $dbi->default_bind_filter($fname);
cleanup
Yuki Kimoto authored on 2010-12-21
1028

            
1029
Default filter when parameter binding is executed.
1030

            
1031
=head2 C<(deprecated) default_fetch_filter>
1032

            
cleanup
Yuki Kimoto authored on 2010-12-22
1033
    my $default_fetch_filter = $dbi->default_fetch_filter;
cleanup
Yuki Kimoto authored on 2010-12-21
1034
    $dbi = $dbi->default_fetch_filter($fname);
1035

            
cleanup
yuki-kimoto authored on 2010-10-17
1036
=head2 C<execute>
packaging one directory
yuki-kimoto authored on 2009-11-16
1037

            
cleanup
yuki-kimoto authored on 2010-10-17
1038
    my $result = $dbi->execute($query,  param => $params, filter => \%filter);
1039
    my $result = $dbi->execute($source, param => $params, filter => \%filter);
update document
yuki-kimoto authored on 2009-11-19
1040

            
cleanup
yuki-kimoto authored on 2010-10-17
1041
Execute query or the source of SQL.
1042
Query is L<DBIx::Custom::Query> object.
1043
Return value is L<DBIx::Custom::Result> if select statement is executed,
1044
or the count of affected rows if insert, update, delete statement is executed.
version 0.0901
yuki-kimoto authored on 2009-12-17
1045

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1048
    my $result = $dbi->execute(
1049
        "select * from books where {= author} and {like title}", 
1050
        param => {author => 'Ken', title => '%Perl%'}
1051
    );
1052
    
1053
    while (my $row = $result->fetch) {
1054
        my $author = $row->[0];
1055
        my $title  = $row->[1];
1056
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1057

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1058
=head2 C<(experimental) expand>
1059

            
1060
    my %expand = $dbi->expand($source);
1061

            
1062
The following hash
1063

            
1064
    {books => {title => 'Perl', author => 'Ken'}}
1065

            
1066
is expanded to
1067

            
1068
    ('books.title' => 'Perl', 'books.author' => 'Ken')
1069

            
1070
This is used in C<select()>
1071

            
1072

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1076
    $dbi->delete(table  => $table,
1077
                 where  => \%where,
1078
                 append => $append,
1079
                 filter => \%filter);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1080

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1081
Execute delete statement.
1082
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments.
1083
C<table> is a table name.
1084
C<where> is where clause. this must be hash reference.
1085
C<append> is a string added at the end of the SQL statement.
1086
C<filter> is filters when parameter binding is executed.
cleanup
yuki-kimoto authored on 2010-08-09
1087
Return value of C<delete()> is the count of affected rows.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1088

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1089
B<Example:>
packaging one directory
yuki-kimoto authored on 2009-11-16
1090

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1098
    $dbi->delete_all(table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
1099

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1100
Execute delete statement to delete all rows.
1101
Arguments is same as C<delete> method,
1102
except that C<delete_all> don't have C<where> argument.
cleanup
yuki-kimoto authored on 2010-08-09
1103
Return value of C<delete_all()> is the count of affected rows.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1104

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

            
added helper method
yuki-kimoto authored on 2010-10-17
1109
=head2 C<(experimental) helper>
1110

            
1111
    $dbi->helper(
1112
        update_or_insert => sub {
1113
            my $self = shift;
1114
            # do something
1115
        },
1116
        find_or_create   => sub {
1117
            my $self = shift;
1118
            # do something
1119
        }
1120
    );
1121

            
1122
Register helper methods. These method is called from L<DBIx::Custom> object directory.
1123

            
1124
    $dbi->update_or_insert;
1125
    $dbi->find_or_create;
1126

            
cleanup
yuki-kimoto authored on 2010-10-17
1127
=head2 C<insert>
1128

            
1129
    $dbi->insert(table  => $table, 
1130
                 param  => \%param,
1131
                 append => $append,
1132
                 filter => \%filter);
1133

            
1134
Execute insert statement.
1135
C<insert> method have C<table>, C<param>, C<append>
1136
and C<filter> arguments.
1137
C<table> is a table name.
1138
C<param> is the pairs of column name value. this must be hash reference.
1139
C<append> is a string added at the end of the SQL statement.
1140
C<filter> is filters when parameter binding is executed.
1141
This is overwrites C<default_bind_filter>.
1142
Return value of C<insert()> is the count of affected rows.
1143

            
1144
B<Example:>
1145

            
1146
    $dbi->insert(table  => 'books', 
1147
                 param  => {title => 'Perl', author => 'Taro'},
1148
                 append => "some statement",
1149
                 filter => {title => 'encode_utf8'})
1150

            
added dbi_options attribute
kimoto authored on 2010-12-20
1151
=head2 C<new>
1152

            
1153
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
1154
                                    user => 'ken', password => '!LFKD%$&');
1155

            
1156
Create a new L<DBIx::Custom> object.
1157

            
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1158
=head2 C<(experimental) iterate_all_columns>
1159

            
1160
    $dbi->iterate_all_columns(
1161
        sub {
1162
            my ($table, $column, $column_info) = @_;
1163
            
1164
            # do something;
1165
        }
1166
    );
1167

            
1168
Iterate all columns of all tables. Argument is callback.
1169
You can do anything by callback.
1170

            
cleanup
yuki-kimoto authored on 2010-10-17
1171
=head2 C<register_filter>
1172

            
1173
    $dbi->register_filter(%filters);
1174
    $dbi->register_filter(\%filters);
1175
    
1176
Register filter. Registered filters is available in the following attributes
1177
or arguments.
1178

            
1179
=over 4
1180

            
1181
=item *
1182

            
1183
C<filter> argument of C<insert()>, C<update()>,
1184
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1185
methods
1186

            
1187
=item *
1188

            
1189
C<execute()> method
1190

            
1191
=item *
1192

            
1193
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1194

            
1195
=item *
1196

            
1197
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1198

            
1199
=back
1200

            
1201
B<Example:>
1202

            
1203
    $dbi->register_filter(
1204
        encode_utf8 => sub {
1205
            my $value = shift;
1206
            
1207
            require Encode;
1208
            
1209
            return Encode::encode('UTF-8', $value);
1210
        },
1211
        decode_utf8 => sub {
1212
            my $value = shift;
1213
            
1214
            require Encode;
1215
            
1216
            return Encode::decode('UTF-8', $value)
1217
        }
1218
    );
1219

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1220
=head2 C<rollback>
cleanup
yuki-kimoto authored on 2010-10-17
1221

            
1222
    $dbi->rollback;
1223

            
1224
Rollback transaction.
1225
This is same as L<DBI>'s C<rollback>.
1226

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1227
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1228
    
cleanup
yuki-kimoto authored on 2010-08-05
1229
    my $result = $dbi->select(table    => $table,
1230
                              column   => [@column],
1231
                              where    => \%where,
1232
                              append   => $append,
1233
                              relation => \%relation,
1234
                              filter   => \%filter);
update document
yuki-kimoto authored on 2009-11-19
1235

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1236
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1237
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1238
C<relation> and C<filter> arguments.
1239
C<table> is a table name.
cleanup
yuki-kimoto authored on 2010-08-09
1240
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1241
C<append> is a string added at the end of the SQL statement.
1242
C<filter> is filters when parameter binding is executed.
update document
yuki-kimoto authored on 2009-11-19
1243

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

            
added commit method
yuki-kimoto authored on 2010-05-27
1246
    # select * from books;
cleanup
yuki-kimoto authored on 2010-08-05
1247
    my $result = $dbi->select(table => 'books');
packaging one directory
yuki-kimoto authored on 2009-11-16
1248
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1249
    # select * from books where title = ?;
1250
    my $result = $dbi->select(table => 'books', where => {title => 'Perl'});
update document
yuki-kimoto authored on 2009-11-19
1251
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1252
    # select title, author from books where id = ? for update;
cleanup
yuki-kimoto authored on 2010-08-05
1253
    my $result = $dbi->select(
removed register_format()
yuki-kimoto authored on 2010-05-26
1254
        table  => 'books',
removed reconnect method
yuki-kimoto authored on 2010-05-28
1255
        column => ['title', 'author'],
removed register_format()
yuki-kimoto authored on 2010-05-26
1256
        where  => {id => 1},
1257
        appned => 'for update'
update document
yuki-kimoto authored on 2009-11-19
1258
    );
1259
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1260
    # select books.name as book_name from books, rental
added commit method
yuki-kimoto authored on 2010-05-27
1261
    # where books.id = rental.book_id;
1262
    my $result = $dbi->select(
removed reconnect method
yuki-kimoto authored on 2010-05-28
1263
        table    => ['books', 'rental'],
1264
        column   => ['books.name as book_name']
added commit method
yuki-kimoto authored on 2010-05-27
1265
        relation => {'books.id' => 'rental.book_id'}
update document
yuki-kimoto authored on 2009-11-19
1266
    );
1267

            
cleanup
yuki-kimoto authored on 2010-08-09
1268
If you use more complex condition,
1269
you can specify a array reference to C<where> argument.
1270

            
1271
    my $result = $dbi->select(
1272
        table  => 'books',
1273
        column => ['title', 'author'],
1274
        where  => ['{= title} or {like author}',
1275
                   {title => '%Perl%', author => 'Ken'}]
1276
    );
1277

            
1278
First element is a string. it contains tags,
1279
such as "{= title} or {like author}".
1280
Second element is paramters.
1281

            
cleanup
yuki-kimoto authored on 2010-10-17
1282
=head2 C<update>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1283

            
cleanup
yuki-kimoto authored on 2010-10-17
1284
    $dbi->update(table  => $table, 
1285
                 param  => \%params,
1286
                 where  => \%where,
1287
                 append => $append,
1288
                 filter => \%filter)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1289

            
cleanup
yuki-kimoto authored on 2010-10-17
1290
Execute update statement.
1291
C<update> method have C<table>, C<param>, C<where>, C<append>
1292
and C<filter> arguments.
1293
C<table> is a table name.
1294
C<param> is column-value pairs. this must be hash reference.
1295
C<where> is where clause. this must be hash reference.
1296
C<append> is a string added at the end of the SQL statement.
1297
C<filter> is filters when parameter binding is executed.
1298
This is overwrites C<default_bind_filter>.
1299
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1300

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1303
    $dbi->update(table  => 'books',
1304
                 param  => {title => 'Perl', author => 'Taro'},
1305
                 where  => {id => 5},
1306
                 append => "some statement",
1307
                 filter => {title => 'encode_utf8'});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1308

            
cleanup
yuki-kimoto authored on 2010-10-17
1309
=head2 C<update_all>
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1310

            
cleanup
yuki-kimoto authored on 2010-10-17
1311
    $dbi->update_all(table  => $table, 
1312
                     param  => \%params,
1313
                     filter => \%filter,
1314
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1315

            
cleanup
yuki-kimoto authored on 2010-10-17
1316
Execute update statement to update all rows.
1317
Arguments is same as C<update> method,
1318
except that C<update_all> don't have C<where> argument.
1319
Return value of C<update_all()> is the count of affected rows.
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1320

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1323
    $dbi->update_all(table  => 'books', 
1324
                     param  => {author => 'taro'},
1325
                     filter => {author => 'encode_utf8'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1326

            
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
1327
=head1 STABILITY
1328

            
1329
L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature.
1330

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1333
Please tell me bugs if found.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1334

            
1335
C<< <kimoto.yuki at gmail.com> >>
1336

            
1337
L<http://github.com/yuki-kimoto/DBIx-Custom>
1338

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1339
=head1 AUTHOR
1340

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

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

            
1345
Copyright 2009 Yuki Kimoto, all rights reserved.
1346

            
1347
This program is free software; you can redistribute it and/or modify it
1348
under the same terms as Perl itself.
1349

            
1350
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1351

            
1352