[siesta-commit] siesta/lib/Siesta Preferences.pm,NONE,1.1 Plugin.pm,1.27,1.28 Storage.pm,1.19,1.20

[prev] [thread] [next] [lurker] [Date index for 2002/10/17]

From: muttley
Subject: [siesta-commit] siesta/lib/Siesta Preferences.pm,NONE,1.1 Plugin.pm,1.27,1.28 Storage.pm,1.19,1.20
Date: 12:52 on 17 Oct 2002
Update of /cvsroot/siesta/siesta/lib/Siesta
In directory usw-pr-cvs1:/tmp/cvs-serv10970/lib/Siesta

Modified Files:
	Plugin.pm Storage.pm 
Added Files:
	Preferences.pm 
Log Message:
Chnage to a new Preference based structure. This cleans up Storage 
and its derivatives. One less item on the todo list.


--- NEW FILE: Preferences.pm ---
# $Id: Preferences.pm,v 1.1 2002/10/17 11:52:18 muttley Exp $
package Siesta::Preferences;
use strict;
use Siesta::Storage;

=item ->preference ($namespace, $user_id, $list_id, $key, [$value])

Returns the value of key for the namespace based on the user and list.

Either or both of these can be undef.

The namespace will usually be the plugin name.

If you pass in a fifth argument as well then the value will be set to that.

This method attempts to work out the best value to look up for this tuple by searching,
in order : per user-per list, per user, per list, system default.

=cut



sub preference {

    my ( $namespace, $user_id, $list_id, $key, $value ) = @_;

    $user_id = UNIVERSAL::can( $user_id, 'id' ) ? $user_id->id : $user_id;
    $list_id = UNIVERSAL::can( $list_id, '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 _get( $namespace, $user_id, $list_id, $key )
    	unless defined $value;

    return Siesta->storage->set_preference( $namespace, $user_id, $list_id, $key, $value );


}

# work out the first valid config value
# the preferred order is
#
#         per user, per list
#                 |
#              per user
#                 |
#              per list
#                 |
#              default

sub _get {
    my ( $namespace, $user_id, $list_id, $key ) = @_;

    $user_id ||= '';
    $list_id ||= '';

    unless ( $user_id eq '' || $list_id eq '' ) {
        my $return =
         Siesta->storage->get_preference( $namespace, $user_id, $list_id, $key );
        return $return
          if defined $return;
    }

    unless ( $user_id eq '' ) {
        my $return =
          Siesta->storage->get_preference( $namespace, $user_id, '', $key );
        return $return
          if defined $return;
    }

    unless ( $list_id eq '' ) {
        my $return =
          Siesta->storage->get_preference( $namespace, '', $list_id, $key );
        return $return
          if defined $return;
    }

    return Siesta->storage->get_preference( $namespace, '', '', $key );
}

=item ->delete($namespace, $user_id, $list_id, $key

Deletes the value of key for the namespace based on the user and list.
     
Either or both of these can be undef.

The namespace will usually be the plugin name.

=cut

sub delete {

    Siesta->storage->delete_preference(@_);
}

1;

Index: Plugin.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Plugin.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- Plugin.pm	20 Sep 2002 20:32:05 -0000	1.27
+++ Plugin.pm	17 Oct 2002 11:52:18 -0000	1.28
@@ -3,6 +3,7 @@
 use strict;
 use Class::MethodMaker new => 'new';
 use Siesta;
+use Siesta::Preferences;
 
 =head1 NAME
 
@@ -27,7 +28,7 @@
 
 sub process { die "virtual" }
 
-=item ->config($message, $key, [$value])
+=item ->preference($message, $key, [$value])
 
 gets (or sets) the value of key for this plugin based on the
 list and user.
@@ -36,7 +37,7 @@
 
 =cut
 
-sub config {
+sub preference {
     my $self = shift;
     my $mail = shift;
 
@@ -45,16 +46,16 @@
     my $list_id = defined $mail->list ? $mail->list->id() : undef;
     my $user_id = defined $mail->user ? $mail->user->id() : undef;
 
-    return Siesta->storage->config( $package, $user_id, $list_id, @_ );
+    return Siesta::Preferences::preference( $package, $user_id, $list_id, @_ );
 }
 
-=item ->delete_config($message, $key)
+=item ->delete_preference($message, $key)
 
 Deletes this particular config value from the database.
 
 =cut
 
-sub delete_config {
+sub delete_preference {
 
     my $self = shift;
     my $mail = shift;
@@ -64,7 +65,7 @@
     my $list_id = defined $mail->list ? $mail->list->id() : undef;
     my $user_id = defined $mail->user ? $mail->user->id() : undef;
 
-    return Siesta->storage->delete_config( $package, $user_id, $list_id, @_ );
+    return Siesta::Preferences::delete ( $package, $user_id, $list_id, @_ );
 }
 
 =item ->options()

Index: Storage.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage.pm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- Storage.pm	17 Sep 2002 12:45:17 -0000	1.19
+++ Storage.pm	17 Oct 2002 11:52:18 -0000	1.20
@@ -31,13 +31,14 @@
 
 sub user_lists { die "virtual" }
 
-sub config { die "virtual" }
+sub get_preference { die "virtual" }
+sub set_preference { die "virtual" }
+sub delete_preference { die "virtual" }
 
 =item ->init_db ($db)
 
 Initialise a new database.
 
-
 =item ->load_user( $id )
 
 return a hash with a user in it, or nothing
@@ -111,19 +112,19 @@
 
 returns List objects for every list the user belongs to.
 
-=item ->config ($namespace, $user_id, $list_id, $key, [$value])
 
-Returns the value of key for the namespace based on the user and list.
+=item ->get_preference($namespace, $user_id, $list_id, $key)
 
-Either or both of these can be undef. 
+Get the value of the preference '$key' for this tuple.
 
-The namespace will usually be the plugin name.
+=item ->set_preference($namespace, $user_id, $list_id, $key, $value)
 
-If you pass in a fifth argument as well then the value will be set to that.
+Set the value of the preference '$key' to '$value'for this tuple.
 
-This method attempts to work out the best value to look up for this tuple by searching, 
-in order : per user-per list, per user, per list, system default.
+=item delete_preference($namespace, $user_id, $list_id, $key)
 
-=cut
+Delete the value of the preference '$key' for this tuple.
+
+=cut 
 
 1;



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