[Bast-commits] r9656 - SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Wed Aug 25 04:43:44 GMT 2010


Author: frew
Date: 2010-08-25 05:43:44 +0100 (Wed, 25 Aug 2010)
New Revision: 9656

Modified:
   SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Test.pm
Log:
small style changes

Modified: SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Test.pm
===================================================================
--- SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Test.pm	2010-08-25 04:18:25 UTC (rev 9655)
+++ SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Test.pm	2010-08-25 04:43:44 UTC (rev 9656)
@@ -40,12 +40,8 @@
   my $ret = $self->tb->ok($same_sql && $same_bind, $msg);
 
   # add debugging info
-  if (!$same_sql) {
-    $self->_sql_differ_diag($sql1, $sql2);
-  }
-  if (!$same_bind) {
-    $self->_bind_differ_diag($bind_ref1, $bind_ref2);
-  }
+  $self->_sql_differ_diag($sql1, $sql2)            unless $same_sql;
+  $self->_bind_differ_diag($bind_ref1, $bind_ref2) unless $same_bind;
 
   # pass ok() result further
   return $ret;
@@ -55,15 +51,13 @@
   my ($self, $sql1, $sql2, $msg) = @_;
 
   # compare
-  my $same_sql  = $self->eq_sql($sql1, $sql2);
+  my $same_sql = $self->eq_sql($sql1, $sql2);
 
   # call Test::Builder::ok
   my $ret = $self->tb->ok($same_sql, $msg);
 
   # add debugging info
-  if (!$same_sql) {
-    $self->_sql_differ_diag($sql1, $sql2);
-  }
+  $self->_sql_differ_diag($sql1, $sql2) unless $same_sql;
 
   # pass ok() result further
   return $ret;
@@ -79,9 +73,7 @@
   my $ret = $self->tb->ok($same_bind, $msg);
 
   # add debugging info
-  if (!$same_bind) {
-    $self->_bind_differ_diag($bind_ref1, $bind_ref2);
-  }
+  $self->_bind_differ_diag($bind_ref1, $bind_ref2) unless $same_bind;
 
   # pass ok() result further
   return $ret;
@@ -90,20 +82,23 @@
 sub _sql_differ_diag {
   my ($self, $sql1, $sql2) = @_;
 
-  $self->tb->diag("SQL expressions differ\n"
-      ."     got: $sql1\n"
-      ."expected: $sql2\n"
-      ."differing in :\n" . $self->sql_differ. "\n"
-      );
+   my $out = sprintf <<"END", $sql1, $sql2, $self->sql_differ;
+SQL expressions differ\n"
+     got: %s
+expected: %s
+differing in :
+%s
+END
+   $self->tb->diag($out);
 }
 
 sub _bind_differ_diag {
   my ($self, $bind_ref1, $bind_ref2) = @_;
 
-  $self->tb->diag("BIND values differ\n"
-      ."     got: " . Dumper($bind_ref1)
-      ."expected: " . Dumper($bind_ref2)
-      );
+  my $out = sprintf "BIND values differ\ngot: %s expected: %s",
+    Dumper($bind_ref1), Dumper($bind_ref2);
+
+  $self->tb->diag($out);
 }
 
 sub eq_sql_bind {
@@ -112,11 +107,10 @@
   return $self->eq_sql($sql1, $sql2) && $self->eq_bind($bind_ref1, $bind_ref2);
 }
 
-
 sub eq_bind {
   my ($self, $bind_ref1, $bind_ref2) = @_;
 
-  local $Data::Dumper::Useqq = 1;
+  local $Data::Dumper::Useqq    = 1;
   local $Data::Dumper::Sortkeys = 1;
 
   return Dumper($bind_ref1) eq Dumper($bind_ref2);
@@ -125,11 +119,7 @@
 sub eq_sql {
   my ($self, $sql1, $sql2) = @_;
 
-  # parse
-  my $tree1 = $self->parse($sql1);
-  my $tree2 = $self->parse($sql2);
-
-  return 1 if $self->_eq_sql($tree1, $tree2);
+  return !!$self->_eq_sql($self->parse($sql1), $self->parse($sql2));
 }
 
 sub _eq_sql {
@@ -145,7 +135,7 @@
   }
   # one is a list, the other is an op with a list
   elsif (ref $left->[0] xor ref $right->[0]) {
-    $self->sql_differ(sprintf ("left: %s\nright: %s\n", map { $self->unparse ($_) } ($left, $right) ));
+    $self->sql_differ(sprintf("left: %s\nright: %s\n", map $self->unparse($_), $left, $right ));
     return 0;
   }
   # one is a list, so is the other
@@ -159,7 +149,7 @@
   else {
 
     # unroll parenthesis if possible/allowed
-    $self->_parenthesis_unroll ($_) for ($left, $right);
+    $self->_parenthesis_unroll($_) for $left, $right;
 
     # if operators are different
     if ( $left->[0] ne $right->[0] ) {
@@ -175,13 +165,13 @@
       if ($left->[0] eq 'LITERAL' ) { # unary
         (my $l = " $left->[1][0] " ) =~ s/\s+/ /g;
         (my $r = " $right->[1][0] ") =~ s/\s+/ /g;
-        my $eq = $self->case_sensitive ? $l eq $r : uc($l) eq uc($r);
-        $self->sql_differ("[$l] != [$r]\n") if not $eq;
+        my $eq = $self->case_sensitive ? $l eq $r : uc $l eq uc $r;
+        $self->sql_differ("[$l] != [$r]\n") unless $eq;
         return $eq;
       }
       else {
         my $eq = $self->_eq_sql($left->[1], $right->[1]);
-        $self->sql_differ($self->sql_differ || sprintf ("left: %s\nright: %s\n", map { $self->unparse ($_) } ($left, $right) )) if not $eq;
+        $self->sql_differ($self->sql_differ || sprintf("left: %s\nright: %s\n", map $self->unparse($_), $left, $right )) unless $eq;
         return $eq;
       }
     }




More information about the Bast-commits mailing list