[Bps-public-commit] dbix-searchbuilder branch, refactor-connecting, created. 1.59-12-gf2be991

Ruslan Zakirov ruz at bestpractical.com
Fri May 20 06:57:16 EDT 2011


The branch, refactor-connecting has been created
        at  f2be99197510953e0c6e139830b5b91bfaa3281d (commit)

- Log -----------------------------------------------------------------
commit e18ef0b670d6939db43973dc378873cf19f61d89
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jan 12 13:12:12 2011 +0300

    refactor connect, indent and a few tiny cleanups

diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index 96acb07..b1b7aa8 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -72,51 +72,46 @@ the handle will be automatically "upgraded" into that subclass.
 =cut
 
 sub Connect  {
-  my $self = shift;
-  
-  my %args = ( Driver => undef,
-	       Database => undef,
-	       Host => undef,
-           SID => undef,
-	       Port => undef,
-	       User => undef,
-	       Password => undef,
-	       RequireSSL => undef,
-           DisconnectHandleOnDestroy => undef,
-	       @_);
-
-   if( $args{'Driver'} && !$self->isa( 'DBIx::SearchBuilder::Handle::'. $args{'Driver'} ) ) {
-      if ( $self->_UpgradeHandle($args{Driver}) ) {
-          return ($self->Connect( %args ));
-      }
-   }
-
-
-    my $dsn = $self->DSN || '';
+    my $self = shift;
+    my %args = (
+        Driver => undef,
+	Database => undef,
+	Host => undef,
+        SID => undef,
+	Port => undef,
+	User => undef,
+	Password => undef,
+	RequireSSL => undef,
+        DisconnectHandleOnDestroy => undef,
+	@_
+    );
 
-    # Setting this actually breaks old RT versions in subtle ways. So we need to explicitly call it
+    if ( $args{'Driver'} && !$self->isa( __PACKAGE__ .'::'. $args{'Driver'} ) ) {
+        return $self->Connect( %args ) if $self->_UpgradeHandle( $args{'Driver'} );
+    }
 
+    # Setting this actually breaks old RT versions in subtle ways.
+    # So we need to explicitly call it
     $self->{'DisconnectHandleOnDestroy'} = $args{'DisconnectHandleOnDestroy'};
-    
 
-  $self->BuildDSN(%args);
+    my $old_dsn = $self->DSN || '';
+    my $new_dsn = $self->BuildDSN( %args );
 
     # Only connect if we're not connected to this source already
-   if ((! $self->dbh ) || (!$self->dbh->ping) || ($self->DSN ne $dsn) ) { 
-     my $handle = DBI->connect($self->DSN, $args{'User'}, $args{'Password'}) || croak "Connect Failed $DBI::errstr\n" ;
- 
-  #databases do case conversion on the name of columns returned. 
-  #actually, some databases just ignore case. this smashes it to something consistent 
-  $handle->{FetchHashKeyName} ='NAME_lc';
+    return undef if $self->dbh && $self->dbh->ping && $new_dsn ne $old_dsn;
 
-  #Set the handle 
-  $self->dbh($handle);
-  
-  return (1); 
-    }
+    my $handle = DBI->connect(
+        $new_dsn, $args{'User'}, $args{'Password'}
+    ) or croak "Connect Failed $DBI::errstr\n";
 
-    return(undef);
+    # databases do case conversion on the name of columns returned.
+    # actually, some databases just ignore case. this smashes it to something consistent
+    $handle->{FetchHashKeyName} ='NAME_lc';
 
+    # Set the handle
+    $self->dbh($handle);
+
+    return 1;
 }
 
 

commit 369c639473c45c7832ee5af87d78ba40b7d08cf2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jan 12 13:16:27 2011 +0300

    refactor BuildDSN
    
    * indent
    * if (defined $x && $x) === if ($x)
    * explicit return

diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index b1b7aa8..a06eb89 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -136,8 +136,6 @@ sub _UpgradeHandle {
 }
 
 
-
-
 =head2 BuildDSN PARAMHASH
 
 Takes a bunch of parameters:  
@@ -151,24 +149,24 @@ Builds a DSN suitable for a DBI connection
 
 sub BuildDSN {
     my $self = shift;
-  my %args = ( Driver => undef,
-	       Database => undef,
-	       Host => undef,
-	       Port => undef,
-           SID => undef,
-	       RequireSSL => undef,
-	       @_);
-  
-  
-  my $dsn = "dbi:$args{'Driver'}:dbname=$args{'Database'}";
-  $dsn .= ";sid=$args{'SID'}" if ( defined $args{'SID'} && $args{'SID'});
-  $dsn .= ";host=$args{'Host'}" if (defined$args{'Host'} && $args{'Host'});
-  $dsn .= ";port=$args{'Port'}" if (defined $args{'Port'} && $args{'Port'});
-  $dsn .= ";requiressl=1" if (defined $args{'RequireSSL'} && $args{'RequireSSL'});
+    my %args = (
+        Driver     => undef,
+        Database   => undef,
+        Host       => undef,
+        Port       => undef,
+        SID        => undef,
+        RequireSSL => undef,
+        @_
+    );
 
-  $self->{'dsn'}= $dsn;
-}
+    my $dsn = "dbi:$args{'Driver'}:dbname=$args{'Database'}";
+    $dsn .= ";sid=$args{'SID'}"   if $args{'SID'};
+    $dsn .= ";host=$args{'Host'}" if $args{'Host'};
+    $dsn .= ";port=$args{'Port'}" if $args{'Port'};
+    $dsn .= ";requiressl=1"       if $args{'RequireSSL'};
 
+    return $self->{'dsn'} = $dsn;
+}
 
 
 =head2 DSN

commit c5dab4ef7fc7195acb6c734a73032477a90b560e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jan 12 13:19:39 2011 +0300

    retab and doc fixes

diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index a06eb89..de253ce 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -75,15 +75,15 @@ sub Connect  {
     my $self = shift;
     my %args = (
         Driver => undef,
-	Database => undef,
-	Host => undef,
+        Database => undef,
+        Host => undef,
         SID => undef,
-	Port => undef,
-	User => undef,
-	Password => undef,
-	RequireSSL => undef,
+        Port => undef,
+        User => undef,
+        Password => undef,
+        RequireSSL => undef,
         DisconnectHandleOnDestroy => undef,
-	@_
+        @_
     );
 
     if ( $args{'Driver'} && !$self->isa( __PACKAGE__ .'::'. $args{'Driver'} ) ) {
@@ -171,7 +171,7 @@ sub BuildDSN {
 
 =head2 DSN
 
-    Returns the DSN for this database connection.
+Returns the DSN for this database connection.
 
 =cut
 
@@ -236,7 +236,7 @@ sub LogSQLStatements {
 
 =head2 _LogSQLStatement STATEMENT DURATION
 
-add an SQL statement to our query log
+Add an SQL statement to our query log
 
 =cut
 

commit f2be99197510953e0c6e139830b5b91bfaa3281d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri May 20 14:01:11 2011 +0400

    fix logic we broke during refactoring
    
    return if old and new DSNs are equal

diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index de253ce..3b699eb 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -98,7 +98,7 @@ sub Connect  {
     my $new_dsn = $self->BuildDSN( %args );
 
     # Only connect if we're not connected to this source already
-    return undef if $self->dbh && $self->dbh->ping && $new_dsn ne $old_dsn;
+    return undef if $self->dbh && $self->dbh->ping && $new_dsn eq $old_dsn;
 
     my $handle = DBI->connect(
         $new_dsn, $args{'User'}, $args{'Password'}

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



More information about the Bps-public-commit mailing list