Bric::App::Session - A class to handle user sessions
$Revision: 1.9 $
$Date: 2001/12/04 18:17:43 $
use Bric::App::Session;
#- Methods called from the apache perl handler -#
setup_user_session($r);
sync_user_session();
handle_callbacks($interp);
#- 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);
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.
This function takes an Apache request object and sets up the persistant 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
Syncronizes 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
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
This function takes an HTML::Mason::Request ($m) object and an anonymous hash of GET and/or POST data as its arguments. It scans anonymous hash looking for specially marked up field names. If it finds them, it executes the proper Mason callback element. Ideally, it should be called from an autohandler, so that it executes before any dhandlers:
<%perl>;
unless ($ARGS{__CB_DONE}) {
# Setup the global session variable.
Bric::App::Session::setup_user_session($r);
# Execute an callbacks set for this request.
Bric::App::Session::handle_callbacks($m, \%ARGS);
}
$m->call_next(%ARGS);
</%perl>
The handle_callbacks() function adds the __CB_DONE key to %ARGS so that when it calls callback element, the autohandler can avoid calling handle_callbacks() again.
Throws:
Error handling callbacks.
Side Effects: Executes one or more callback mason elements.
Notes: The format for field names that will be handled by this function is:
<widget_name>|<field_name>_cb
If any request sends a field element of this format, this callback function will look in the widget directory, within the folder named <widget_name> and look for a mason element called 'callback.mc'. This element will be called with the widget name, the field name that cause the callback and the query string (and/or form field) parameters:
$m->comp($callback_comp, widget => $widget_name,
field => $field_name, param => $parameter_hash);
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
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
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
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
Completely clears the state information for the given widget.
Throws:
NONE
Side Effects:
Sets the global variable %HTML::Mason::Commands::session
Notes:
NONE
Get/set logged in user information.
Throws: NONE
Side Effects:
Uses Bric::App::Util::get_pref() and Bric::App::Util::set_pref().
Notes: NONE
NONE
NONE
NONE
"Garth Webb" <garth@perijove.com>
Bricolage Engineering
perl, Bric, Apache::Session::File
Hey! The above document had some coding errors, which are explained below:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
You forgot a '=back' before '=head2'
=back without =over