[Bps-public-commit] dbix-searchbuilder branch, functions-in-limit, updated. 1.59-37-g9d4a091

Ruslan Zakirov ruz at bestpractical.com
Tue May 24 16:08:48 EDT 2011


The branch, functions-in-limit has been updated
       via  9d4a091a915bebc8c3d85db551fa199ec9e64255 (commit)
       via  3e9db4c9528290aa5d6e28efe86e0e04b37a7964 (commit)
       via  dad82c4a0419158ba6231d0340d39094c03af3c1 (commit)
       via  de9bc76705921553d0deab4d8bde999b8b3dfc80 (commit)
       via  ae38d0a08a2b139bfa6da2c6f9cad7469afb0679 (commit)
       via  b12256b1c024b17a81d22889ee835481cf88fdac (commit)
       via  80a5d166d9345fe8d522ef4c34de35b753b8de9b (commit)
       via  6ba220d7f81c89501d173c38bace07a464b68926 (commit)
       via  8f7a6c320a08ad220b03c00480e5d866f66c2d49 (commit)
       via  0ef68d1e4979a2cfaffa3a9b067338474048e7bb (commit)
       via  f7bd7c2684c219deb5bc3e1d73f6881ddad3266f (commit)
       via  69891fddc9d0be1a5e65056efa0776c477a8b602 (commit)
       via  c8414546f9f4d23a59a72aaa04088230f178f543 (commit)
       via  32a174692fadf03e1aeb26581557717c5a21f52d (commit)
       via  53f8417d3d1b68c9413eab9529b6b5b3580af741 (commit)
       via  e5b690e3ca573babcad00f4db8848cab407c1e8b (commit)
       via  afab7b1a93a99cbcac4b76eedfda86b4a6c0ca09 (commit)
       via  f2be99197510953e0c6e139830b5b91bfaa3281d (commit)
       via  c5dab4ef7fc7195acb6c734a73032477a90b560e (commit)
       via  369c639473c45c7832ee5af87d78ba40b7d08cf2 (commit)
       via  e18ef0b670d6939db43973dc378873cf19f61d89 (commit)
      from  6016cffc94dd4f7a168cb6b74834f160d1ed680f (commit)

Summary of changes:
 Changes                          |    4 +
 lib/DBIx/SearchBuilder.pm        |  165 ++++++++++++++++++++++++++++----------
 lib/DBIx/SearchBuilder/Handle.pm |  111 ++++++++++++--------------
 3 files changed, 177 insertions(+), 103 deletions(-)

- Log -----------------------------------------------------------------
commit b12256b1c024b17a81d22889ee835481cf88fdac
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue May 24 17:02:07 2011 +0400

    indent

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index b1bf459..6504749 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -813,10 +813,9 @@ sub Limit {
     unless ( $args{'ENTRYAGGREGATOR'} ) {
         if ( $args{'LEFTJOIN'} ) {
             $args{'ENTRYAGGREGATOR'} = 'AND';
-            } else {
-
+        } else {
             $args{'ENTRYAGGREGATOR'} = 'OR';
-            }
+        }
     }
 
 

commit ae38d0a08a2b139bfa6da2c6f9cad7469afb0679
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue May 24 17:02:25 2011 +0400

    drop pointless comments

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 6504749..39d4a5f 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -891,7 +891,7 @@ sub _GenericRestriction {
         $args{'ALIAS'} = $args{'LEFTJOIN'};
     }
 
-    # {{{ if there's no alias set, we need to set it
+    # if there's no alias set, we need to set it
 
     unless ( $args{'ALIAS'} ) {
 
@@ -905,17 +905,12 @@ sub _GenericRestriction {
             $args{'ALIAS'} = 'main';
         }
 
-        # {{{ if we're joining, we need to work out the table alias
-
+        # if we're joining, we need to work out the table alias
         else {
             $args{'ALIAS'} = $self->NewAlias( $args{'TABLE'} );
         }
-
-        # }}}
     }
 
-    # }}}
-
     # Set this to the name of the field and the alias, unless we've been
     # handed a subclause name
 

commit de9bc76705921553d0deab4d8bde999b8b3dfc80
Merge: ae38d0a 80a5d16
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue May 24 23:07:19 2011 +0400

    Merge branch 'master' into functions-in-limit


commit dad82c4a0419158ba6231d0340d39094c03af3c1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue May 24 23:31:10 2011 +0400

    extract combining function with field into a method

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 36f89c8..d4ecb07 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -1569,26 +1569,8 @@ sub Column {
     $args{'ALIAS'} ||= 'main';
 
     my $name;
-    if ( $args{FIELD} && $args{FUNCTION} ) {
-        $name = $args{'ALIAS'} .'.'. $args{'FIELD'};
-
-        my $func = $args{FUNCTION};
-        if ( $func =~ /^DISTINCT\s*COUNT$/i ) {
-            $name = "COUNT(DISTINCT $name)";
-        }
-        # If we want to substitute 
-        elsif ($func =~ /\?/) {
-            $name = join($name,split(/\?/,$func));
-        }
-        # If we want to call a simple function on the column
-        elsif ($func !~ /\(/)  {
-            $name = "\U$func\E($name)";
-        } else {
-            $name = $func;
-        }
-    }
-    elsif ( $args{FUNCTION} ) {
-        $name = $args{FUNCTION};
+    if ( $args{FUNCTION} ) {
+        $name = $self->CombineFunctionWithField( %args );
     }
     elsif ( $args{FIELD} ) {
         $name = $args{'ALIAS'} .'.'. $args{'FIELD'};
@@ -1611,6 +1593,37 @@ sub Column {
     return $column;
 }
 
+sub CombineFunctionWithField {
+    my $self = shift;
+    my %args = (
+        FUNCTION => undef,
+        ALIAS    => undef,
+        FIELD    => undef,
+        @_
+    );
+
+    my $func = $args{'FUNCTION'};
+    return $func unless $args{'FIELD'};
+
+    my $field = ($args{'ALIAS'} || 'main') .'.'. $args{'FIELD'};
+
+    if ( $func =~ /^DISTINCT\s*COUNT$/i ) {
+        $func = "COUNT(DISTINCT $field)";
+    }
+
+    # If we want to substitute
+    elsif ( $func =~ s/\?/$field/g ) {
+        # no need to do anything, we already replaced
+    }
+
+    # If we want to call a simple function on the column
+    elsif ( $func !~ /\(/ )  {
+        $func = "\U$func\E($field)";
+    }
+
+    return $func;
+}
+
 
 
 

commit 3e9db4c9528290aa5d6e28efe86e0e04b37a7964
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue May 24 23:35:59 2011 +0400

    fix typo

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index d4ecb07..fa88211 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -835,7 +835,7 @@ sub Limit {
         }
         $args{'OPERATOR'} =~ s/(?:MATCHES|ENDSWITH|STARTSWITH)/LIKE/i;
 
-        if ( $args{'OPERATOR'} !~ /IS/i ) {
+        if ( $args{'OPERATOR'} =~ /IS/i ) {
             $args{'VALUE'} = 'NULL';
             $args{'QUOTEVALUE'} = 0;
         }

commit 9d4a091a915bebc8c3d85db551fa199ec9e64255
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue May 24 23:43:25 2011 +0400

    make it possible to pass FUNCTION into Limit method

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index fa88211..67ff120 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -798,9 +798,10 @@ sub Limit {
     my $self = shift;
     my %args = (
         TABLE           => $self->Table,
+        ALIAS           => undef,
         FIELD           => undef,
+        FUNCTION        => undef,
         VALUE           => undef,
-        ALIAS           => undef,
         QUOTEVALUE      => 1,
         ENTRYAGGREGATOR => undef,
         CASESENSITIVE   => undef,
@@ -871,6 +872,7 @@ sub _GenericRestriction {
     my $self = shift;
     my %args = ( TABLE           => $self->Table,
                  FIELD           => undef,
+                 FUNCTION        => undef,
                  VALUE           => undef,
                  ALIAS           => undef,
                  LEFTJOIN        => undef,
@@ -944,6 +946,10 @@ sub _GenericRestriction {
 
     }
 
+    if ( $args{'FUNCTION'} ) {
+        $QualifiedField = $self->CombineFunctionWithField( %args );
+    }
+
     my $clause = {
         field => $QualifiedField,
         op => $args{'OPERATOR'},

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list