Bric::App::Util(3p)

NAME
Bric::App::Util - A class to house general application functions.

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2007-04-24 14:29:27 +0200 (Tue, 24 Apr 2007) $

SYNOPSIS
  use Bric::App::Util;

DESCRIPTION
Utility functions.

INTERFACE

  Constructors
NONE

  Destructors

  Public Class Methods

(1 || undef) = add_msg($txt)
    Add a new warning message to the current list of messages.

    Throws:

    NONE

    Side Effects: Adds the message to the session.

    Notes:

    NONE

$txt = get_msg($num)
(@txt_list || $txt_list) = get_msg()
    Return warning message number '$num' or if $num is not given return all error messages.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

($txt || undef) = next_msg
    Returns the next warning message in the list. If there are no more messages, it will return undef.

    Throws:

    NONE

    Side Effects:

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

    Notes:

    NONE

$num = num_msg
    Returns the current number of warning messages.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

clear_msg
    Clears out all the error messages remaining. This should be called after all messages have been processed.

    Throws:

    NONE

    Side Effects:

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

    Notes:

    NONE

my $aref = mk_aref($arg)
    Returns an array reference. If $arg is an anonymous array, it is simply returned. If it's a defined scalar, it's returned as the single value in an anonymous array. If it's undef, an empty anonymous array will be returned.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

my $value = get_pref($pref_name)
    Returns a preference value.

    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 get cache value.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Pref->lookup_val() internally.

my $pkg = get_package_name
    Returns the package name given a short name.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

(1 || 0) = set_redirect($loc)
$loc     = get_redirect
$loc     = del_redirect
    Get/Set/Delete a redirect to happen during the next page load that includes the 'header.mc' header element.

    Throws:

    NONE

    Side Effects:

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

    Notes:

    This only works with pages that use the 'header.mc' element.

(1 || 0) = do_queued_redirect
    If there is a redirected set, then redirect the browser, otherwise return.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

(1 || 0) = redirect
    Redirect to a different location.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

(1 || 0) = redirect_onload()
      redirect('/');
      redirect('/', $cbh);

    Uses a JavaScript function call to redirect the browser to a different location. Will not clear out the buffer first, so stuff sent ahead will still draw in the browser. If a Params::Callback object is passed in as the second argument, the Apache request object will be used to send the JavaScript to the Browser and the callback handler object will be used to abort the request. Otherwise, the Mason request object will be used to send the JavaScript to the browser and to abort the request.

    Throws: NONE.

    Side Effects: Because "redirect_onload()" executes immediately, if it is called from a callback, note that no further callbacks will be executed, not even post-callback request callbacks.

    Notes: NONE.

status_msg($msg)
severe_status_msg($msg)
    Sometimes there's a long process executing, and you want to send status messages to the browser so that the user knows what's happening. These functions will do this for you. Call "status_msg()" each time you want to send a status messages, and it'll take care of the rest for you. The "severe_status_msg()" will do the same, but convert the message into a red, bold-fased message before sending it to the browser. When you're done sending status messages, you can either redirect to another page, or simply finish drawing the current page. It will draw in below the status messages. This function will work both in callbacks and in Mason UI code.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

log_history($args)
    Log the current URL for historical purposes.

    Throws:

    NONE

    Side Effects:

    Populates the history key of the session data.

    Notes:

    NONE

$uri = last_page($n);
    Grab the $n-th page visited. Argument $n defaults to 1, or the very last page (A $n value of 0 is the current page). Only MAX_HISTORY pages are saved.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

$uri = pop_page;
    Pops the last page visited off of the page history and returns it.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    NONE

($section, $mode, $type, ...) = parse_uri($uri);
    Returns $section (e.g. admin), $mode (e.g. manager, profile) and $type (e.g. user, media, etc). This is centralized here in case it becomes a complicated thing to do. And, centralizing is nice.

    Throws:

    NONE

    Side Effects:

    NONE

    Notes:

    Was comp/lib/util/parseUri.mc.

my $wf = find_workflow($site_id, $type, $perm);
    Returns a workflow of a particular type in a given site for which the user has a given permission to the documents and/or templates in that workflow. Returns "undef" if no workflow is found.

my $desk = find_desk($wf, $doc_perm)
    Returns the desk in the given workflow for which the user has the permission to access its documents and/or templates. Returns "undef" if no desk is found.

my @sites = site_list($perm)
    Returns a list or array reference of sites to which the user has the specified permission.

my $select_options = eval_codeselect($code)
    Returns a hash reference or reference to an array of arrays as returned by the code in $code. If the code just returns a list, it will be converted to a reference of array references, unless it has an odd number of items, in which case an error message will be displayed.

  Public Instance Methods
NONE

  Private Methods
NONE

  Private Class Methods
NONE

  Private Instance Methods
NONE

NOTES
NONE

AUTHOR
Garth Webb <garth@perijove.com> David Wheeler <david@justatheory.com>

SEE ALSO
perl, Bric