Bric::Util::UserPref(3)

NAME
Bric::Util::UserPref - Interface to Bricolage per-user preferences.

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2004-07-07 23:39:24 -0700 (Wed, 07 Jul 2004) $

SYNOPSIS
  use Bric::Util::UserPref;

  # Constructors.
  my $user_pref = Bric::Util::UserPref->new($init);
  $user_pref = Bric::Util::UserPref->lookup({ id => $id });
  $user_pref = Bric::Util::UserPref->lookup({ name => $name });
  my @prefs = Bric::Util::UserPref->list($params);

  # Class Methods.
  my @pref_ids = Bric::Util::UserPref->list_ids($params);
  my $meths = Bric::Util::UserPref->my_meths;
  my @meths = Bric::Util::UserPref->my_meths(1);

  # Instance Methods
  my $pref_id = $user_pref->get_pref_id;
  my $name = $user_pref->get_name;
  my $desc = $user_pref->get_description;
  my $default = $user_pref->get_default;
  my $opt_type = $user_pref->get_opt_type;
  my $val_name = $user_pref->get_val_name;

  # Get a list of available value options.
  my @opts = $user_pref->get_opts;
  my $opts_ref = $user_pref->get_opts_href;

  # Get the associated Bric::Util::Pref object
  my $pref = $user_pref->get_pref;

  # Get and set the value.
  my $value = $user_pref->get_value;
  $user_pref = $user_pref->set_value($value);

  # Save the pref.
  $user_pref = $user_pref->save;

DESCRIPTION
This module provides a class for representing per-user preferences. This allows each user to override values for preferences like language or character set.

INTERFACE

  Constructors

my $user_pref = Bric::Util::Pref->lookup({ id => $id })
my $user_pref = Bric::Util::Pref->lookup({ name => $name })
    Looks up and instantiates a new Bric::Util::Pref object based on the Bric::Util::Pref object ID or name passed. If $id or $name is not found in the database, lookup() returns undef.

    Throws:

    *   Too many Bric::Dist::Util::Pref objects found.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to connect to database.

    *   Unable to select column into arrayref.

    *   Unable to execute SQL statement.

    *   Unable to bind to columns to statement handle.

    *   Unable to fetch row from statement handle.

    Side Effects: If $id is found, populates the new Bric::Util::Pref object with data from the database before returning it.

    Notes: NONE.

my (@prefs || $user_prefs_aref) = Bric::Util::Pref->list($params)
    Returns a list or anonymous array of Bric::Util::Pref objects based on the search parameters passed via an anonymous hash. The supported lookup keys are:

    *   id

    *   pref_id

    *   user_id

    *   description

    *   default

    *   value

    *   val_name

    *   manual

    *   opt_type

    *   grp_id

    Throws:

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to connect to database.

    *   Unable to select column into arrayref.

    *   Unable to execute SQL statement.

    *   Unable to bind to columns to statement handle.

    *   Unable to fetch row from statement handle.

    Side Effects: Populates each Bric::Util::Pref object with data from the database before returning them all.

    Notes: NONE.

  Destructors

$user_pref->DESTROY
    Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Class Methods

$meths = Bric::Util::Pref->my_meths
(@meths || $meths_aref) = Bric::Util::Pref->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Util::Pref->my_meths(0, TRUE)
    Returns an anonymous hash of introspection data for this object. If called with a true argument, it will return an ordered list or anonymous array of introspection data. If a second true argument is passed instead of a first, then a list or anonymous array of introspection data will be returned for properties that uniquely identify an object (excluding "id", which is assumed).

    Each hash key is the name of a property or attribute of the object. The value for a hash key is another anonymous hash containing the following keys:

    name
        The name of the property or attribute. Is the same as the hash key when an anonymous hash is returned.

    disp
        The display name of the property or attribute.

    get_meth
        A reference to the method that will retrieve the value of the property or attribute.

    get_args
        An anonymous array of arguments to pass to a call to get_meth in order to retrieve the value of the property or attribute.

    set_meth
        A reference to the method that will set the value of the property or attribute.

    set_args
        An anonymous array of arguments to pass to a call to set_meth in order to set the value of the property or attribute.

    type
        The type of value the property or attribute contains. There are only three types:

        short
        date
        blob
    len If the value is a 'short' value, this hash key contains the length of the field.

    search
        The property is searchable via the list() and list_ids() methods.

    req The property or attribute is required.

    props
        An anonymous hash of properties used to display the property or attribute. Possible keys include:

        type
            The display field type. Possible values are

            text
            textarea
            password
            hidden
            radio
            checkbox
            select
        length
            The Length, in letters, to display a text or password field.

        maxlength
            The maximum length of the property or value - usually defined by the SQL DDL.

    rows
        The number of rows to format in a textarea field.

    cols
        The number of columns to format in a textarea field.

    vals
        An anonymous hash of key/value pairs reprsenting the values and display names to use in a select list.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Instance Methods

my $id = $user_pref->get_pref_id
    Returns the ID of the Bric::Util::UserPref object.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'id' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: If the Bric::Util::UserPref object has been instantiated via the new() constructor and has not yet been "save"d, the object will not yet have an ID, so this method call will return undef.

my $pref_id = $user_pref->get_pref_id
    Returns the pref ID of the Bric::Util::UserPref object.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'pref_id' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

my $pref_id = $user_pref->get_user_id
    Returns the user ID of the Bric::Util::UserPref object.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'user_id' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

my $name = $user_pref->get_name
    Returns preference name.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'name' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $description = $user_pref->get_description
    Returns preference description.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'description' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $default = $user_pref->get_default
    Returns preference default.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'default' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $value = $user_pref->get_value
    Returns the preference value.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'value' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

$self = $user_pref->set_value($value)
    Sets the preference value.

    Throws:

    *   Incorrect number of args to _set().

    Side Effects: NONE.

    Notes: NONE.

my $opt_type = $user_pref->get_opt_type
    Returns preference opt_type ('select', 'radio', 'text', ...).

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'opt_type' required.

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $val_name = $user_pref->get_val_name
    Returns preference value's descriptive name. Note that if you've set the value, this method will return an incorrect value unless and until you instantiate the object again using lookup() or list().

    Throws:

    *   Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to select column into arrayref.

    *   Incorrect number of args to _set().

    Side Effects: NONE.

    Notes: NONE.

my $user_id = $user_pref->get_user_id
    Returns the user id for this usre preference.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to connect to database.

    *   Unable to execute SQL statement.

    *   Unable to bind to columns to statement handle.

    *   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

my (@opts || $opts_aref) = $user_pref->get_opts
    Returns a list or anonymous array of options available for filling in the value of this preference.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to connect to database.

    *   Unable to execute SQL statement.

    *   Unable to bind to columns to statement handle.

    *   Unable to fetch row from statement handle.

    *   Incorrect number of args to Bric::_set().

    *   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

my $opts_href = $user_pref->get_opts_href
    Returns a hashref of options available for filling in the value of this preference. The hash keys are the options, and the values are their descriptions.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to connect to database.

    *   Unable to execute SQL statement.

    *   Unable to bind to columns to statement handle.

    *   Unable to fetch row from statement handle.

    *   Incorrect number of args to Bric::_set().

    *   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$pref = $user_pref->pref()
    Loads the Bric::Util::Pref object for the given user preference object.

    Throws:

        ??

    Side Effects: NONE.

    Notes: Uses Bric::App::Cache for persistence across processes.

$self = $user_pref->save
    Saves any changes to the Bric::Util::Pref object. Returns $self on success and undef on failure.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to execute SQL statement.

    Side Effects: NONE.

    Notes: NONE.

$self = $user_pref->delete
    Delete a user preference from the database.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to execute SQL statement.

    Side Effects: NONE.

    Notes: NONE.

PRIVATE

  Private Class Methods
NONE.

  Private Instance Methods
NONE.

  Private Functions

my $user_pref_aref = &$get_em( $pkg, $params )
my $user_pref_ids_aref = &$get_em( $pkg, $params, 1 )
    Function used by lookup() and list() to return a list of Bric::Util::Pref objects or, if called with an optional third argument, returns a list of Bric::Util::Pref object IDs (used by list_ids()).

    Throws:

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to connect to database.

    *   Unable to select column into arrayref.

    *   Unable to execute SQL statement.

    *   Unable to bind to columns to statement handle.

    *   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

NOTES
NONE.

AUTHOR
David Wheeler <david@wheeler.net>

SEE ALSO
Bric