Bric::Util::Pref - Interface to Bricolage preferences. $LastChangedRevision$ $LastChangedDate: 2006-03-18 01:26:34 +0100 (Sat, 18 Mar 2006) $ use Bric::Util::Pref; # Constructors. my $pref = Bric::Util::Pref->new($init); $pref = Bric::Util::Pref->lookup({ id => $id }); $pref = Bric::Util::Pref->lookup({ name => $name }); my @prefs = Bric::Util::Pref->list($params); # Class Methods. my @pref_ids = Bric::Util::Pref->list_ids($params); my $meths = Bric::Util::Pref->my_meths; my @meths = Bric::Util::Pref->my_meths(1); # Fetch a value from the cache. my $val = Bric::Util::Pref->lookup_val($name); # Instance Methods my $id = $pref->get_id; my $name = $pref->get_name; my $desc = $pref->get_description; my $default = $pref->get_default; my $opt_type = $pref->get_opt_type; my $val_name = $pref->get_val_name; # Get a list of available value options. my @opts = $pref->get_opts; my $opts_ref = $pref->get_opts_href; # Get and set the value. my $value = $pref->get_value; $pref = $pref->set_value($value); # Save the pref. $pref = $pref->save; This is the central interface for managing Bricolage application preferences. It should scale when we later decide to add user and user group preferences. Right now it'll just support those global application preferences that we deem necessary for the application to work, such as Time Zone.

Constructors
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. 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: Preference ID. May use "ANY" for a list of possible values. Preference name. May use "ANY" for a list of possible values. Preference description. May use "ANY" for a list of possible values. Preference default value. May use "ANY" for a list of possible values. Value to which preference is set. May use "ANY" for a list of possible values. Name of the value. May use "ANY" for a list of possible values. Boolean indicating whether a value can be manually entered by the user, rather than selected from a list. May use "ANY" for a list of possible values. Boolean indicating whether or not users can override the global preference value. May use "ANY" for a list of possible values. The preference option type. May use "ANY" for a list of possible values. The ID of a Bric::Util::Grp object with which prefereneces may be associated. May use "ANY" for a list of possible values. 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
Dummy method to prevent wasting time trying to AUTOLOAD DESTROY. Throws: NONE. Side Effects: NONE. Notes: NONE.

Public Class Methods
Returns a list or anonymous array of Bric::Util::Pref object IDs based on the search criteria passed via an anonymous hash. The supported lookup keys are the same as those for list(). 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. Returns true if "lookup_val()" will return the value of a user preference, and false if it will not. Pass in a true or false value to change enable or disable the returning of user preferences by "lookup_val()". Throws: NONE. Side Effects: NONE. Notes: NONE. Looks up and returns the value of a preference without the expense of instantiating an object. Plus, it uses caching to keep it quick - the cache changes only when a value changes. If "use_user_prefs()" returns true and a user is currently logged in, then the value of the preference for that user will be returned. Otherwise, the global preference will be returned. Throws: Unable to instantiate create cache. Unable to populate preference cache. Unable to connect to database. Unable to prepare SQL statement. Unable to execute SQL statement. Unable to bind to columns to statement handle. Unable to fetch row from statement handle. Unable to get cache value. Side Effects: See &$load_cache(). Notes: See &$load_cache(). 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: The name of the property or attribute. Is the same as the hash key when an anonymous hash is returned. The display name of the property or attribute. A reference to the method that will retrieve the value of the property or attribute. An anonymous array of arguments to pass to a call to get_meth in order to retrieve the value of the property or attribute. A reference to the method that will set the value of the property or attribute. An anonymous array of arguments to pass to a call to set_meth in order to set the value of the property or attribute. The type of value the property or attribute contains. There are only three types: If the value is a 'short' value, this hash key contains the length of the field. The property is searchable via the list() and list_ids() methods. The property or attribute is required. An anonymous hash of properties used to display the property or attribute. Possible keys include: The display field type. Possible values are The Length, in letters, to display a text or password field. The maximum length of the property or value - usually defined by the SQL DDL. The number of rows to format in a textarea field. The number of columns to format in a textarea field. 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
Returns the ID of the Bric::Util::Pref 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::Pref 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. 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. 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. 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. 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. Sets the preference value. Throws: Incorrect number of args to _set(). Side Effects: NONE. Notes: NONE. Returns a boolean indicating whether the value can be overridden on a per-user basis. Throws: Bad AUTOLOAD method format. Cannot AUTOLOAD private methods. Access denied: READ access for field 'can_be_overridden' required. No AUTOLOAD method. Side Effects: NONE. Notes: NONE. Sets whether the value can be overridden on a per-user basis. Throws: Incorrect number of args to _set(). Side Effects: NONE. Notes: NONE. 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. 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. 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. 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. 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. Unable to instantiate preference cache. Unable to populate preference cache. Unable to set cache value. Side Effects: NONE. Notes: NONE.

Private Class Methods
NONE.

Private Instance Methods
NONE.

Private Functions
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. Queries this preference's value options from the database. Throws: Bric::_get() - Problems retrieving fields. Unable to connect to database. Unable to prepare SQL statement. 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. Incorrect number of args to Bric::_set(). Bric::set() - Problems setting fields. Side Effects: NONE. Notes: NONE. Loads all the preference keys and values into a Cache::FileCache object. Throws: Unable to instantiate preference cache. Unable to populate preference cache. Unable to connect to database. Unable to prepare SQL statement. Unable to execute SQL statement. Unable to bind to columns to statement handle. Unable to fetch row from statement handle. Side Effects: NONE. Notes: Uses Bric::App::Cache for persistence across processes. Sets a value in the cache. Throws: Unable to instantiate preference cache. Unable to populate preference cache. Unable to connect to database. Unable to prepare SQL statement. Unable to execute SQL statement. Unable to bind to columns to statement handle. Unable to fetch row from statement handle. Unable to set cache value. Side Effects: See &$load_cache(). Notes: See &$load_cache(). NONE. David Wheeler <david@justatheory.com> Bric