[Bast-commits] r3794 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class t

bricas at dev.catalyst.perl.org bricas at dev.catalyst.perl.org
Thu Sep 27 19:37:15 GMT 2007


Author: bricas
Date: 2007-09-27 19:37:15 +0100 (Thu, 27 Sep 2007)
New Revision: 3794

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
   DBIx-Class/0.08/trunk/t/88result_set_column.t
Log:
ResultSetColumn::func() now returns all results if called in list context

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2007-09-26 21:33:52 UTC (rev 3793)
+++ DBIx-Class/0.08/trunk/Changes	2007-09-27 18:37:15 UTC (rev 3794)
@@ -2,6 +2,8 @@
 
         - When adding relationships, it will throw an exception if you get the
           foreign and self parts the wrong way round in the condition
+        - ResultSetColumn::func() now returns all results if called in list
+          context; this makes things like func('DISTINCT') work as expected
 
 0.08007 2007-09-04 19:36:00
         - patch for Oracle datetime inflation (abram at arin.net)

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm	2007-09-26 21:33:52 UTC (rev 3793)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm	2007-09-27 18:37:15 UTC (rev 3794)
@@ -175,8 +175,13 @@
 
 sub func {
   my ($self,$function) = @_;
-  my ($row) = $self->{_parent_resultset}->search(undef, {select => {$function => $self->{_column}}, as => [$self->{_column}]})->cursor->next;
-  return $row;
+  my $cursor = $self->{_parent_resultset}->search(undef, {select => {$function => $self->{_column}}, as => [$self->{_column}]})->cursor;
+  
+  if( wantarray ) {
+    return map { $_->[ 0 ] } $cursor->all;
+  }
+
+  return ( $cursor->next )[ 0 ];
 }
 
 1;

Modified: DBIx-Class/0.08/trunk/t/88result_set_column.t
===================================================================
--- DBIx-Class/0.08/trunk/t/88result_set_column.t	2007-09-26 21:33:52 UTC (rev 3793)
+++ DBIx-Class/0.08/trunk/t/88result_set_column.t	2007-09-27 18:37:15 UTC (rev 3794)
@@ -7,7 +7,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 9; 
+plan tests => 10; 
 
 my $cd;
 my $rs = $cd = $schema->resultset("CD")->search({});
@@ -17,6 +17,8 @@
 
 is($rs_title->next, 'Spoonful of bees', "next okay");
 
+is_deeply( [ sort $rs_year->func('DISTINCT') ], [ 1997, 1998, 1999, 2001 ],  "wantarray context okay");
+
 my @all = $rs_title->all;
 cmp_ok(scalar @all, '==', 5, "five titles returned");
 




More information about the Bast-commits mailing list