[Bast-commits] r6393 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t/count

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sat May 23 22:50:08 GMT 2009


Author: ribasushi
Date: 2009-05-23 22:50:08 +0000 (Sat, 23 May 2009)
New Revision: 6393

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm
   DBIx-Class/0.08/trunk/t/count/distinct.t
Log:
Extend distinct deprecation tests and clarify warnings

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-05-23 22:47:40 UTC (rev 6392)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-05-23 22:50:08 UTC (rev 6393)
@@ -856,10 +856,10 @@
 
 sub search_like {
   my $class = shift;
-  carp join ("\n",
-    'search_like() is deprecated and will be removed in 0.09.',
-    'Instead use ->search({ x => { -like => "y%" } })',
-    '(note the outer pair of {}s - they are important!)'
+  carp (
+    'search_like() is deprecated and will be removed in DBIC version 0.09.'
+   .' Instead use ->search({ x => { -like => "y%" } })'
+   .' (note the outer pair of {}s - they are important!)'
   );
   my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
   my $query = ref $_[0] eq 'HASH' ? { %{shift()} }: {@_};

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm	2009-05-23 22:47:40 UTC (rev 6392)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm	2009-05-23 22:50:08 UTC (rev 6393)
@@ -193,20 +193,20 @@
       if ($func eq 'distinct') {
         my $_fields = $fields->{$func};
         if (ref $_fields eq 'ARRAY' && @{$_fields} > 1) {
-          croak "Unsupported syntax, please use " . 
-              "{ group_by => [ qw/" . (join ' ', @$_fields) . "/ ] }" .
-              " or " .
-              "{ select => [ qw/" . (join ' ', @$_fields) . "/ ], distinct => 1 }";
+          croak (
+            'The select => { distinct => ... } syntax is not supported for multiple columns.'
+           .' Instead please use { group_by => [ qw/' . (join ' ', @$_fields) . '/ ] }'
+           .' or { select => [ qw/' . (join ' ', @$_fields) . '/ ], distinct => 1 }'
+          );
         }
         else {
           $_fields = @{$_fields}[0] if ref $_fields eq 'ARRAY';
-          carp "This syntax will be deprecated in 09, please use " . 
-               "{ group_by => '${_fields}' }" . 
-               " or " .
-               "{ select => '${_fields}', distinct => 1 }";
+          carp (
+            'The select => { distinct => ... } syntax will be deprecated in DBIC version 0.09,'
+           ." please use { group_by => '${_fields}' } or { select => '${_fields}', distinct => 1 }"
+          );
         }
       }
-      
       return $self->_sqlcase($func)
         .'( '.$self->_recurse_fields($fields->{$func}).' )';
     }

Modified: DBIx-Class/0.08/trunk/t/count/distinct.t
===================================================================
--- DBIx-Class/0.08/trunk/t/count/distinct.t	2009-05-23 22:47:40 UTC (rev 6392)
+++ DBIx-Class/0.08/trunk/t/count/distinct.t	2009-05-23 22:50:08 UTC (rev 6393)
@@ -77,14 +77,23 @@
 $rs = $schema->resultset('Tag')->search({}, { select => 'length(me.tag)', distinct => 1 });
 is($rs->count, 3, 'Count by distinct function result as select literal');
 
-my @warnings;
-{
-  local $SIG{__WARN__} = sub { push @warnings, shift };
+eval {
+  my @warnings;
+  local $SIG{__WARN__} = sub { $_[0] =~ /The select => { distinct => ... } syntax will be deprecated/ 
+    ? push @warnings, @_
+    : warn @_
+  };
   my $row = $schema->resultset('Tag')->search({}, { select => { distinct => 'tag' } })->first;
-}
+  is (@warnings, 1, 'Warned about deprecated distinct') if $DBIx::Class::VERSION < 0.09;
+};
+ok ($@, 'Exception on deprecated distinct usage thrown') if $DBIx::Class::VERSION >= 0.09;
 
-is(@warnings, 1, 'expecteing warn');
+throws_ok(
+  sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first },
+  qr/select => { distinct => ... } syntax is not supported for multiple columns/,
+  'throw on unsupported syntax'
+);
 
-dies_ok(sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first }, 'expecting to die');
+# These two rely on the database to throw an exception. This might not be the case one day. Please revise.
 dies_ok(sub { my $count = $schema->resultset('Tag')->search({}, { '+select' => \'tagid AS tag_id', distinct => 1 })->count }, 'expecting to die');
 dies_ok(sub { my $count = $schema->resultset('Tag')->search({}, { select => { length => 'tag' }, distinct => 1 })->count }, 'expecting to die');




More information about the Bast-commits mailing list