Newer Older
609 lines | 14.554kb
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 fetch {
43
    my $self = shift;
44
    
45
    # Info
46
    $self->_cache unless $self->{_cache};
47
    
48
    # Fetch
49
    my @row = $self->{sth}->fetchrow_array;
50
    return unless @row;
51
    
52
    # Type rule
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
53
    if ($self->{type_rule}->{from1} && !$self->{type_rule_off} && !$self->{type_rule1_off}) {
54
        my $from = $self->{type_rule}->{from1};
micro optimization
Yuki Kimoto authored on 2011-11-07
55
        for my $type (keys %$from) {
56
            for my $column (@{$self->{_type_map}->{$type}}) {
57
                $row[$_] = $from->{$type}->($row[$_])
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
58
                  for @{$self->{_pos}{$column} || []};
micro optimization
Yuki Kimoto authored on 2011-11-07
59
            }
60
        }
61
    }
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
62
    if ($self->{type_rule}->{from2} && !$self->{type_rule_off} && !$self->{type_rule2_off}) {
63
        my $from = $self->{type_rule}->{from2};
micro optimization
Yuki Kimoto authored on 2011-11-07
64
        for my $type (keys %$from) {
65
            for my $column (@{$self->{_type_map}->{$type}}) {
66
                $row[$_] = $from->{$type}->($row[$_])
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
67
                  for @{$self->{_pos}{$column} || []};
micro optimization
Yuki Kimoto authored on 2011-11-07
68
            }
69
        }
70
    }
71
    
72
    # Filter
73
    if (($self->{filter} || $self->{default_filter}) && !$self->{filter_off}) {
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
74
         my @columns = $self->{default_filter} ? keys %{$self->{_columns}}
75
           : keys %{$self->{filter}};
76
         
77
         for my $column (@columns) {
78
             my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column}
79
               : $self->{default_filter};
80
             next unless $filter;
81
             $row[$_] = $filter->($row[$_])
82
               for @{$self->{_pos}{$column} || []};
83
         }
micro optimization
Yuki Kimoto authored on 2011-11-07
84
    }
85
    if ($self->{end_filter} && !$self->{filter_off}) {
86
         for my $column (keys %{$self->{end_filter}}) {
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
87
             next unless $self->{end_filter}->{$column};
micro optimization
Yuki Kimoto authored on 2011-11-07
88
             $row[$_] = $self->{end_filter}->{$column}->($row[$_])
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
89
               for @{$self->{_pos}{$column} || []};
micro optimization
Yuki Kimoto authored on 2011-11-07
90
         }
91
    }
92

            
93
    return \@row;
94
}
95

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

            
cleanup
yuki-kimoto authored on 2010-10-17
146
sub fetch_all {
147
    my $self = shift;
148
    
149
    # Fetch all rows
150
    my $rows = [];
cleanup
Yuki Kimoto authored on 2011-06-15
151
    while(my $row = $self->fetch) { push @$rows, $row}
152
    
cleanup
yuki-kimoto authored on 2010-10-17
153
    return $rows;
154
}
155

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
156
sub fetch_first {
157
    my $self = shift;
158
    
159
    # Fetch
160
    my $row = $self->fetch;
161
    return unless $row;
162
    
163
    # Finish statement handle
164
    $self->sth->finish;
165
    
166
    return $row;
167
}
168

            
cleanup
yuki-kimoto authored on 2010-10-17
169
sub fetch_hash_all {
170
    my $self = shift;
171
    
172
    # Fetch all rows as hash
173
    my $rows = [];
cleanup
Yuki Kimoto authored on 2011-06-15
174
    while(my $row = $self->fetch_hash) { push @$rows, $row }
cleanup
yuki-kimoto authored on 2010-10-17
175
    
176
    return $rows;
177
}
178

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
179
sub fetch_hash_first {
packaging one directory
yuki-kimoto authored on 2009-11-16
180
    my $self = shift;
181
    
182
    # Fetch hash
183
    my $row = $self->fetch_hash;
184
    return unless $row;
185
    
186
    # Finish statement handle
some changed
yuki-kimoto authored on 2010-05-02
187
    $self->sth->finish;
packaging one directory
yuki-kimoto authored on 2009-11-16
188
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
189
    return $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
190
}
191

            
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
192
sub fetch_hash_multi {
packaging one directory
yuki-kimoto authored on 2009-11-16
193
    my ($self, $count) = @_;
194
    
cleanup
Yuki Kimoto authored on 2011-06-15
195
    # Fetch multiple rows
cleanup
Yuki Kimoto authored on 2011-04-25
196
    croak 'Row count must be specified ' . _subname
packaging one directory
yuki-kimoto authored on 2009-11-16
197
      unless $count;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
198
    
199
    return if $self->{_finished};
200

            
packaging one directory
yuki-kimoto authored on 2009-11-16
201
    my $rows = [];
202
    for (my $i = 0; $i < $count; $i++) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
203
        my $row = $self->fetch_hash;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
204
        unless ($row) {
205
            $self->{_finished} = 1;
206
            last;
207
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
208
        push @$rows, $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
209
    }
210
    
211
    return unless @$rows;
removed reconnect method
yuki-kimoto authored on 2010-05-28
212
    return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
213
}
214

            
cleanup
yuki-kimoto authored on 2010-10-17
215
sub fetch_multi {
216
    my ($self, $count) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
217
    
cleanup
yuki-kimoto authored on 2010-10-17
218
    # Row count not specifed
cleanup
Yuki Kimoto authored on 2011-04-25
219
    croak 'Row count must be specified ' . _subname
cleanup
yuki-kimoto authored on 2010-10-17
220
      unless $count;
221
    
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
222
    return if $self->{_finished};
223
    
cleanup
yuki-kimoto authored on 2010-10-17
224
    # Fetch multi rows
packaging one directory
yuki-kimoto authored on 2009-11-16
225
    my $rows = [];
cleanup
yuki-kimoto authored on 2010-10-17
226
    for (my $i = 0; $i < $count; $i++) {
227
        my $row = $self->fetch;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
228
        unless ($row) {
229
            $self->{_finished} = 1;
230
            last;
231
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
232
        push @$rows, $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
233
    }
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
234
    
cleanup
yuki-kimoto authored on 2010-10-17
235
    return unless @$rows;
removed reconnect method
yuki-kimoto authored on 2010-05-28
236
    return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
237
}
238

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
243
sub type_rule {
244
    my $self = shift;
245
    
246
    if (@_) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
247
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
248

            
249
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
250
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
251
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
252
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
253
                croak qq{data type of from$i section must be lower case or number}
254
                  if $data_type =~ /[A-Z]/;
255
                my $fname = $type_rule->{"from$i"}{$data_type};
256
                if (defined $fname && ref $fname ne 'CODE') {
257
                    croak qq{Filter "$fname" is not registered" } . _subname
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
258
                      unless exists $self->dbi->filters->{$fname};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
259
                    
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
260
                    $type_rule->{"from$i"}{$data_type} = $self->dbi->filters->{$fname};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
261
                }
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
262
            }
263
        }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
264
        $self->{type_rule} = $type_rule;
DBIx::Custom::Result type_ru...
Yuki Kimoto authored on 2011-06-17
265
        
266
        return $self;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
267
    }
268
    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
269
    return $self->{type_rule} || {};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
270
}
271

            
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
272
sub type_rule_off {
273
    my $self = shift;
274
    $self->{type_rule_off} = 1;
275
    return $self;
276
}
277

            
278
sub type_rule_on {
279
    my $self = shift;
280
    $self->{type_rule_off} = 0;
281
    return $self;
282
}
283

            
284
sub type_rule1_off {
285
    my $self = shift;
286
    $self->{type_rule1_off} = 1;
287
    return $self;
288
}
289

            
290
sub type_rule1_on {
291
    my $self = shift;
292
    $self->{type_rule1_off} = 0;
293
    return $self;
294
}
295

            
296
sub type_rule2_off {
297
    my $self = shift;
298
    $self->{type_rule2_off} = 1;
299
    return $self;
300
}
301

            
302
sub type_rule2_on {
303
    my $self = shift;
304
    $self->{type_rule2_off} = 0;
305
    return $self;
306
}
307

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
308
sub _cache {
309
    my $self = shift;
310
    $self->{_type_map} = {};
311
    $self->{_pos} = {};
312
    $self->{_columns} = {};
313
    for (my $i = 0; $i < @{$self->{sth}->{NAME}}; $i++) {
314
        my $type = lc $self->{sth}{TYPE}[$i];
315
        my $name = $self->{sth}{NAME}[$i];
316
        $self->{_type_map}{$type} ||= [];
317
        push @{$self->{_type_map}{$type}}, $name;
318
        $self->{_pos}{$name} ||= [];
319
        push @{$self->{_pos}{$name}}, $i;
320
        $self->{_columns}{$name} = 1;
321
    }
322
    $self->{_cache} = 1;
323
}
324

            
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
325
# DEPRECATED!
326
sub filter_off {
327
    warn "filter_off method is DEPRECATED!";
328
    my $self = shift;
329
    $self->{filter_off} = 1;
330
    return $self;
331
}
332

            
333
# DEPRECATED!
334
sub filter_on {
335
    warn "filter_on method is DEPRECATED!";
336
    my $self = shift;
337
    $self->{filter_off} = 0;
338
    return $self;
339
}
340

            
cleanup
Yuki Kimoto authored on 2011-06-13
341
# DEPRECATED!
342
sub end_filter {
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
343
    warn "end_filter method is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
344
    my $self = shift;
345
    if (@_) {
346
        my $end_filter = {};
cleanup
Yuki Kimoto authored on 2011-06-15
347
        if (ref $_[0] eq 'HASH') { $end_filter = $_[0] }
348
        else { 
cleanup
Yuki Kimoto authored on 2011-06-13
349
            $end_filter = _array_to_hash(
350
                @_ > 1 ? [@_] : $_[0]
351
            );
352
        }
cleanup
Yuki Kimoto authored on 2011-10-21
353
        for my $column (keys %$end_filter) {
cleanup
Yuki Kimoto authored on 2011-06-13
354
            my $fname = $end_filter->{$column};
355
            if  (exists $end_filter->{$column}
356
              && defined $fname
357
              && ref $fname ne 'CODE') 
358
            {
359
              croak qq{Filter "$fname" is not registered" } . _subname
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
360
                unless exists $self->dbi->filters->{$fname};
361
              $end_filter->{$column} = $self->dbi->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-06-13
362
            }
363
        }
364
        $self->{end_filter} = {%{$self->end_filter}, %$end_filter};
365
        return $self;
366
    }
367
    return $self->{end_filter} ||= {};
368
}
cleanup
Yuki Kimoto authored on 2011-06-13
369
# DEPRECATED!
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
370
sub remove_end_filter {
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
371
    warn "remove_end_filter is DEPRECATED!";
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
372
    my $self = shift;
373
    $self->{end_filter} = {};
374
    return $self;
375
}
cleanup
Yuki Kimoto authored on 2011-06-13
376
# DEPRECATED!
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
377
sub remove_filter {
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
378
    warn "remove_filter is DEPRECATED!";
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
379
    my $self = shift;
380
    $self->{filter} = {};
381
    return $self;
382
}
cleanup
Yuki Kimoto authored on 2011-06-13
383
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
384
sub default_filter {
cleanup
Yuki Kimoto authored on 2011-06-13
385
    warn "default_filter is DEPRECATED!";
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
386
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-01-12
387
    if (@_) {
388
        my $fname = $_[0];
389
        if (@_ && !$fname) {
390
            $self->{default_filter} = undef;
391
        }
392
        else {
many changed
Yuki Kimoto authored on 2011-01-23
393
            croak qq{Filter "$fname" is not registered}
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
394
              unless exists $self->dbi->filters->{$fname};
395
            $self->{default_filter} = $self->dbi->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
396
        }
397
        return $self;
398
    }
399
    return $self->{default_filter};
400
}
cleanup
Yuki Kimoto authored on 2011-01-23
401
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
402
has 'filter_check'; 
cleanup
Yuki Kimoto authored on 2011-01-23
403

            
update document
yuki-kimoto authored on 2010-01-30
404
1;
405

            
packaging one directory
yuki-kimoto authored on 2009-11-16
406
=head1 NAME
407

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-15
415
    # Fetch a row and put it into array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
416
    while (my $row = $result->fetch) {
cleanup
yuki-kimoto authored on 2010-08-05
417
        my $author = $row->[0];
418
        my $title  = $row->[1];
version 0.0901
yuki-kimoto authored on 2009-12-17
419
    }
420
    
cleanup
Yuki Kimoto authored on 2011-06-15
421
    # Fetch only a first row and put it into array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
422
    my $row = $result->fetch_first;
423
    
cleanup
Yuki Kimoto authored on 2011-06-15
424
    # Fetch all rows and put them into array of array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
425
    my $rows = $result->fetch_all;
cleanup
yuki-kimoto authored on 2010-08-05
426

            
cleanup
Yuki Kimoto authored on 2011-06-15
427
    # Fetch a row and put it into hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
428
    while (my $row = $result->fetch_hash) {
cleanup
yuki-kimoto authored on 2010-08-05
429
        my $title  = $row->{title};
430
        my $author = $row->{author};
packaging one directory
yuki-kimoto authored on 2009-11-16
431
    }
removed reconnect method
yuki-kimoto authored on 2010-05-28
432
    
cleanup
Yuki Kimoto authored on 2011-06-15
433
    # Fetch only a first row and put it into hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
434
    my $row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-06-15
435
    my $row = $result->one; # Same as fetch_hash_first
removed reconnect method
yuki-kimoto authored on 2010-05-28
436
    
cleanup
Yuki Kimoto authored on 2011-06-15
437
    # Fetch all rows and put them into array of hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
438
    my $rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-06-15
439
    my $rows = $result->all; # Same as fetch_hash_all
packaging one directory
yuki-kimoto authored on 2009-11-16
440

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

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

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

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

            
450
=head2 C<sth>
451

            
452
    my $sth = $reuslt->sth
453
    $result = $result->sth($sth);
454

            
455
Statement handle of L<DBI>.
456

            
update document
yuki-kimoto authored on 2010-01-30
457
=head1 METHODS
458

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

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

            
464
    my $rows = $result->all;
465

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
480
=head2 C<fetch_first>
481

            
482
    my $row = $result->fetch_first;
483

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
493
=head2 C<fetch_hash_all>
494

            
495
    my $rows = $result->fetch_hash_all;
496

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
518
=head2 C<filter>
519

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

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

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

            
529
    my $header = $result->header;
530

            
531
Get header column names.
532

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

            
535
    my $row = $result->one;
536

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

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

            
541
    my $stash = $result->stash;
542
    my $foo = $result->stash->{foo};
543
    $result->stash->{foo} = $foo;
544

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
547
=head2 C<type_rule>
cleanup
Yuki Kimoto authored on 2011-06-15
548
    
549
    # Merge type rule
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
550
    $result->type_rule(
551
        # DATE
552
        9 => sub { ... },
553
        # DATETIME or TIMESTAMP
554
        11 => sub { ... }
555
    );
556

            
cleanup
Yuki Kimoto authored on 2011-06-15
557
    # Replace type rule(by reference)
558
    $result->type_rule([
559
        # DATE
560
        9 => sub { ... },
561
        # DATETIME or TIMESTAMP
562
        11 => sub { ... }
563
    ]);
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
564

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

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

            
569
    $result = $result->type_rule_off;
570

            
571
Turn C<from1> and C<from2> type rule off.
572
By default, type rule is on.
573

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

            
576
    $result = $result->type_rule_on;
577

            
578
Turn C<from1> and C<from2> type rule on.
579
By default, type rule is on.
580

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

            
583
    $result = $result->type_rule1_off;
584

            
585
Turn C<from1> type rule off.
586
By default, type rule is on.
587

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

            
590
    $result = $result->type_rule1_on;
591

            
592
Turn C<from1> type rule on.
593
By default, type rule is on.
594

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

            
597
    $result = $result->type_rule2_off;
598

            
599
Turn C<from2> type rule off.
600
By default, type rule is on.
601

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

            
604
    $result = $result->type_rule2_on;
605

            
606
Turn C<from2> type rule on.
607
By default, type rule is on.
608

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