DBIx::Custom::Result::kv method's multi option is DEPRE...
...CATED! added DBIx::Custom...
... | ... |
@@ -1,4 +1,7 @@ |
1 |
-0.27 (2012-09-17) |
|
1 |
+0.28 |
|
2 |
+ - DBIx::Custom::Result::kv method's multi option is DEPRECATED! |
|
3 |
+ added DBIx::Custom::Result::kvs method instead. |
|
4 |
+0.27 |
|
2 | 5 |
- fixed documentation miss about execute method's table_alias option. |
3 | 6 |
0.26 |
4 | 7 |
- fixed bug that when id option's value is object, don't work. |
... | ... |
@@ -2,7 +2,7 @@ use 5.008007; |
2 | 2 |
package DBIx::Custom; |
3 | 3 |
use Object::Simple -base; |
4 | 4 |
|
5 |
-our $VERSION = '0.27'; |
|
5 |
+our $VERSION = '0.28'; |
|
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
8 | 8 |
use DBI; |
... | ... |
@@ -256,6 +256,8 @@ sub kv { |
256 | 256 |
my $key_value = delete $row->{$key_name}; |
257 | 257 |
next unless defined $key_value; |
258 | 258 |
if ($opt{multi}) { |
259 |
+ _deprecate('0.28', "DBIx::Custom::Result::kv method's " |
|
260 |
+ . 'multi option is DEPRECATED. use kvs method instead'); |
|
259 | 261 |
$kv->{$key_value} ||= []; |
260 | 262 |
push @{$kv->{$key_value}}, $row; |
261 | 263 |
} |
... | ... |
@@ -265,6 +267,21 @@ sub kv { |
265 | 267 |
return $kv; |
266 | 268 |
} |
267 | 269 |
|
270 |
+sub kvs { |
|
271 |
+ my ($self, %opt) = @_; |
|
272 |
+ |
|
273 |
+ my $key_name = $self->{sth}{NAME}[0]; |
|
274 |
+ my $kv = {}; |
|
275 |
+ while (my $row = $self->fetch_hash) { |
|
276 |
+ my $key_value = delete $row->{$key_name}; |
|
277 |
+ next unless defined $key_value; |
|
278 |
+ $kv->{$key_value} ||= []; |
|
279 |
+ push @{$kv->{$key_value}}, $row; |
|
280 |
+ } |
|
281 |
+ |
|
282 |
+ return $kv; |
|
283 |
+} |
|
284 |
+ |
|
268 | 285 |
sub header { shift->sth->{NAME} } |
269 | 286 |
|
270 | 287 |
*one = \&fetch_hash_one; |
... | ... |
@@ -614,7 +631,6 @@ You can create key-value pair easily. |
614 | 631 |
=head2 C<kv> |
615 | 632 |
|
616 | 633 |
my $key_value = $result->kv; |
617 |
- my $key_values = $result->kv(multi => 1); |
|
618 | 634 |
|
619 | 635 |
Get key-value pairs. |
620 | 636 |
|
... | ... |
@@ -636,10 +652,13 @@ C<kv> method return the following data. |
636 | 652 |
|
637 | 653 |
First column value become key. |
638 | 654 |
|
639 |
-If value contains multipule data, you can push it to |
|
640 |
-array refernce by C<multi> option. |
|
655 |
+=head2 C<kvs> |
|
641 | 656 |
|
642 |
- my $books = $dbi->select(['author', 'title', 'price'])->kv(multi => 1); |
|
657 |
+ my $key_values = $result->kvs; |
|
658 |
+ |
|
659 |
+Get key-values pairs. |
|
660 |
+ |
|
661 |
+ my $books = $dbi->select(['author', 'title', 'price'])->kvs; |
|
643 | 662 |
|
644 | 663 |
If C<all> method return the following data: |
645 | 664 |
|
... | ... |
@@ -650,7 +669,7 @@ If C<all> method return the following data: |
650 | 669 |
{author => 'Taro', title => 'Sky', price => 4000} |
651 | 670 |
] |
652 | 671 |
|
653 |
-C<kv> method return the following data. |
|
672 |
+C<kvs> method return the following data. |
|
654 | 673 |
|
655 | 674 |
{ |
656 | 675 |
Ken => [ |
... | ... |
@@ -5,7 +5,7 @@ use Encode qw/encode_utf8/; |
5 | 5 |
use FindBin; |
6 | 6 |
use Scalar::Util 'isweak'; |
7 | 7 |
|
8 |
-$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25'; |
|
8 |
+$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.28'; |
|
9 | 9 |
|
10 | 10 |
my $dbi; |
11 | 11 |
|
... | ... |
@@ -3767,6 +3767,18 @@ is_deeply($rows, { |
3767 | 3767 |
] |
3768 | 3768 |
}); |
3769 | 3769 |
|
3770 |
+$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2"); |
|
3771 |
+$rows = $result->kvs; |
|
3772 |
+is_deeply($rows, { |
|
3773 |
+ 0 => [ |
|
3774 |
+ {$key2 => 1}, |
|
3775 |
+ {$key2 => 2} |
|
3776 |
+ ], |
|
3777 |
+ 3 => [ |
|
3778 |
+ {$key2 => 4}, |
|
3779 |
+ {$key2 => 5} |
|
3780 |
+ ] |
|
3781 |
+}); |
|
3770 | 3782 |
|
3771 | 3783 |
test 'DBIx::Custom::Result fetch_multi'; |
3772 | 3784 |
eval { $dbi->execute("drop table $table1") }; |