Newer Older
641 lines | 15.159kb
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

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

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

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

            
102
    return \@row;
103
}
104

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
165
sub fetch_first {
166
    my $self = shift;
167
    
168
    # Fetch
169
    my $row = $self->fetch;
170
    return unless $row;
171
    
172
    # Finish statement handle
173
    $self->sth->finish;
174
    
175
    return $row;
176
}
177

            
cleanup
yuki-kimoto authored on 2010-10-17
178
sub fetch_hash_all {
179
    my $self = shift;
180
    
181
    # Fetch all rows as hash
182
    my $rows = [];
cleanup
Yuki Kimoto authored on 2011-06-15
183
    while(my $row = $self->fetch_hash) { push @$rows, $row }
cleanup
yuki-kimoto authored on 2010-10-17
184
    
185
    return $rows;
186
}
187

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
188
sub fetch_hash_first {
packaging one directory
yuki-kimoto authored on 2009-11-16
189
    my $self = shift;
190
    
191
    # Fetch hash
192
    my $row = $self->fetch_hash;
193
    return unless $row;
194
    
195
    # Finish statement handle
some changed
yuki-kimoto authored on 2010-05-02
196
    $self->sth->finish;
packaging one directory
yuki-kimoto authored on 2009-11-16
197
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
198
    return $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
199
}
200

            
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
201
sub fetch_hash_multi {
packaging one directory
yuki-kimoto authored on 2009-11-16
202
    my ($self, $count) = @_;
203
    
cleanup
Yuki Kimoto authored on 2011-06-15
204
    # Fetch multiple rows
cleanup
Yuki Kimoto authored on 2011-04-25
205
    croak 'Row count must be specified ' . _subname
packaging one directory
yuki-kimoto authored on 2009-11-16
206
      unless $count;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
207
    
208
    return if $self->{_finished};
209

            
packaging one directory
yuki-kimoto authored on 2009-11-16
210
    my $rows = [];
211
    for (my $i = 0; $i < $count; $i++) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
212
        my $row = $self->fetch_hash;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
213
        unless ($row) {
214
            $self->{_finished} = 1;
215
            last;
216
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
217
        push @$rows, $row;
packaging one directory
yuki-kimoto authored on 2009-11-16
218
    }
219
    
220
    return unless @$rows;
removed reconnect method
yuki-kimoto authored on 2010-05-28
221
    return $rows;
packaging one directory
yuki-kimoto authored on 2009-11-16
222
}
223

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

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

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

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

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

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

            
287
sub type_rule_on {
288
    my $self = shift;
289
    $self->{type_rule_off} = 0;
290
    return $self;
291
}
292

            
293
sub type_rule1_off {
294
    my $self = shift;
295
    $self->{type_rule1_off} = 1;
296
    return $self;
297
}
298

            
299
sub type_rule1_on {
300
    my $self = shift;
301
    $self->{type_rule1_off} = 0;
302
    return $self;
303
}
304

            
305
sub type_rule2_off {
306
    my $self = shift;
307
    $self->{type_rule2_off} = 1;
308
    return $self;
309
}
310

            
311
sub type_rule2_on {
312
    my $self = shift;
313
    $self->{type_rule2_off} = 0;
314
    return $self;
315
}
316

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

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

            
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
341
# DEPRECATED!
342
sub filter_off {
343
    warn "filter_off method is DEPRECATED!";
344
    my $self = shift;
345
    $self->{filter_off} = 1;
346
    return $self;
347
}
348

            
349
# DEPRECATED!
350
sub filter_on {
351
    warn "filter_on method is DEPRECATED!";
352
    my $self = shift;
353
    $self->{filter_off} = 0;
354
    return $self;
355
}
356

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

            
update document
yuki-kimoto authored on 2010-01-30
420
1;
421

            
packaging one directory
yuki-kimoto authored on 2009-11-16
422
=head1 NAME
423

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-15
431
    # Fetch a row and put it into array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
432
    while (my $row = $result->fetch) {
cleanup
yuki-kimoto authored on 2010-08-05
433
        my $author = $row->[0];
434
        my $title  = $row->[1];
version 0.0901
yuki-kimoto authored on 2009-12-17
435
    }
436
    
cleanup
Yuki Kimoto authored on 2011-06-15
437
    # Fetch only a first row and put it into array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
438
    my $row = $result->fetch_first;
439
    
cleanup
Yuki Kimoto authored on 2011-06-15
440
    # Fetch all rows and put them into array of array reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
441
    my $rows = $result->fetch_all;
cleanup
yuki-kimoto authored on 2010-08-05
442

            
cleanup
Yuki Kimoto authored on 2011-06-15
443
    # Fetch a row and put it into hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
444
    while (my $row = $result->fetch_hash) {
cleanup
yuki-kimoto authored on 2010-08-05
445
        my $title  = $row->{title};
446
        my $author = $row->{author};
packaging one directory
yuki-kimoto authored on 2009-11-16
447
    }
removed reconnect method
yuki-kimoto authored on 2010-05-28
448
    
cleanup
Yuki Kimoto authored on 2011-06-15
449
    # Fetch only a first row and put it into hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
450
    my $row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-06-15
451
    my $row = $result->one; # Same as fetch_hash_first
removed reconnect method
yuki-kimoto authored on 2010-05-28
452
    
cleanup
Yuki Kimoto authored on 2011-06-15
453
    # Fetch all rows and put them into array of hash reference
removed reconnect method
yuki-kimoto authored on 2010-05-28
454
    my $rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-06-15
455
    my $rows = $result->all; # Same as fetch_hash_all
packaging one directory
yuki-kimoto authored on 2009-11-16
456

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

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

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

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

            
466
=head2 C<sth>
467

            
468
    my $sth = $reuslt->sth
469
    $result = $result->sth($sth);
470

            
471
Statement handle of L<DBI>.
472

            
update document
yuki-kimoto authored on 2010-01-30
473
=head1 METHODS
474

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

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

            
480
    my $rows = $result->all;
481

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

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

            
486
    my $column = $result->column;
487

            
488
Get first column's all values.
489

            
490
    my $names = $dbi->select('name', table => 'book')->column;
491

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
555
Get header column names.
556

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

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

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

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

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

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

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

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

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

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

            
593
    $result = $result->type_rule_off;
594

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

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

            
600
    $result = $result->type_rule_on;
601

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

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

            
607
    $result = $result->type_rule1_off;
608

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

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

            
614
    $result = $result->type_rule1_on;
615

            
616
Turn C<from1> type rule on.
617
By default, type rule is on.
618

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

            
621
    $result = $result->type_rule2_off;
622

            
623
Turn C<from2> type rule off.
624
By default, type rule is on.
625

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

            
628
    $result = $result->type_rule2_on;
629

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

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

            
635
    my $value = $result->value;
636

            
637
Get first column's first value.
638

            
639
    my $count = $dbi->select('count(*)')->value;
640

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