[siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.8,1.9

[prev] [thread] [next] [lurker] [Date index for 2002/09/07]

From: clampr
Subject: [siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.8,1.9
Date: 16:19 on 07 Sep 2002
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage
In directory usw-pr-cvs1:/tmp/cvs-serv4908

Modified Files:
	DBI.pm 
Log Message:
make ->dbh the private ->_dbh so we're not leaking over the edges


Index: DBI.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage/DBI.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- DBI.pm	6 Sep 2002 10:24:09 -0000	1.8
+++ DBI.pm	7 Sep 2002 15:19:52 -0000	1.9
@@ -5,13 +5,13 @@
 use base 'Siesta::Storage';
 
 use DBI;
-use Class::MethodMaker get_set => [ 'dbh' ];
+use Class::MethodMaker get_set => [ '_dbh' ];
 
 sub new {
     my $class = shift;
     my $dbh = DBI->connect(@_);
     return unless $dbh;
-    bless { dbh => $dbh }, $class;
+    bless { _dbh => $dbh }, $class;
 }
 
 
@@ -27,42 +27,42 @@
                    );
 
     $sql = join ('', $sql, 
-			" WHERE ", join(' AND ', 
+                        " WHERE ", join(' AND ', 
                                     map { "$_ = '$where{$_}'" } keys %where)
-		) if %where;
+                ) if %where;
 
 
     return map {
         my %foo;
         @foo{@columns} = @$_;
         \%foo;
-    }  @{ $self->dbh->selectall_arrayref($sql) };
+    }  @{ $self->_dbh->selectall_arrayref($sql) };
 }
 
 
 sub get_lists {
-	my $self = shift;
-	
-	return map { Siesta::List->new_from_hash($_) } 
-		$self->_get_rows(table   => 'lists',
-				 where   => {},
-				 columns => \@Siesta::List::fields);
+        my $self = shift;
+        
+        return map { Siesta::List->new_from_hash($_) } 
+                $self->_get_rows(table   => 'lists',
+                                 where   => {},
+                                 columns => \@Siesta::List::fields);
 }
 
 sub get_users {
-	my $self = shift;
-	
-	return map { Siesta::User->new_from_hash($_) }
-		$self->_get_rows(table   => 'users',
-				 where   => {},
-				 columns => \@Siesta::User::fields);
+        my $self = shift;
+        
+        return map { Siesta::User->new_from_hash($_) }
+                $self->_get_rows(table   => 'users',
+                                 where   => {},
+                                 columns => \@Siesta::User::fields);
 }
 
 sub get_lists_of_user
 {
-	my $self    = shift;
-	my $user_id = shift;
-  	# make sure we've got the id
+        my $self    = shift;
+        my $user_id = shift;
+        # make sure we've got the id
         $user_id = (ref ($user_id))? $user_id->id() : $user_id;
 
         my @returns;
@@ -71,7 +71,7 @@
         foreach my $list ($self->get_lists())
         {
                 push @returns, $list if 
-			($self->member_of_list($list->id(), $user_id));
+                        ($self->member_of_list($list->id(), $user_id));
         }
 
         return @returns;
@@ -100,45 +100,39 @@
     return unless defined $user;
 
     my @fields =  @Siesta::User::fields;
-	
+        
     my $sql;
-
     # if it already exists then we're updating 
     if (Siesta->storage->load_user($user->id())) {
-
-	$sql = join ( '', 
-			"UPDATE users SET ",
-			join (',', 
-				map { "$_=".$self->dbh->quote($user->$_()) } @fields
-			     ),
-			" WHERE id=", $self->dbh->quote($user->id())
-		    );
-
-    # inserting 
-    } else {
-   
-
-    	$sql    = join ( '',
-                        "INSERT INTO users (", join (',', @fields), ") ",
-                        "VALUES (", join( ',', map { $self->dbh->quote($user->$_()) } @fields) ,")"
-                  ) ;
-
+        $sql = join ( '', 
+                      "UPDATE users SET ",
+                      join (',', 
+                            map { "$_=".$self->_dbh->quote($user->$_()) } @fields
+                           ),
+                      " WHERE id=", $self->_dbh->quote($user->id())
+                    );
+    } 
+    else {
+        # inserting 
+        $sql    = join ( '',
+                         "INSERT INTO users (", join (',', @fields), ") ",
+                         "VALUES (", join( ',', map { $self->_dbh->quote($user->$_()) } @fields) ,")"
+                       ) ;
     }
 
-   return $self->dbh->do($sql)
-		or die $self->dbh->errstr;
-
+    return $self->_dbh->do($sql)
+      or die $self->_dbh->errstr;
 }
 
 
 sub delete_user {
-     my $self = shift;
-     my $user = shift;
+    my $self = shift;
+    my $user = shift;
 
-     $user = (ref $user)? $user->id : $user;
+    $user = (ref $user)? $user->id : $user;
 
-     return $self->dbh->do(qq{DELETE FROM users
-                             WHERE id = '$user'});	
+    return $self->_dbh->do(qq{DELETE FROM users
+                              WHERE id = '$user'});     
 }
 
 sub load_list {
@@ -159,51 +153,42 @@
 
     return unless defined $list;
 
-
     my @fields = @Siesta::List::fields;
-
     my $sql;
 
     # if it already exists then we're updating 
     if (Siesta->storage->load_list($list->id)) {
-
-	$sql = join ( '', 
-			"UPDATE lists SET ",
-			join (',', 
-				map { "$_=".$self->dbh->quote($list->$_()) } @fields
-			     ),
-			" WHERE id=", $self->dbh->quote($list->id())
-		    );
-
-    # inserting 
-    } else {
-   
-
-    	$sql    = join ( '',
-                        "INSERT INTO lists (", join (',', @fields), ") ",
-                        "VALUES (", join( ',', map { $self->dbh->quote($list->$_()) } @fields) ,")"
-                  ) ;
-
+        $sql = join( '', 
+                     "UPDATE lists SET ",
+                     join(',', 
+                           map { 
+                               "$_ = ".$self->_dbh->quote($list->$_()) 
+                           } @fields),
+                     " WHERE id=", $self->_dbh->quote($list->id())
+                   );
+    } 
+    else {
+        # inserting 
+        $sql = join( '',
+                     "INSERT INTO lists (", join (',', @fields), ") ",
+                     "VALUES (", join( ',', map { $self->_dbh->quote($list->$_()) } @fields) ,")"
+                   ) ;
     }
 
-   return $self->dbh->do($sql)
-		or die $self->dbh->errstr;
-
-
-
-
+    return $self->_dbh->do($sql)
+      or die $self->_dbh->errstr;
 }
 
 
 sub delete_list {
-     my $self = shift;
-     my $list = shift;
+    my $self = shift;
+    my $list = shift;
 
-     # make sure we've got the id 
-     $list = (ref $list)? $list->id : $list;
+    # make sure we've got the id 
+    $list = (ref $list)? $list->id : $list;
 
-     return $self->dbh->do(qq{DELETE FROM lists
-                             WHERE id = '$list'});
+    return $self->_dbh->do(qq{DELETE FROM lists
+                              WHERE id = '$list'});
 }
 
 
@@ -226,9 +211,9 @@
     my $list = shift;
     my $user = shift;
 
-    $self->dbh->do(qq{INSERT INTO list_users (list_id, user_id)
-                      VALUES ('$list', '$user')})
-      or die $self->dbh->errstr;
+    $self->_dbh->do(qq{INSERT INTO list_users (list_id, user_id)
+                       VALUES ('$list', '$user')})
+      or die $self->_dbh->errstr;
     return 1;
 }
 
@@ -238,8 +223,8 @@
     my $list = shift;
     my $user = shift;
 
-    return $self->dbh->do(qq{DELETE FROM list_users
-                             WHERE list_id = '$list' AND user_id = '$user'});
+    return $self->_dbh->do(qq{DELETE FROM list_users
+                              WHERE list_id = '$list' AND user_id = '$user'});
 }
 
 
@@ -269,14 +254,15 @@
 
 
 sub user_lists {
-	my $self = shift;
-	my $user = shift;
-	
-	my @fields = qw( list_id );
-	my @results = $self->_get_rows(table   => 'list_users',
-				       where   => { user_id => $user },
-				       columns => \@fields);
-	
-	return map { Siesta::List->new($_->{list_id}) } @results;
+    my $self = shift;
+    my $user = shift;
+
+    my @fields = qw( list_id );
+    my @results = $self->_get_rows(table   => 'list_users',
+                                   where   => { user_id => $user },
+                                   columns => \@fields);
+
+    return map { Siesta::List->new($_->{list_id}) } @results;
 }
+
 1;



Generated at 13:57 on 01 Jul 2004 by mariachi 0.52