Newer Older
689 lines | 14.768kb
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

            
micro optimization
Yuki Kimoto authored on 2011-11-07
21
sub fetch {
cleanup
Yuki Kimoto authored on 2012-01-20
22
  my $self = shift;
23
  
24
  # Info
25
  $self->_cache unless $self->{_cache};
26
  
27
  # Fetch
28
  my @row = $self->{sth}->fetchrow_array;
29
  return unless @row;
30
  
31
  # Type rule
32
  if ($self->{type_rule}->{from1} && !$self->{type_rule_off} && !$self->{type_rule1_off}) {
33
    my $from = $self->{type_rule}->{from1};
34
    for my $type (keys %$from) {
35
      for my $column (@{$self->{_type_map}->{$type}}) {
36
        $row[$_] = $from->{$type}->($row[$_])
37
          for @{$self->{_pos}{$column} || []};
38
      }
micro optimization
Yuki Kimoto authored on 2011-11-07
39
    }
cleanup
Yuki Kimoto authored on 2012-01-20
40
  }
41
  if ($self->{type_rule}->{from2} && !$self->{type_rule_off} && !$self->{type_rule2_off}) {
42
    my $from = $self->{type_rule}->{from2};
43
    for my $type (keys %$from) {
44
      for my $column (@{$self->{_type_map}->{$type}}) {
45
        $row[$_] = $from->{$type}->($row[$_])
46
          for @{$self->{_pos}{$column} || []};
47
      }
micro optimization
Yuki Kimoto authored on 2011-11-07
48
    }
cleanup
Yuki Kimoto authored on 2012-01-20
49
  }
50
  
51
  # Filter
52
  if (($self->{filter} || $self->{default_filter}) && !$self->{filter_off}) {
53
     my @columns = $self->{default_filter} ? keys %{$self->{_columns}}
54
       : keys %{$self->{filter}};
55
     
56
     for my $column (@columns) {
57
       my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column}
58
         : $self->{default_filter};
59
       next unless $filter;
60
       $row[$_] = $filter->($row[$_])
61
         for @{$self->{_pos}{$column} || []};
62
     }
63
  }
64
  if ($self->{end_filter} && !$self->{filter_off}) {
65
     for my $column (keys %{$self->{end_filter}}) {
66
       next unless $self->{end_filter}->{$column};
67
       $row[$_] = $self->{end_filter}->{$column}->($row[$_])
68
         for @{$self->{_pos}{$column} || []};
69
     }
70
  }
71

            
72
  return \@row;
micro optimization
Yuki Kimoto authored on 2011-11-07
73
}
74

            
75
sub fetch_hash {
cleanup
Yuki Kimoto authored on 2012-01-20
76
  my $self = shift;
77
  
78
  # Info
79
  $self->_cache unless $self->{_cache};
80
  
81
  # Fetch
82
  return unless my $row = $self->{sth}->fetchrow_hashref;
83
  
84
  # Type rule
85
  if ($self->{type_rule}->{from1} &&
86
    !$self->{type_rule_off} && !$self->{type_rule1_off})
87
  {
88
    my $from = $self->{type_rule}->{from1};
89
    for my $type (keys %$from) {
90
      $from->{$type} and $row->{$_} = $from->{$type}->($row->{$_})
91
        for @{$self->{_type_map}->{$type}};
micro optimization
Yuki Kimoto authored on 2011-11-07
92
    }
cleanup
Yuki Kimoto authored on 2012-01-20
93
  }
94
  if ($self->{type_rule}->{from2} &&
95
    !$self->{type_rule_off} && !$self->{type_rule2_off})
96
  {
97
    my $from = $self->{type_rule}->{from2};
98
    for my $type (keys %{$self->{type_rule}->{from2}}) {
99
      $from->{$type} and $row->{$_} = $from->{$type}->($row->{$_})
100
        for @{$self->{_type_map}->{$type}};
micro optimization
Yuki Kimoto authored on 2011-11-07
101
    }
cleanup
Yuki Kimoto authored on 2012-01-20
102
  }        
103
  # Filter
104
  if (($self->{filter} || $self->{default_filter}) &&
105
    !$self->{filter_off})
106
  {
107
     my @columns = $self->{default_filter} ? keys %{$self->{_columns}}
108
       : keys %{$self->{filter}};
109
     
110
     for my $column (@columns) {
111
       next unless exists $row->{$column};
112
       my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column}
113
         : $self->{default_filter};
114
       $row->{$column} = $filter->($row->{$column}) if $filter;
115
     }
116
  }
117
  if ($self->{end_filter} && !$self->{filter_off}) {
118
     exists $self->{_columns}{$_} && $self->{end_filter}->{$_} and
119
         $row->{$_} = $self->{end_filter}->{$_}->($row->{$_})
120
       for keys %{$self->{end_filter}};
121
  }
122
  $row;
micro optimization
Yuki Kimoto authored on 2011-11-07
123
}
124

            
cleanup
yuki-kimoto authored on 2010-10-17
125
sub fetch_all {
cleanup
Yuki Kimoto authored on 2012-01-20
126
  my $self = shift;
127
  
128
  # Fetch all rows
129
  my $rows = [];
130
  while(my $row = $self->fetch) { push @$rows, $row}
131
  
132
  return $rows;
cleanup
yuki-kimoto authored on 2010-10-17
133
}
134

            
135
sub fetch_hash_all {
cleanup
Yuki Kimoto authored on 2012-01-20
136
  my $self = shift;
137
  
138
  # Fetch all rows as hash
139
  my $rows = [];
140
  while(my $row = $self->fetch_hash) { push @$rows, $row }
141
  
142
  return $rows;
cleanup
yuki-kimoto authored on 2010-10-17
143
}
144

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
145
sub fetch_hash_one {
cleanup
Yuki Kimoto authored on 2012-01-20
146
  my $self = shift;
147
  
148
  # Fetch hash
149
  my $row = $self->fetch_hash;
150
  return unless $row;
151
  
152
  # Finish statement handle
153
  $self->sth->finish;
154
  
155
  return $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
156
}
157

            
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
158
sub fetch_hash_multi {
cleanup
Yuki Kimoto authored on 2012-01-20
159
  my ($self, $count) = @_;
160
  
161
  # Fetch multiple rows
162
  croak 'Row count must be specified ' . _subname
163
    unless $count;
164
  
165
  return if $self->{_finished};
166

            
167
  my $rows = [];
168
  for (my $i = 0; $i < $count; $i++) {
169
    my $row = $self->fetch_hash;
170
    unless ($row) {
171
      $self->{_finished} = 1;
172
      last;
packaging one directory
yuki-kimoto authored on 2009-11-16
173
    }
cleanup
Yuki Kimoto authored on 2012-01-20
174
    push @$rows, $row;
175
  }
176
  
177
  return unless @$rows;
178
  return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
179
}
180

            
cleanup
yuki-kimoto authored on 2010-10-17
181
sub fetch_multi {
cleanup
Yuki Kimoto authored on 2012-01-20
182
  my ($self, $count) = @_;
183
  
184
  # Row count not specifed
185
  croak 'Row count must be specified ' . _subname
186
    unless $count;
187
  
188
  return if $self->{_finished};
189
  
190
  # Fetch multi rows
191
  my $rows = [];
192
  for (my $i = 0; $i < $count; $i++) {
193
    my $row = $self->fetch;
194
    unless ($row) {
195
      $self->{_finished} = 1;
196
      last;
packaging one directory
yuki-kimoto authored on 2009-11-16
197
    }
cleanup
Yuki Kimoto authored on 2012-01-20
198
    push @$rows, $row;
199
  }
200
  
201
  return unless @$rows;
202
  return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
203
}
204

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

            
206
sub fetch_one {
cleanup
Yuki Kimoto authored on 2012-01-20
207
  my $self = shift;
208
  
209
  # Fetch
210
  my $row = $self->fetch;
211
  return unless $row;
212
  
213
  # Finish statement handle
214
  $self->sth->finish;
215
  
216
  return $row;
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
217
}
218

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
219
sub filter {
220
  my $self = shift;
221
  
222
  # Set
223
  if (@_) {
224
    
225
    # Convert filter name to subroutine
226
    my $filter = @_ == 1 ? $_[0] : [@_];
227
    $filter = _array_to_hash($filter);
228
    for my $column (keys %$filter) {
229
      my $fname = $filter->{$column};
230
      if  (exists $filter->{$column}
231
        && defined $fname
232
        && ref $fname ne 'CODE') 
233
      {
234
        croak qq{Filter "$fname" is not registered" } . _subname
235
          unless exists $self->dbi->filters->{$fname};
236
        $filter->{$column} = $self->dbi->filters->{$fname};
237
      }
238
    }
239
    
240
    # Merge
241
    $self->{filter} = {%{$self->filter}, %$filter};
242
    
243
    return $self;
244
  }
245
  
246
  return $self->{filter} ||= {};
247
}
248

            
249
sub flat {
250
  my $self = shift;
251
  
252
  my @flat;
253
  while (my $row = $self->fetch) {
254
    push @flat, @$row;
255
  }
256
  return @flat;
257
}
258

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
263
sub type_rule {
cleanup
Yuki Kimoto authored on 2012-01-20
264
  my $self = shift;
265
  
266
  if (@_) {
267
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
268

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

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

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

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

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

            
316
sub type_rule2_off {
cleanup
Yuki Kimoto authored on 2012-01-20
317
  my $self = shift;
318
  $self->{type_rule2_off} = 1;
319
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
320
}
321

            
322
sub type_rule2_on {
cleanup
Yuki Kimoto authored on 2012-01-20
323
  my $self = shift;
324
  $self->{type_rule2_off} = 0;
325
  return $self;
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
326
}
327

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
328
sub value {
cleanup
Yuki Kimoto authored on 2012-01-20
329
  my $self = shift;
330
  my $row = $self->fetch_one;
331
  my $value = $row ? $row->[0] : undef;
332
  return $value;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
333
}
334

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
335
sub _cache {
cleanup
Yuki Kimoto authored on 2012-01-20
336
  my $self = shift;
337
  $self->{_type_map} = {};
338
  $self->{_pos} = {};
339
  $self->{_columns} = {};
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
340
  for (my $i = 0; $i < @{$self->{sth}->{NAME} || []}; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
341
    my $type = lc $self->{sth}{TYPE}[$i];
342
    my $name = $self->{sth}{NAME}[$i];
343
    $self->{_type_map}{$type} ||= [];
344
    push @{$self->{_type_map}{$type}}, $name;
345
    $self->{_pos}{$name} ||= [];
346
    push @{$self->{_pos}{$name}}, $i;
347
    $self->{_columns}{$name} = 1;
348
  }
349
  $self->{_cache} = 1;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
350
}
351

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

            
359
# DEPRECATED!
360
sub fetch_first {
cleanup
Yuki Kimoto authored on 2012-01-20
361
  my $self = shift;
362
  warn "DBIx::Custom::Result::fetch_first is DEPRECATED! use fetch_one instead";
363
  return $self->fetch_one(@_);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
364
}
365

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

            
374
# DEPRECATED!
375
sub filter_on {
cleanup
Yuki Kimoto authored on 2012-01-20
376
  warn "filter_on method is DEPRECATED!";
377
  my $self = shift;
378
  $self->{filter_off} = 0;
379
  return $self;
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
380
}
381

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

            
update document
yuki-kimoto authored on 2010-01-30
445
1;
446

            
packaging one directory
yuki-kimoto authored on 2009-11-16
447
=head1 NAME
448

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

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

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

            
456
  # Fetch a row and put it into array reference
457
  while (my $row = $result->fetch) {
458
    my $author = $row->[0];
459
    my $title  = $row->[1];
460
  }
461
  
462
  # Fetch only a first row and put it into array reference
463
  my $row = $result->fetch_one;
464
  
465
  # Fetch all rows and put them into array of array reference
466
  my $rows = $result->fetch_all;
467

            
468
  # Fetch a row and put it into hash reference
469
  while (my $row = $result->fetch_hash) {
470
    my $title  = $row->{title};
471
    my $author = $row->{author};
472
  }
473
  
474
  # Fetch only a first row and put it into hash reference
475
  my $row = $result->fetch_hash_one;
476
  my $row = $result->one; # Alias for "fetch_hash_one"
477
  
478
  # Fetch all rows and put them into array of hash reference
479
  my $rows = $result->fetch_hash_all;
480
  my $rows = $result->all; # Alias for "fetch_hash_all"
packaging one directory
yuki-kimoto authored on 2009-11-16
481

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
486
  my $dbi = $result->dbi;
487
  $result = $result->dbi($dbi);
cleanup
yuki-kimoto authored on 2010-10-17
488

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

            
491
=head2 C<sth>
492

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

            
496
Statement handle of L<DBI>.
497

            
update document
yuki-kimoto authored on 2010-01-30
498
=head1 METHODS
499

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

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
509
=head2 C<column>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
510

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

            
513
Get first column's all values.
514

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
542
=head2 C<fetch_hash_all>
543

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
567
=head2 C<filter>
568

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
576
=head2 C<flat> EXPERIMENTAL
577

            
578
  my $flat = $result->flat;
579

            
580
All value is flatten and added to one array reference.
581
  
582
  my @flat = $dbi->select(['id', 'title'])->flat;
583

            
584
If C<fetch_all> method return the following data
585

            
586
  [
587
    [1, 'Perl'],
588
    [2, 'Ruby']
589
  ]
590

            
591
C<flat> method return the following data.
592

            
593
  (1, 'Perl', 2, 'Ruby')
594

            
595
You can create key-value pair easily.
596

            
597
  my %titles = $dbi->select(['id', 'title'])->flat;
598

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

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

            
603
Get header column names.
604

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
613
  my $stash = $result->stash;
614
  my $foo = $result->stash->{foo};
615
  $result->stash->{foo} = $foo;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
616

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
619
=head2 C<type_rule>
cleanup
Yuki Kimoto authored on 2012-01-20
620
  
621
  # Merge type rule
622
  $result->type_rule(
623
    # DATE
624
    9 => sub { ... },
625
    # DATETIME or TIMESTAMP
626
    11 => sub { ... }
627
  );
628

            
629
  # Replace type rule(by reference)
630
  $result->type_rule([
631
    # DATE
632
    9 => sub { ... },
633
    # DATETIME or TIMESTAMP
634
    11 => sub { ... }
635
  ]);
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
636

            
cleanup
Yuki Kimoto authored on 2011-06-15
637
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
638

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

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

            
643
Turn C<from1> and C<from2> type rule off.
644
By default, type rule is on.
645

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

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

            
650
Turn C<from1> and C<from2> type rule on.
651
By default, type rule is on.
652

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

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

            
657
Turn C<from1> type rule off.
658
By default, type rule is on.
659

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

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

            
664
Turn C<from1> type rule on.
665
By default, type rule is on.
666

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

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

            
671
Turn C<from2> type rule off.
672
By default, type rule is on.
673

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

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

            
678
Turn C<from2> type rule on.
679
By default, type rule is on.
680

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
681
=head2 C<value>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
682

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

            
685
Get first column's first value.
686

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

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