Newer Older
656 lines | 14.241kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::Result;
updatedd pod
Yuki Kimoto authored on 2011-06-12
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2010-02-11
3

            
packaging one directory
yuki-kimoto authored on 2009-11-16
4
use Carp 'croak';
cleanup
Yuki Kimoto authored on 2011-04-25
5
use DBIx::Custom::Util qw/_array_to_hash _subname/;
packaging one directory
yuki-kimoto authored on 2009-11-16
6

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
7
has [qw/dbi sth/],
cleanup
Yuki Kimoto authored on 2012-01-20
8
  stash => sub { {} };
cleanup
Yuki Kimoto authored on 2010-12-21
9

            
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
10
*all = \&fetch_hash_all;
11

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
12
sub column {
cleanup
Yuki Kimoto authored on 2012-01-20
13
  my $self = shift;
14
  
15
  my $column = [];
16
  my $rows = $self->fetch_all;
17
  push @$column, $_->[0] for @$rows;
18
  return $column;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
19
}
20

            
cleanup
Yuki Kimoto authored on 2010-12-21
21
sub filter {
cleanup
Yuki Kimoto authored on 2012-01-20
22
  my $self = shift;
23
  
24
  # Set
25
  if (@_) {
26
    
27
    # Convert filter name to subroutine
28
    my $filter = @_ == 1 ? $_[0] : [@_];
29
    $filter = _array_to_hash($filter);
30
    for my $column (keys %$filter) {
31
      my $fname = $filter->{$column};
32
      if  (exists $filter->{$column}
33
        && defined $fname
34
        && ref $fname ne 'CODE') 
35
      {
36
        croak qq{Filter "$fname" is not registered" } . _subname
37
          unless exists $self->dbi->filters->{$fname};
38
        $filter->{$column} = $self->dbi->filters->{$fname};
39
      }
cleanup
Yuki Kimoto authored on 2010-12-21
40
    }
41
    
cleanup
Yuki Kimoto authored on 2012-01-20
42
    # Merge
43
    $self->{filter} = {%{$self->filter}, %$filter};
44
    
45
    return $self;
46
  }
47
  
48
  return $self->{filter} ||= {};
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
49
}
50

            
micro optimization
Yuki Kimoto authored on 2011-11-07
51
sub fetch {
cleanup
Yuki Kimoto authored on 2012-01-20
52
  my $self = shift;
53
  
54
  # Info
55
  $self->_cache unless $self->{_cache};
56
  
57
  # Fetch
58
  my @row = $self->{sth}->fetchrow_array;
59
  return unless @row;
60
  
61
  # Type rule
62
  if ($self->{type_rule}->{from1} && !$self->{type_rule_off} && !$self->{type_rule1_off}) {
63
    my $from = $self->{type_rule}->{from1};
64
    for my $type (keys %$from) {
65
      for my $column (@{$self->{_type_map}->{$type}}) {
66
        $row[$_] = $from->{$type}->($row[$_])
67
          for @{$self->{_pos}{$column} || []};
68
      }
micro optimization
Yuki Kimoto authored on 2011-11-07
69
    }
cleanup
Yuki Kimoto authored on 2012-01-20
70
  }
71
  if ($self->{type_rule}->{from2} && !$self->{type_rule_off} && !$self->{type_rule2_off}) {
72
    my $from = $self->{type_rule}->{from2};
73
    for my $type (keys %$from) {
74
      for my $column (@{$self->{_type_map}->{$type}}) {
75
        $row[$_] = $from->{$type}->($row[$_])
76
          for @{$self->{_pos}{$column} || []};
77
      }
micro optimization
Yuki Kimoto authored on 2011-11-07
78
    }
cleanup
Yuki Kimoto authored on 2012-01-20
79
  }
80
  
81
  # Filter
82
  if (($self->{filter} || $self->{default_filter}) && !$self->{filter_off}) {
83
     my @columns = $self->{default_filter} ? keys %{$self->{_columns}}
84
       : keys %{$self->{filter}};
85
     
86
     for my $column (@columns) {
87
       my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column}
88
         : $self->{default_filter};
89
       next unless $filter;
90
       $row[$_] = $filter->($row[$_])
91
         for @{$self->{_pos}{$column} || []};
92
     }
93
  }
94
  if ($self->{end_filter} && !$self->{filter_off}) {
95
     for my $column (keys %{$self->{end_filter}}) {
96
       next unless $self->{end_filter}->{$column};
97
       $row[$_] = $self->{end_filter}->{$column}->($row[$_])
98
         for @{$self->{_pos}{$column} || []};
99
     }
100
  }
101

            
102
  return \@row;
micro optimization
Yuki Kimoto authored on 2011-11-07
103
}
104

            
105
sub fetch_hash {
cleanup
Yuki Kimoto authored on 2012-01-20
106
  my $self = shift;
107
  
108
  # Info
109
  $self->_cache unless $self->{_cache};
110
  
111
  # Fetch
112
  return unless my $row = $self->{sth}->fetchrow_hashref;
113
  
114
  # Type rule
115
  if ($self->{type_rule}->{from1} &&
116
    !$self->{type_rule_off} && !$self->{type_rule1_off})
117
  {
118
    my $from = $self->{type_rule}->{from1};
119
    for my $type (keys %$from) {
120
      $from->{$type} and $row->{$_} = $from->{$type}->($row->{$_})
121
        for @{$self->{_type_map}->{$type}};
micro optimization
Yuki Kimoto authored on 2011-11-07
122
    }
cleanup
Yuki Kimoto authored on 2012-01-20
123
  }
124
  if ($self->{type_rule}->{from2} &&
125
    !$self->{type_rule_off} && !$self->{type_rule2_off})
126
  {
127
    my $from = $self->{type_rule}->{from2};
128
    for my $type (keys %{$self->{type_rule}->{from2}}) {
129
      $from->{$type} and $row->{$_} = $from->{$type}->($row->{$_})
130
        for @{$self->{_type_map}->{$type}};
micro optimization
Yuki Kimoto authored on 2011-11-07
131
    }
cleanup
Yuki Kimoto authored on 2012-01-20
132
  }        
133
  # Filter
134
  if (($self->{filter} || $self->{default_filter}) &&
135
    !$self->{filter_off})
136
  {
137
     my @columns = $self->{default_filter} ? keys %{$self->{_columns}}
138
       : keys %{$self->{filter}};
139
     
140
     for my $column (@columns) {
141
       next unless exists $row->{$column};
142
       my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column}
143
         : $self->{default_filter};
144
       $row->{$column} = $filter->($row->{$column}) if $filter;
145
     }
146
  }
147
  if ($self->{end_filter} && !$self->{filter_off}) {
148
     exists $self->{_columns}{$_} && $self->{end_filter}->{$_} and
149
         $row->{$_} = $self->{end_filter}->{$_}->($row->{$_})
150
       for keys %{$self->{end_filter}};
151
  }
152
  $row;
micro optimization
Yuki Kimoto authored on 2011-11-07
153
}
154

            
cleanup
yuki-kimoto authored on 2010-10-17
155
sub fetch_all {
cleanup
Yuki Kimoto authored on 2012-01-20
156
  my $self = shift;
157
  
158
  # Fetch all rows
159
  my $rows = [];
160
  while(my $row = $self->fetch) { push @$rows, $row}
161
  
162
  return $rows;
cleanup
yuki-kimoto authored on 2010-10-17
163
}
164

            
165
sub fetch_hash_all {
cleanup
Yuki Kimoto authored on 2012-01-20
166
  my $self = shift;
167
  
168
  # Fetch all rows as hash
169
  my $rows = [];
170
  while(my $row = $self->fetch_hash) { push @$rows, $row }
171
  
172
  return $rows;
cleanup
yuki-kimoto authored on 2010-10-17
173
}
174

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
175
sub fetch_hash_one {
cleanup
Yuki Kimoto authored on 2012-01-20
176
  my $self = shift;
177
  
178
  # Fetch hash
179
  my $row = $self->fetch_hash;
180
  return unless $row;
181
  
182
  # Finish statement handle
183
  $self->sth->finish;
184
  
185
  return $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
186
}
187

            
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
188
sub fetch_hash_multi {
cleanup
Yuki Kimoto authored on 2012-01-20
189
  my ($self, $count) = @_;
190
  
191
  # Fetch multiple rows
192
  croak 'Row count must be specified ' . _subname
193
    unless $count;
194
  
195
  return if $self->{_finished};
196

            
197
  my $rows = [];
198
  for (my $i = 0; $i < $count; $i++) {
199
    my $row = $self->fetch_hash;
200
    unless ($row) {
201
      $self->{_finished} = 1;
202
      last;
packaging one directory
yuki-kimoto authored on 2009-11-16
203
    }
cleanup
Yuki Kimoto authored on 2012-01-20
204
    push @$rows, $row;
205
  }
206
  
207
  return unless @$rows;
208
  return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
209
}
210

            
cleanup
yuki-kimoto authored on 2010-10-17
211
sub fetch_multi {
cleanup
Yuki Kimoto authored on 2012-01-20
212
  my ($self, $count) = @_;
213
  
214
  # Row count not specifed
215
  croak 'Row count must be specified ' . _subname
216
    unless $count;
217
  
218
  return if $self->{_finished};
219
  
220
  # Fetch multi rows
221
  my $rows = [];
222
  for (my $i = 0; $i < $count; $i++) {
223
    my $row = $self->fetch;
224
    unless ($row) {
225
      $self->{_finished} = 1;
226
      last;
packaging one directory
yuki-kimoto authored on 2009-11-16
227
    }
cleanup
Yuki Kimoto authored on 2012-01-20
228
    push @$rows, $row;
229
  }
230
  
231
  return unless @$rows;
232
  return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
233
}
234

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
235

            
236
sub fetch_one {
cleanup
Yuki Kimoto authored on 2012-01-20
237
  my $self = shift;
238
  
239
  # Fetch
240
  my $row = $self->fetch;
241
  return unless $row;
242
  
243
  # Finish statement handle
244
  $self->sth->finish;
245
  
246
  return $row;
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
247
}
248

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
249
sub header { shift->sth->{NAME} }
250

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
251
*one = \&fetch_hash_one;
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
252

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
253
sub type_rule {
cleanup
Yuki Kimoto authored on 2012-01-20
254
  my $self = shift;
255
  
256
  if (@_) {
257
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
258

            
259
    # From
260
    for my $i (1 .. 2) {
261
      $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
262
      for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
263
        croak qq{data type of from$i section must be lower case or number}
264
          if $data_type =~ /[A-Z]/;
265
        my $fname = $type_rule->{"from$i"}{$data_type};
266
        if (defined $fname && ref $fname ne 'CODE') {
267
          croak qq{Filter "$fname" is not registered" } . _subname
268
            unless exists $self->dbi->filters->{$fname};
269
          
270
          $type_rule->{"from$i"}{$data_type} = $self->dbi->filters->{$fname};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
271
        }
cleanup
Yuki Kimoto authored on 2012-01-20
272
      }
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
273
    }
cleanup
Yuki Kimoto authored on 2012-01-20
274
    $self->{type_rule} = $type_rule;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
275
    
cleanup
Yuki Kimoto authored on 2012-01-20
276
    return $self;
277
  }
278
  
279
  return $self->{type_rule} || {};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
280
}
281

            
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
282
sub type_rule_off {
cleanup
Yuki Kimoto authored on 2012-01-20
283
  my $self = shift;
284
  $self->{type_rule_off} = 1;
285
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
286
}
287

            
288
sub type_rule_on {
cleanup
Yuki Kimoto authored on 2012-01-20
289
  my $self = shift;
290
  $self->{type_rule_off} = 0;
291
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
292
}
293

            
294
sub type_rule1_off {
cleanup
Yuki Kimoto authored on 2012-01-20
295
  my $self = shift;
296
  $self->{type_rule1_off} = 1;
297
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
298
}
299

            
300
sub type_rule1_on {
cleanup
Yuki Kimoto authored on 2012-01-20
301
  my $self = shift;
302
  $self->{type_rule1_off} = 0;
303
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
304
}
305

            
306
sub type_rule2_off {
cleanup
Yuki Kimoto authored on 2012-01-20
307
  my $self = shift;
308
  $self->{type_rule2_off} = 1;
309
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
310
}
311

            
312
sub type_rule2_on {
cleanup
Yuki Kimoto authored on 2012-01-20
313
  my $self = shift;
314
  $self->{type_rule2_off} = 0;
315
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
316
}
317

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
318
sub value {
cleanup
Yuki Kimoto authored on 2012-01-20
319
  my $self = shift;
320
  my $row = $self->fetch_one;
321
  my $value = $row ? $row->[0] : undef;
322
  return $value;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
323
}
324

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
325
sub _cache {
cleanup
Yuki Kimoto authored on 2012-01-20
326
  my $self = shift;
327
  $self->{_type_map} = {};
328
  $self->{_pos} = {};
329
  $self->{_columns} = {};
330
  for (my $i = 0; $i < @{$self->{sth}->{NAME}}; $i++) {
331
    my $type = lc $self->{sth}{TYPE}[$i];
332
    my $name = $self->{sth}{NAME}[$i];
333
    $self->{_type_map}{$type} ||= [];
334
    push @{$self->{_type_map}{$type}}, $name;
335
    $self->{_pos}{$name} ||= [];
336
    push @{$self->{_pos}{$name}}, $i;
337
    $self->{_columns}{$name} = 1;
338
  }
339
  $self->{_cache} = 1;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
340
}
341

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
342
# DEPRECATED!
343
sub fetch_hash_first {
cleanup
Yuki Kimoto authored on 2012-01-20
344
  my $self = shift;
345
  warn "DBIx::Custom::Result::fetch_hash_first is DEPRECATED! use fetch_hash_one instead";
346
  return $self->fetch_hash_one(@_);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
347
}
348

            
349
# DEPRECATED!
350
sub fetch_first {
cleanup
Yuki Kimoto authored on 2012-01-20
351
  my $self = shift;
352
  warn "DBIx::Custom::Result::fetch_first is DEPRECATED! use fetch_one instead";
353
  return $self->fetch_one(@_);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
354
}
355

            
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
356
# DEPRECATED!
357
sub filter_off {
cleanup
Yuki Kimoto authored on 2012-01-20
358
  warn "filter_off method is DEPRECATED!";
359
  my $self = shift;
360
  $self->{filter_off} = 1;
361
  return $self;
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
362
}
363

            
364
# DEPRECATED!
365
sub filter_on {
cleanup
Yuki Kimoto authored on 2012-01-20
366
  warn "filter_on method is DEPRECATED!";
367
  my $self = shift;
368
  $self->{filter_off} = 0;
369
  return $self;
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
370
}
371

            
cleanup
Yuki Kimoto authored on 2011-06-13
372
# DEPRECATED!
373
sub end_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
374
  warn "end_filter method is DEPRECATED!";
375
  my $self = shift;
376
  if (@_) {
377
    my $end_filter = {};
378
    if (ref $_[0] eq 'HASH') { $end_filter = $_[0] }
379
    else { 
380
      $end_filter = _array_to_hash(
381
          @_ > 1 ? [@_] : $_[0]
382
      );
383
    }
384
    for my $column (keys %$end_filter) {
385
      my $fname = $end_filter->{$column};
386
      if (exists $end_filter->{$column}
387
        && defined $fname
388
        && ref $fname ne 'CODE') 
389
      {
390
        croak qq{Filter "$fname" is not registered" } . _subname
391
          unless exists $self->dbi->filters->{$fname};
392
        $end_filter->{$column} = $self->dbi->filters->{$fname};
393
      }
cleanup
Yuki Kimoto authored on 2011-06-13
394
    }
cleanup
Yuki Kimoto authored on 2012-01-20
395
    $self->{end_filter} = {%{$self->end_filter}, %$end_filter};
396
    return $self;
397
  }
398
  return $self->{end_filter} ||= {};
cleanup
Yuki Kimoto authored on 2011-06-13
399
}
cleanup
Yuki Kimoto authored on 2011-06-13
400
# DEPRECATED!
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
401
sub remove_end_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
402
  warn "remove_end_filter is DEPRECATED!";
403
  my $self = shift;
404
  $self->{end_filter} = {};
405
  return $self;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
406
}
cleanup
Yuki Kimoto authored on 2011-06-13
407
# DEPRECATED!
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
408
sub remove_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
409
  warn "remove_filter is DEPRECATED!";
410
  my $self = shift;
411
  $self->{filter} = {};
412
  return $self;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
413
}
cleanup
Yuki Kimoto authored on 2011-06-13
414
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
415
sub default_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
416
  warn "default_filter is DEPRECATED!";
417
  my $self = shift;
418
  if (@_) {
419
    my $fname = $_[0];
420
    if (@_ && !$fname) {
421
      $self->{default_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
422
    }
cleanup
Yuki Kimoto authored on 2012-01-20
423
    else {
424
      croak qq{Filter "$fname" is not registered}
425
        unless exists $self->dbi->filters->{$fname};
426
      $self->{default_filter} = $self->dbi->filters->{$fname};
427
    }
428
    return $self;
429
  }
430
  return $self->{default_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
431
}
cleanup
Yuki Kimoto authored on 2011-01-23
432
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
433
has 'filter_check'; 
cleanup
Yuki Kimoto authored on 2011-01-23
434

            
update document
yuki-kimoto authored on 2010-01-30
435
1;
436

            
packaging one directory
yuki-kimoto authored on 2009-11-16
437
=head1 NAME
438

            
cleanup
yuki-kimoto authored on 2010-08-05
439
DBIx::Custom::Result - Result of select statement
packaging one directory
yuki-kimoto authored on 2009-11-16
440

            
update document
yuki-kimoto authored on 2010-01-30
441
=head1 SYNOPSIS
cleanup
yuki-kimoto authored on 2010-08-05
442

            
cleanup
Yuki Kimoto authored on 2012-01-20
443
  # Result
444
  my $result = $dbi->select(table => 'book');
445

            
446
  # Fetch a row and put it into array reference
447
  while (my $row = $result->fetch) {
448
    my $author = $row->[0];
449
    my $title  = $row->[1];
450
  }
451
  
452
  # Fetch only a first row and put it into array reference
453
  my $row = $result->fetch_one;
454
  
455
  # Fetch all rows and put them into array of array reference
456
  my $rows = $result->fetch_all;
457

            
458
  # Fetch a row and put it into hash reference
459
  while (my $row = $result->fetch_hash) {
460
    my $title  = $row->{title};
461
    my $author = $row->{author};
462
  }
463
  
464
  # Fetch only a first row and put it into hash reference
465
  my $row = $result->fetch_hash_one;
466
  my $row = $result->one; # Alias for "fetch_hash_one"
467
  
468
  # Fetch all rows and put them into array of hash reference
469
  my $rows = $result->fetch_hash_all;
470
  my $rows = $result->all; # Alias for "fetch_hash_all"
packaging one directory
yuki-kimoto authored on 2009-11-16
471

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

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
474
=head2 C<dbi>
cleanup
yuki-kimoto authored on 2010-10-17
475

            
cleanup
Yuki Kimoto authored on 2012-01-20
476
  my $dbi = $result->dbi;
477
  $result = $result->dbi($dbi);
cleanup
yuki-kimoto authored on 2010-10-17
478

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
479
L<DBIx::Custom> object.
cleanup
yuki-kimoto authored on 2010-10-17
480

            
481
=head2 C<sth>
482

            
cleanup
Yuki Kimoto authored on 2012-01-20
483
  my $sth = $reuslt->sth
484
  $result = $result->sth($sth);
cleanup
yuki-kimoto authored on 2010-10-17
485

            
486
Statement handle of L<DBI>.
487

            
update document
yuki-kimoto authored on 2010-01-30
488
=head1 METHODS
489

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
490
L<DBIx::Custom::Result> inherits all methods from L<Object::Simple>
cleanup
yuki-kimoto authored on 2010-08-05
491
and implements the following new ones.
packaging one directory
yuki-kimoto authored on 2009-11-16
492

            
updated pod
Yuki Kimoto authored on 2011-06-07
493
=head2 C<all>
494

            
cleanup
Yuki Kimoto authored on 2012-01-20
495
  my $rows = $result->all;
updated pod
Yuki Kimoto authored on 2011-06-07
496

            
cleanup
Yuki Kimoto authored on 2011-06-15
497
Same as C<fetch_hash_all>.
updated pod
Yuki Kimoto authored on 2011-06-07
498

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
499
=head2 C<column> EXPERIMENTAL
500

            
cleanup
Yuki Kimoto authored on 2012-01-20
501
  my $column = $result->column;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
502

            
503
Get first column's all values.
504

            
cleanup
Yuki Kimoto authored on 2012-01-20
505
  my $names = $dbi->select('name', table => 'book')->column;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
506

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
509
  my $row = $result->fetch;
version 0.0901
yuki-kimoto authored on 2009-12-17
510

            
cleanup
Yuki Kimoto authored on 2011-06-15
511
Fetch a row and put it into array reference.
packaging one directory
yuki-kimoto authored on 2009-11-16
512

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
515
  my $rows = $result->fetch_all;
version 0.0901
yuki-kimoto authored on 2009-12-17
516

            
cleanup
Yuki Kimoto authored on 2011-06-15
517
Fetch all rows and put them into array of array reference.
packaging one directory
yuki-kimoto authored on 2009-11-16
518

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
519
=head2 C<fetch_one>
cleanup
yuki-kimoto authored on 2010-10-17
520

            
cleanup
Yuki Kimoto authored on 2012-01-20
521
  my $row = $result->fetch_one;
cleanup
yuki-kimoto authored on 2010-10-17
522

            
cleanup
Yuki Kimoto authored on 2011-06-15
523
Fetch only a first row and put it into array reference,
524
and finish statment handle.
cleanup
yuki-kimoto authored on 2010-10-17
525

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
526
=head2 C<fetch_hash>
packaging one directory
yuki-kimoto authored on 2009-11-16
527

            
cleanup
Yuki Kimoto authored on 2012-01-20
528
  my $row = $result->fetch_hash;
packaging one directory
yuki-kimoto authored on 2009-11-16
529

            
cleanup
Yuki Kimoto authored on 2011-06-15
530
Fetch a row and put it into hash reference.
update document
yuki-kimoto authored on 2009-11-19
531

            
cleanup
yuki-kimoto authored on 2010-10-17
532
=head2 C<fetch_hash_all>
533

            
cleanup
Yuki Kimoto authored on 2012-01-20
534
  my $rows = $result->fetch_hash_all;
cleanup
yuki-kimoto authored on 2010-10-17
535

            
cleanup
Yuki Kimoto authored on 2011-06-15
536
Fetch all rows and put them into array of hash reference.
cleanup
yuki-kimoto authored on 2010-10-17
537

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
538
=head2 C<fetch_hash_one>
cleanup
Yuki Kimoto authored on 2012-01-20
539
  
540
  my $row = $result->fetch_hash_one;
packaging one directory
yuki-kimoto authored on 2009-11-16
541

            
cleanup
Yuki Kimoto authored on 2011-06-15
542
Fetch only a first row and put it into hash reference,
543
and finish statment handle.
packaging one directory
yuki-kimoto authored on 2009-11-16
544

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
545
=head2 C<fetch_hash_multi>
update document
yuki-kimoto authored on 2009-11-19
546

            
cleanup
Yuki Kimoto authored on 2012-01-20
547
  my $rows = $result->fetch_hash_multi(5);
548
  
cleanup
Yuki Kimoto authored on 2011-06-15
549
Fetch multiple rows and put them into array of hash reference.
update document
yuki-kimoto authored on 2009-11-19
550

            
cleanup
yuki-kimoto authored on 2010-10-17
551
=head2 C<fetch_multi>
packaging one directory
yuki-kimoto authored on 2009-11-16
552

            
cleanup
Yuki Kimoto authored on 2012-01-20
553
  my $rows = $result->fetch_multi(5);
554
  
cleanup
Yuki Kimoto authored on 2011-06-15
555
Fetch multiple rows and put them into array of array reference.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
556

            
cleanup
Yuki Kimoto authored on 2010-12-21
557
=head2 C<filter>
558

            
cleanup
Yuki Kimoto authored on 2012-01-20
559
  $result->filter(title  => sub { uc $_[0] }, author => 'to_upper');
560
  $result->filter([qw/title author/] => 'to_upper');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
561

            
cleanup
Yuki Kimoto authored on 2011-06-15
562
Set filter for column.
563
You can use subroutine or filter name as filter.
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
564
This filter is executed after C<type_rule> filter.
cleanup
Yuki Kimoto authored on 2010-12-21
565

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
566
=head2 C<header>
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
567

            
cleanup
Yuki Kimoto authored on 2012-01-20
568
  my $header = $result->header;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
569

            
570
Get header column names.
571

            
updated pod
Yuki Kimoto authored on 2011-06-07
572
=head2 C<one>
573

            
cleanup
Yuki Kimoto authored on 2012-01-20
574
  my $row = $result->one;
updated pod
Yuki Kimoto authored on 2011-06-07
575

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
576
Alias for C<fetch_hash_one>.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
577

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
578
=head2 C<stash>
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
579

            
cleanup
Yuki Kimoto authored on 2012-01-20
580
  my $stash = $result->stash;
581
  my $foo = $result->stash->{foo};
582
  $result->stash->{foo} = $foo;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
583

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
584
Stash is hash reference to save some data.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
585

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
586
=head2 C<type_rule>
cleanup
Yuki Kimoto authored on 2012-01-20
587
  
588
  # Merge type rule
589
  $result->type_rule(
590
    # DATE
591
    9 => sub { ... },
592
    # DATETIME or TIMESTAMP
593
    11 => sub { ... }
594
  );
595

            
596
  # Replace type rule(by reference)
597
  $result->type_rule([
598
    # DATE
599
    9 => sub { ... },
600
    # DATETIME or TIMESTAMP
601
    11 => sub { ... }
602
  ]);
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
603

            
cleanup
Yuki Kimoto authored on 2011-06-15
604
This is same as L<DBIx::Custom>'s C<type_rule>'s <from>.
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
605

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
606
=head2 C<type_rule_off>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
607

            
cleanup
Yuki Kimoto authored on 2012-01-20
608
  $result = $result->type_rule_off;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
609

            
610
Turn C<from1> and C<from2> type rule off.
611
By default, type rule is on.
612

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
613
=head2 C<type_rule_on>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
614

            
cleanup
Yuki Kimoto authored on 2012-01-20
615
  $result = $result->type_rule_on;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
616

            
617
Turn C<from1> and C<from2> type rule on.
618
By default, type rule is on.
619

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
620
=head2 C<type_rule1_off>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
621

            
cleanup
Yuki Kimoto authored on 2012-01-20
622
  $result = $result->type_rule1_off;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
623

            
624
Turn C<from1> type rule off.
625
By default, type rule is on.
626

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
627
=head2 C<type_rule1_on>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
628

            
cleanup
Yuki Kimoto authored on 2012-01-20
629
  $result = $result->type_rule1_on;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
630

            
631
Turn C<from1> type rule on.
632
By default, type rule is on.
633

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
634
=head2 C<type_rule2_off>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
635

            
cleanup
Yuki Kimoto authored on 2012-01-20
636
  $result = $result->type_rule2_off;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
637

            
638
Turn C<from2> type rule off.
639
By default, type rule is on.
640

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
641
=head2 C<type_rule2_on>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
642

            
cleanup
Yuki Kimoto authored on 2012-01-20
643
  $result = $result->type_rule2_on;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
644

            
645
Turn C<from2> type rule on.
646
By default, type rule is on.
647

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
648
=head2 C<value> EXPERIMENTAL
649

            
cleanup
Yuki Kimoto authored on 2012-01-20
650
  my $value = $result->value;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
651

            
652
Get first column's first value.
653

            
cleanup
Yuki Kimoto authored on 2012-01-20
654
  my $count = $dbi->select('count(*)')->value;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
655

            
packaging one directory
yuki-kimoto authored on 2009-11-16
656
=cut