Newer Older
634 lines | 15.292kb
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/],
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-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

            
cleanup
Yuki Kimoto authored on 2010-12-21
12
sub filter {
13
    my $self = shift;
cleanup
Yuki Kimoto authored on 2010-12-22
14
    
cleanup
Yuki Kimoto authored on 2011-06-15
15
    # Set
cleanup
Yuki Kimoto authored on 2010-12-22
16
    if (@_) {
17
        
cleanup
Yuki Kimoto authored on 2011-06-15
18
        # Convert filter name to subroutine
19
        my $filter = @_ == 1 ? $_[0] : [@_];
20
        $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-10-21
21
        for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2010-12-22
22
            my $fname = $filter->{$column};
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
23
            if  (exists $filter->{$column}
24
              && defined $fname
25
              && ref $fname ne 'CODE') 
26
            {
cleanup
Yuki Kimoto authored on 2011-04-25
27
              croak qq{Filter "$fname" is not registered" } . _subname
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
28
                unless exists $self->dbi->filters->{$fname};
29
              $filter->{$column} = $self->dbi->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-22
30
            }
cleanup
Yuki Kimoto authored on 2010-12-21
31
        }
cleanup
Yuki Kimoto authored on 2010-12-22
32
        
cleanup
Yuki Kimoto authored on 2011-06-15
33
        # Merge
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
34
        $self->{filter} = {%{$self->filter}, %$filter};
cleanup
Yuki Kimoto authored on 2010-12-22
35
        
36
        return $self;
cleanup
Yuki Kimoto authored on 2010-12-21
37
    }
38
    
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
39
    return $self->{filter} ||= {};
40
}
41

            
micro optimization
Yuki Kimoto authored on 2011-11-07
42
sub _cache {
43
    my $self = shift;
44
    $self->{_type_map} = {};
45
    $self->{_pos} = {};
46
    $self->{_columns} = {};
47
    for (my $i = 0; $i < @{$self->{sth}->{NAME}}; $i++) {
48
        my $type = lc $self->{sth}{TYPE}[$i];
49
        my $name = $self->{sth}{NAME}[$i];
50
        $self->{_type_map}{$type} ||= [];
51
        push @{$self->{_type_map}{$type}}, $name;
52
        $self->{_pos}{$name} ||= [];
53
        push @{$self->{_pos}{$name}}, $i;
54
        $self->{_columns}{$name} = 1;
55
    }
56
    $self->{_cache} = 1;
57
}
58

            
59
=pod
60
sub fetch {
61
    my $self = shift;
62
    
63
    # Info
64
    $self->_cache unless $self->{_cache};
65
    
66
    # Fetch
67
    my @row = $self->{sth}->fetchrow_array;
68
    return unless @row;
69
    
70
    # Type rule
71
    if ((my $from = $self->type_rule->{from1}) && !$self->{type_rule_off} && !$self->{type_rule1_off}) {
72
        for my $type (keys %$from) {
73
            for my $column (@{$self->{_type_map}->{$type}}) {
74
                $row[$_] = $from->{$type}->($row[$_])
75
                  for @{$self->{_pos}{$column}};
76
            }
77
        }
78
    }
79
    if ((my $from = $self->type_rule->{from2}) && !$self->{type_rule_off} && !$self->{type_rule2_off}) {
80
        for my $type (keys %$from) {
81
            for my $column (@{$self->{_type_map}->{$type}}) {
82
                $row[$_] = $from->{$type}->($row[$_])
83
                  for @{$self->{_pos}{$column}};
84
            }
85
        }
86
    }
87
    
88
    # Filter
89
    if (($self->{filter} || $self->{default_filter}) && !$self->{filter_off}) {
90
        for my $column (keys %{$self->{filter}}) {
91
            $row[$_] = ($self->{filter}->{$column} || $self->{default_filter} || sub { shift })
92
                ->($row[$_])
93
              for @{$self->{_pos}{$column}};
94
        }
95
    }
96
    if ($self->{end_filter} && !$self->{filter_off}) {
97
         for my $column (keys %{$self->{end_filter}}) {
98
             $row[$_] = $self->{end_filter}->{$column}->($row[$_])
99
               for @{$self->{_pos}{$column}};
100
         }
101
    }
102

            
103
    return \@row;
104
}
105
=cut
106

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
157
sub fetch {
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
158
    my $self = shift;
159
    
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
160
    # Info
161
    my $columns = $self->{sth}->{NAME};
162
    my $types = $self->{sth}->{TYPE};
163
    
packaging one directory
yuki-kimoto authored on 2009-11-16
164
    # Fetch
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
165
    my @row = $self->{sth}->fetchrow_array;
update document
yuki-kimoto authored on 2010-05-27
166
    return unless @row;
added check_filter attribute
yuki-kimoto authored on 2010-08-08
167
    
cleanup
yuki-kimoto authored on 2010-08-05
168
    # Filtering
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
169
    my $type_rule1 = $self->type_rule->{from1} || {};
170
    my $type_rule2 = $self->type_rule->{from2} || {};
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
171
    my $filter = $self->filter;
fixed end_filter DEPRECATED ...
Yuki Kimoto authored on 2011-07-01
172
    my $end_filter = $self->{end_filter} || {};
cleanup
yuki-kimoto authored on 2010-08-05
173
    for (my $i = 0; $i < @$columns; $i++) {
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
174
        
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
175
        # Column
cleanup
yuki-kimoto authored on 2010-08-05
176
        my $column = $columns->[$i];
some changed
yuki-kimoto authored on 2010-05-02
177
        
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
178
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
179
        my $type_filter1 = $type_rule1->{lc($types->[$i])};
180
        $row[$i] = $type_filter1->($row[$i])
181
          if  $type_filter1 && !$self->{type_rule_off}
182
           && !$self->{type_rule1_off};
183
        my $type_filter2 = $type_rule2->{lc($types->[$i])};
184
        $row[$i] = $type_filter2->($row[$i])
185
          if  $type_filter2 && !$self->{type_rule_off}
186
           && !$self->{type_rule2_off};
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
187
        
188
        # Filter
189
        my $filter  = $filter->{$column} || $self->{default_filter};
190
        $row[$i] = $filter->($row[$i])
191
          if $filter && !$self->{filter_off};
192
        $row[$i] = $end_filter->{$column}->($row[$i])
193
          if $end_filter->{$column} && !$self->{filter_off};
packaging one directory
yuki-kimoto authored on 2009-11-16
194
    }
many many changes
yuki-kimoto authored on 2010-04-30
195

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
196
    return \@row;
197
}
198

            
cleanup
yuki-kimoto authored on 2010-10-17
199
sub fetch_all {
200
    my $self = shift;
201
    
202
    # Fetch all rows
203
    my $rows = [];
cleanup
Yuki Kimoto authored on 2011-06-15
204
    while(my $row = $self->fetch) { push @$rows, $row}
205
    
cleanup
yuki-kimoto authored on 2010-10-17
206
    return $rows;
207
}
208

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
209
sub fetch_first {
210
    my $self = shift;
211
    
212
    # Fetch
213
    my $row = $self->fetch;
214
    return unless $row;
215
    
216
    # Finish statement handle
217
    $self->sth->finish;
218
    
219
    return $row;
220
}
221

            
cleanup
yuki-kimoto authored on 2010-10-17
222
sub fetch_hash_all {
223
    my $self = shift;
224
    
225
    # Fetch all rows as hash
226
    my $rows = [];
cleanup
Yuki Kimoto authored on 2011-06-15
227
    while(my $row = $self->fetch_hash) { push @$rows, $row }
cleanup
yuki-kimoto authored on 2010-10-17
228
    
229
    return $rows;
230
}
231

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
232
sub fetch_hash_first {
packaging one directory
yuki-kimoto authored on 2009-11-16
233
    my $self = shift;
234
    
235
    # Fetch hash
236
    my $row = $self->fetch_hash;
237
    return unless $row;
238
    
239
    # Finish statement handle
some changed
yuki-kimoto authored on 2010-05-02
240
    $self->sth->finish;
packaging one directory
yuki-kimoto authored on 2009-11-16
241
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
242
    return $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
243
}
244

            
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
245
sub fetch_hash_multi {
packaging one directory
yuki-kimoto authored on 2009-11-16
246
    my ($self, $count) = @_;
247
    
cleanup
Yuki Kimoto authored on 2011-06-15
248
    # Fetch multiple rows
cleanup
Yuki Kimoto authored on 2011-04-25
249
    croak 'Row count must be specified ' . _subname
packaging one directory
yuki-kimoto authored on 2009-11-16
250
      unless $count;
251
    my $rows = [];
252
    for (my $i = 0; $i < $count; $i++) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
253
        my $row = $self->fetch_hash;
254
        last unless $row;
255
        push @$rows, $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
256
    }
257
    
258
    return unless @$rows;
removed reconnect method
yuki-kimoto authored on 2010-05-28
259
    return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
260
}
261

            
cleanup
yuki-kimoto authored on 2010-10-17
262
sub fetch_multi {
263
    my ($self, $count) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
264
    
cleanup
yuki-kimoto authored on 2010-10-17
265
    # Row count not specifed
cleanup
Yuki Kimoto authored on 2011-04-25
266
    croak 'Row count must be specified ' . _subname
cleanup
yuki-kimoto authored on 2010-10-17
267
      unless $count;
268
    
269
    # Fetch multi rows
packaging one directory
yuki-kimoto authored on 2009-11-16
270
    my $rows = [];
cleanup
yuki-kimoto authored on 2010-10-17
271
    for (my $i = 0; $i < $count; $i++) {
272
        my $row = $self->fetch;
273
        last unless $row;
removed reconnect method
yuki-kimoto authored on 2010-05-28
274
        push @$rows, $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
275
    }
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
276
    
cleanup
yuki-kimoto authored on 2010-10-17
277
    return unless @$rows;
removed reconnect method
yuki-kimoto authored on 2010-05-28
278
    return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
279
}
280

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

            
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
283
*one = \&fetch_hash_first;
284

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
285
sub type_rule {
286
    my $self = shift;
287
    
288
    if (@_) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
289
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
290

            
291
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
292
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
293
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
294
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
295
                croak qq{data type of from$i section must be lower case or number}
296
                  if $data_type =~ /[A-Z]/;
297
                my $fname = $type_rule->{"from$i"}{$data_type};
298
                if (defined $fname && ref $fname ne 'CODE') {
299
                    croak qq{Filter "$fname" is not registered" } . _subname
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
300
                      unless exists $self->dbi->filters->{$fname};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
301
                    
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
302
                    $type_rule->{"from$i"}{$data_type} = $self->dbi->filters->{$fname};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
303
                }
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
304
            }
305
        }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
306
        $self->{type_rule} = $type_rule;
DBIx::Custom::Result type_ru...
Yuki Kimoto authored on 2011-06-17
307
        
308
        return $self;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
309
    }
310
    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
311
    return $self->{type_rule} || {};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
312
}
313

            
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
314
sub type_rule_off {
315
    my $self = shift;
316
    $self->{type_rule_off} = 1;
317
    return $self;
318
}
319

            
320
sub type_rule_on {
321
    my $self = shift;
322
    $self->{type_rule_off} = 0;
323
    return $self;
324
}
325

            
326
sub type_rule1_off {
327
    my $self = shift;
328
    $self->{type_rule1_off} = 1;
329
    return $self;
330
}
331

            
332
sub type_rule1_on {
333
    my $self = shift;
334
    $self->{type_rule1_off} = 0;
335
    return $self;
336
}
337

            
338
sub type_rule2_off {
339
    my $self = shift;
340
    $self->{type_rule2_off} = 1;
341
    return $self;
342
}
343

            
344
sub type_rule2_on {
345
    my $self = shift;
346
    $self->{type_rule2_off} = 0;
347
    return $self;
348
}
349

            
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
350
# DEPRECATED!
351
sub filter_off {
352
    warn "filter_off method is DEPRECATED!";
353
    my $self = shift;
354
    $self->{filter_off} = 1;
355
    return $self;
356
}
357

            
358
# DEPRECATED!
359
sub filter_on {
360
    warn "filter_on method is DEPRECATED!";
361
    my $self = shift;
362
    $self->{filter_off} = 0;
363
    return $self;
364
}
365

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

            
update document
yuki-kimoto authored on 2010-01-30
429
1;
430

            
packaging one directory
yuki-kimoto authored on 2009-11-16
431
=head1 NAME
432

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
437
    # Result
cleanup
Yuki Kimoto authored on 2011-06-15
438
    my $result = $dbi->select(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
439

            
cleanup
Yuki Kimoto authored on 2011-06-15
440
    # Fetch a row and put it into array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
441
    while (my $row = $result->fetch) {
cleanup
yuki-kimoto authored on 2010-08-05
442
        my $author = $row->[0];
443
        my $title  = $row->[1];
version 0.0901
yuki-kimoto authored on 2009-12-17
444
    }
445
    
cleanup
Yuki Kimoto authored on 2011-06-15
446
    # Fetch only a first row and put it into array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
447
    my $row = $result->fetch_first;
448
    
cleanup
Yuki Kimoto authored on 2011-06-15
449
    # Fetch all rows and put them into array of array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
450
    my $rows = $result->fetch_all;
cleanup
yuki-kimoto authored on 2010-08-05
451

            
cleanup
Yuki Kimoto authored on 2011-06-15
452
    # Fetch a row and put it into hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
453
    while (my $row = $result->fetch_hash) {
cleanup
yuki-kimoto authored on 2010-08-05
454
        my $title  = $row->{title};
455
        my $author = $row->{author};
packaging one directory
yuki-kimoto authored on 2009-11-16
456
    }
removed reconnect method
yuki-kimoto authored on 2010-05-28
457
    
cleanup
Yuki Kimoto authored on 2011-06-15
458
    # Fetch only a first row and put it into hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
459
    my $row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-06-15
460
    my $row = $result->one; # Same as fetch_hash_first
removed reconnect method
yuki-kimoto authored on 2010-05-28
461
    
cleanup
Yuki Kimoto authored on 2011-06-15
462
    # Fetch all rows and put them into array of hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
463
    my $rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-06-15
464
    my $rows = $result->all; # Same as fetch_hash_all
packaging one directory
yuki-kimoto authored on 2009-11-16
465

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

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

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
470
    my $dbi = $result->dbi;
471
    $result = $result->dbi($dbi);
cleanup
yuki-kimoto authored on 2010-10-17
472

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

            
475
=head2 C<sth>
476

            
477
    my $sth = $reuslt->sth
478
    $result = $result->sth($sth);
479

            
480
Statement handle of L<DBI>.
481

            
update document
yuki-kimoto authored on 2010-01-30
482
=head1 METHODS
483

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

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

            
489
    my $rows = $result->all;
490

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
495
    my $row = $result->fetch;
version 0.0901
yuki-kimoto authored on 2009-12-17
496

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
501
    my $rows = $result->fetch_all;
version 0.0901
yuki-kimoto authored on 2009-12-17
502

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

            
cleanup
yuki-kimoto authored on 2010-10-17
505
=head2 C<fetch_first>
506

            
507
    my $row = $result->fetch_first;
508

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
514
    my $row = $result->fetch_hash;
packaging one directory
yuki-kimoto authored on 2009-11-16
515

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

            
cleanup
yuki-kimoto authored on 2010-10-17
518
=head2 C<fetch_hash_all>
519

            
520
    my $rows = $result->fetch_hash_all;
521

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

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
524
=head2 C<fetch_hash_first>
removed reconnect method
yuki-kimoto authored on 2010-05-28
525
    
cleanup
yuki-kimoto authored on 2010-08-05
526
    my $row = $result->fetch_hash_first;
packaging one directory
yuki-kimoto authored on 2009-11-16
527

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
533
    my $rows = $result->fetch_hash_multi(5);
update document
yuki-kimoto authored on 2009-11-19
534
    
cleanup
Yuki Kimoto authored on 2011-06-15
535
Fetch multiple rows and put them into array of hash reference.
update document
yuki-kimoto authored on 2009-11-19
536

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

            
cleanup
yuki-kimoto authored on 2010-10-17
539
    my $rows = $result->fetch_multi(5);
540
    
cleanup
Yuki Kimoto authored on 2011-06-15
541
Fetch multiple rows and put them into array of array reference.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
542

            
cleanup
Yuki Kimoto authored on 2010-12-21
543
=head2 C<filter>
544

            
cleanup
Yuki Kimoto authored on 2011-06-15
545
    $result->filter(title  => sub { uc $_[0] }, author => 'to_upper');
546
    $result->filter([qw/title author/] => 'to_upper');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
547

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

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

            
554
    my $header = $result->header;
555

            
556
Get header column names.
557

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

            
560
    my $row = $result->one;
561

            
cleanup
Yuki Kimoto authored on 2011-06-15
562
Same as C<fetch_hash_first>.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
563

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

            
566
    my $stash = $result->stash;
567
    my $foo = $result->stash->{foo};
568
    $result->stash->{foo} = $foo;
569

            
cleanup
Yuki Kimoto authored on 2011-06-15
570
Stash is hash reference for data.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
571

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
572
=head2 C<type_rule>
cleanup
Yuki Kimoto authored on 2011-06-15
573
    
574
    # Merge type rule
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
575
    $result->type_rule(
576
        # DATE
577
        9 => sub { ... },
578
        # DATETIME or TIMESTAMP
579
        11 => sub { ... }
580
    );
581

            
cleanup
Yuki Kimoto authored on 2011-06-15
582
    # Replace type rule(by reference)
583
    $result->type_rule([
584
        # DATE
585
        9 => sub { ... },
586
        # DATETIME or TIMESTAMP
587
        11 => sub { ... }
588
    ]);
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
589

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

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

            
594
    $result = $result->type_rule_off;
595

            
596
Turn C<from1> and C<from2> type rule off.
597
By default, type rule is on.
598

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

            
601
    $result = $result->type_rule_on;
602

            
603
Turn C<from1> and C<from2> type rule on.
604
By default, type rule is on.
605

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

            
608
    $result = $result->type_rule1_off;
609

            
610
Turn C<from1> 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_rule1_on>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
614

            
615
    $result = $result->type_rule1_on;
616

            
617
Turn C<from1> 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_rule2_off>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
621

            
622
    $result = $result->type_rule2_off;
623

            
624
Turn C<from2> 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_rule2_on>
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
628

            
629
    $result = $result->type_rule2_on;
630

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

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