Bric::App::Session(3p)

NAME
Bric::App::Session - A class to handle user sessions

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2005-10-13 22:37:00 +0200 (Thu, 13 Oct 2005) $

SYNOPSIS
  use Bric::App::Session;

  #- Methods called from the apache perl handler -#

  setup_user_session($r);

  sync_user_session();

  #- Methods called from widgets -#

  [$new_state_name, $new_state_data] = init_state($widget, $state, $data);

  $state_name = state_name($widget, $name);

  $state_data = state_data($widget, ($data_hash || $name, $value));

  [$state_name, $state_data] = state($widget, $state_name, $state_data);

DESCRIPTION
This module provides all the necessary functions for maintaining state within widgets. This includes setting a global state variable $session as well as accessor methods for setting the state name of a widget and state data of a widget.

INTERFACE

  Public Class Methods

instance()
    Return a reference to the %session hash so that other parts of the API can get the current session without using %HTML::Mason::Commands::session directly.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

#------------------------------------------------------------------------------#

  Functions

setup_user_session($r)
    This function takes an Apache request object and sets up the persistent user session hash. This hash is tied to an Apache::Session::File object.

    Throws:

    *   Difficulties tie'ing the session hash.

    Side Effects:

    *   Sends a cookie to the users browser.

    *   Creates a session file on the file system.

    *   Sets global variable '%session' in package 'HTML::Mason::Commands'.

    Notes:

    NONE

sync_user_session()
    Synchronizes changes to the user session back to the file system.

    Throws:

    *   Unable to synchronize user session.

    Side Effects:

    *   Unties the global variable %HTML::Mason::Commands::session.

    Notes:

    NONE

expire_session()
    Expires the user session, deleting it from the disk.

    Throws:

    *   Unable to expire user session.

    Side Effects:

    *   Deletes the global %HTML::Mason::Commands::session session object.

    Notes:

    NONE

[$new_state_name, $new_state_data] = init_state($widget, $state, $data)
$cur_name = init_state_name($widget, $name);
$cur_val  = init_state_data($widget, $name, $value);
$key_val  = reset_state($widget, $reset_key);
    If a widget has not yet been called and this function is called, it will set some default values for that widgets state name and state data.

    Throws:

    NONE

    Side Effects:

    *   Sets the global variable %HTML::Mason::Commands::session

    Notes:

    NONE

$state_name = set_state_name($widget, $name)
$state_name = get_state_name($widget)
    Set or get the current widget state name. A state name cannot be set to undef since it is bad style to rely on a state that you do not set explicitly. If you want to clear the state entirely, use clear_state.

    Throws:

    NONE

    Side Effects:

    *   Sets the global variable %HTML::Mason::Commands::session

    Notes:

    NONE

$state_data = set_state_data($widget, ($data_hash || $name, $value))
$state_data = get_state_data($widget, $name)
    Get or set the state data. The set function takes either a hash or a key/value. Given a hash the set function will overwrite the state data. Given a key/value pair, it will set that key in the state data to that value.

    The get function will return the whole state data hash if given just a widget. If passed a name it will return the value for the state data with that name.

    Throws:

    NONE

    Side Effects:

    *   Sets the global variable %HTML::Mason::Commands::session

    Notes:

    NONE

[$state_name, $state_data] = set_state($widget, $state_name, $state_data)
[$state_name, $state_data] = get_state($widget)
    The set function takes a widget name, $widget, a state name, $state_name, and a hash ref, $state_data, containing state data. Both $state_name and $state_data are optional. If $state_name is undef, the state name will not be set, but if it does have a value it will be used to update the widget $widget state name. The same holds true for $state_data; undef will leave the state data untouched while a hash value will be used to overwrite the state data.

    The get function returns both the state name and the state data..

    Throws:

    NONE

    Side Effects:

    *   Sets the global variable %HTML::Mason::Commands::session

    Notes:

    NONE

clear_state($widget)
    Completely clears the state information for the given widget.

    Throws:

    NONE

    Side Effects:

    *   Sets the global variable %HTML::Mason::Commands::session

    Notes:

    NONE

(0 || 1) = set_user($user);
($login || undef) = get_user_login;
($uid || undef) = get_user_id;
($user || undef) = get_user_object;
    Get/set logged in user information.

    Throws: NONE

    Side Effects:

    *   Uses Bric::App::Util::get_pref() and Bric::App::Util::set_pref().

    Notes: NONE

NOTES
NONE

AUTHOR
Garth Webb <garth@perijove.com>

SEE ALSO
perl, Bric, Apache::Session::File