[siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.11,1.12

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

From: clampr
Subject: [siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.11,1.12
Date: 15:13 on 08 Sep 2002
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage
In directory usw-pr-cvs1:/tmp/cvs-serv3077

Modified Files:
	DBI.pm 
Log Message:
layout/dumbness fixes


Index: DBI.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage/DBI.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- DBI.pm	8 Sep 2002 12:03:59 -0000	1.11
+++ DBI.pm	8 Sep 2002 14:13:36 -0000	1.12
@@ -41,41 +41,37 @@
 
 
 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;
+    my $self = shift;
         
-        return map { Siesta::User->new_from_hash($_) }
-                $self->_get_rows(table   => 'users',
-                                 where   => {},
-                                 columns => \@Siesta::User::fields);
+    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
-        $user_id = (ref ($user_id))? $user_id->id() : $user_id;
-
-        my @returns;
-
+sub get_lists_of_user {
+    my $self    = shift;
+    my $user_id = shift;
+    # make sure we've got the id
+    $user_id = (ref ($user_id))? $user_id->id() : $user_id;
 
-        foreach my $list ($self->get_lists())
-        {
-                push @returns, $list if 
-                        ($self->member_of_list($list->id(), $user_id));
-        }
+    my @returns;
 
-        return @returns;
+    foreach my $list ($self->get_lists()) {
+        push @returns, $list
+          if $self->member_of_list($list->id(), $user_id);
+    }
 
+    return @returns;
 }
 
 sub load_user {
@@ -83,8 +79,6 @@
     my $user = shift;
 
     my @fields =  @Siesta::User::fields;
-
-
     my @results = $self->_get_rows(table   => 'users',
                                    where   => { id => $user },
                                    columns => \@fields);
@@ -100,20 +94,19 @@
     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 ( '', 
+        $sql = join ( '',
                       "UPDATE users SET ",
-                      join (',', 
+                      join (',',
                             map { "$_=".$self->_dbh->quote($user->$_()) } @fields
                            ),
                       " WHERE id=", $self->_dbh->quote($user->id())
                     );
-    } 
+    }
     else {
-        # inserting 
+        # inserting
         $sql    = join ( '',
                          "INSERT INTO users (", join (',', @fields), ") ",
                          "VALUES (", join( ',', map { $self->_dbh->quote($user->$_()) } @fields) ,")"
@@ -132,7 +125,7 @@
     $user = (ref $user)? $user->id : $user;
 
     return $self->_dbh->do(qq{DELETE FROM users
-                              WHERE id = '$user'});     
+                              WHERE id = '$user'});
 }
 
 sub load_list {
@@ -147,6 +140,7 @@
     return %{ $results[0] };
 }
 
+
 sub save_list {
     my $self = shift;
     my $list = shift;
@@ -265,75 +259,56 @@
     return map { Siesta::List->new($_->{list_id}) } @results;
 }
 
-sub config
-{
-	my $self = shift;
-
-
-
-	my ($namespace, $user_id, $list_id, $key, $value) = @_;
-
-	# make sure that we get the id and not the object
-	if (defined $user_id) {
-		$user_id = (ref $user_id)?$user_id->id():$user_id;
-	}
-
-
-	# make sure that we get the id and not the object
-	if (defined $list_id) {
-		$list_id = (ref $list_id)?$list_id->id():$list_id;
-	}
-
-	# make suyre they're not undef
-	$user_id ||= '';
-	$list_id ||= '';
-
-
-	# if we haven't been passed a value then fetch and return it
-	return $self->get_config($namespace, $user_id, $list_id, $key) 
-				if (!defined $value);	
-
+sub config {
+    my $self = shift;
 
-	
+    my ($namespace, $user_id, $list_id, $key, $value) = @_;
 
+    $user_id = ref $user_id ? $user_id->id : $user_id;
+    $list_id = ref $list_id ? $list_id->id : $list_id;
 
-	# otherwise we need to check to see if it's been defined 
-	# explicitly for this particular tuple and update or insert
-	# appropriately.
+    # make suyre they're not undef
+    $user_id ||= '';
+    $list_id ||= '';
 
-	my $return = $self->get_config_explicitly($namespace, $user_id, $list_id, $key);
+    # if we haven't been passed a value then fetch and return it
+    return $self->get_config($namespace, $user_id, $list_id, $key)
+      unless defined $value;
 
-	my $sql;
-	# are we updating 
-	if (defined $return) {
-		$sql = sprintf "UPDATE config set value=%s where
-				namespace=%s AND user_id=%s AND
-				list_id=%s AND key=%s",
-				$self->_dbh->quote($value), 
-				$self->_dbh->quote($namespace), 
-				$self->_dbh->quote($user_id), 
-				$self->_dbh->quote($list_id), 
-				$self->_dbh->quote($key);
+    # otherwise we need to check to see if it's been defined 
+    # explicitly for this particular tuple and update or insert
+    # appropriately.
 
-	# ... or inserting
-	} else {
-		$sql = sprintf "INSERT INTO config 
-				(namespace, user_id, list_id, key, value) 
-				VALUES (%s, %s, %s, %s, %s)",
-				$self->_dbh->quote($namespace), 
-				$self->_dbh->quote($user_id), 
-				$self->_dbh->quote($list_id), 
-				$self->_dbh->quote($key), 
-				$self->_dbh->quote($value);
-	}
-	
-	
-	return $self->_dbh->do($sql) 
-		or die $self->_dbh->errstr;
+    my $return = $self->get_config_explicitly($namespace, $user_id, $list_id, $key);
 
-	
-	
+    my $sql;
+    # are we updating 
+    if (defined $return) {
+        $sql = sprintf( "UPDATE config set value=%s where
+                        namespace=%s AND user_id=%s AND
+                        list_id=%s AND key=%s",
+                        $self->_dbh->quote($value),
+                        $self->_dbh->quote($namespace),
+                        $self->_dbh->quote($user_id),
+                        $self->_dbh->quote($list_id),
+                        $self->_dbh->quote($key),
+                      );
+    }
+    else {
+        # ... or inserting
+        $sql = sprintf( "INSERT INTO config 
+                        (namespace, user_id, list_id, key, value) 
+                        VALUES (%s, %s, %s, %s, %s)",
+                        $self->_dbh->quote($namespace), 
+                        $self->_dbh->quote($user_id), 
+                        $self->_dbh->quote($list_id), 
+                        $self->_dbh->quote($key), 
+                        $self->_dbh->quote($value)
+                      );
+    }
 
+    return $self->_dbh->do($sql)
+      or die $self->_dbh->errstr;
 }
 
 # work out the first valid config value
@@ -341,60 +316,55 @@
 #
 #         per user, per list
 #                 |
-#              per user        
+#              per user
 #                 |
 #              per listÅ
 #                 |
 #           system default
 #
-sub get_config
-{
-	my ($self, $namespace, $user_id, $list_id, $key) = @_;
 
-	unless (($user_id eq '')  || ($list_id eq ''))
-	{
-		my $return = $self->get_config_explicitly($namespace, $user_id, $list_id, $key);
-		return $return if defined $return;
-	}	
+sub get_config {
+    my ($self, $namespace, $user_id, $list_id, $key) = @_;
 
-	unless ($user_id eq '')
-	{
-		my $return = $self->get_config_explicitly($namespace, '', $list_id, $key);
-		return $return if defined $return;
-	}	
+    unless (($user_id eq '')  || ($list_id eq '')) {
+        my $return = $self->get_config_explicitly($namespace, $user_id, $list_id, $key);
+        return $return
+          if defined $return;
+    }   
 
-	unless ($list_id eq '')
-	{
-		my $return = $self->get_config_explicitly($namespace, $user_id, '', $key);
-		return $return if defined $return;
-	}	
+    unless ($user_id eq '') {
+        my $return = $self->get_config_explicitly($namespace, '', $list_id, $key);
+        return $return 
+          if defined $return;
+    }   
 
-	return $self->get_config_explicitly($namespace, '', '', $key);
+    unless ($list_id eq '') {
+        my $return = $self->get_config_explicitly($namespace, $user_id, '', $key);
+        return $return
+          if defined $return;
+    }   
 
-	
+    return $self->get_config_explicitly($namespace, '', '', $key);
 }
 
 
 # explicitly look up a config value for a given
 # namespace, user, list, key tuple. 
-sub get_config_explicitly
-{
-	my ($self, $namespace, $user_id, $list_id, $key) = @_;
-
-	# just to be sure
-	$user_id ||= '';
-	$list_id ||= '';
-	
-	my @results = $self->_get_rows(table  => 'config',
-				 	where  => { user_id   => $user_id,
-					            list_id   => $list_id,
-				                    key       => $key,
-					            namespace => $namespace },
-				        columns => ['value']);
+sub get_config_explicitly {
+    my ($self, $namespace, $user_id, $list_id, $key) = @_;
 
-	return $results[0]->{value};		
+    # just to be sure
+    $user_id ||= '';
+    $list_id ||= '';
 
+    my @results = $self->_get_rows(table  => 'config',
+                                   where  => { user_id   => $user_id,
+                                               list_id   => $list_id,
+                                               key       => $key,
+                                               namespace => $namespace },
+                                   columns => ['value']);
 
+    return $results[0]->{value};
 }
 
 1;



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