NAME

WeBWorK::CourseEnvironment - Read configuration information from defaults.config and course.conf files.

SYNOPSIS

use WeBWorK::CourseEnvironment;
$ce = WeBWorK::CourseEnvironment->new({
       webwork_url         => "/webwork2",
       webwork_dir         => "/opt/webwork2",
       pg_dir              => "/opt/pg",
       webwork_htdocs_url  => "/webwork2_files",
       webwork_htdocs_dir  => "/opt/webwork2/htdocs",
       webwork_courses_url => "/webwork2_course_files",
       webwork_courses_dir => "/opt/webwork2/courses",
       courseName          => "name_of_course",
});

my $timeout = $courseEnv->{sessionKeyTimeout};
my $mode    = $courseEnv->{pg}->{options}->{displayMode};
# etc...

DESCRIPTION

The WeBWorK::CourseEnvironment module reads the system-wide defaults.config and course-specific course.conf files used by WeBWorK to calculate and store settings needed throughout the system. The .conf files are perl source files that can contain any code allowed under the default safe compartment opset. After evaluation of both files, any package variables are copied out of the safe compartment into a hash. This hash becomes the course environment.

CONSTRUCTION

new($seedVars)

$seedVars is an optional argument. If provided it must be a reference to a hash containing scalar variables with which to seed the course environment. It may contain values for the keys webwork_dir, pg_dir, courseName, and web_config_filename.

If webwork_dir or pg_dir are not given in $seedVars they will be taken from the %WeBWorK::SeedCE hash. If they are still not found in that hash, then they will be taken from the system environment variables WEBWORK_ROOT and PG_ROOT.

The new method finds the file conf/defaults.config relative to the webwork_dir directory. After reading this file, it uses the $courseFiles{environment} variable, if present, to locate the course environment file. If found, the file is read and added to the environment.

ACCESS

There are no formal accessor methods. However, since the course environemnt is a hash of hashes and arrays, is exists as the self hash of an instance variable:

$ce->{someKey}{someOtherKey};

EXPERIMENTAL ACCESS METHODS

This is an experiment in extending CourseEnvironment to know a little more about its contents, and perform useful operations for me.

There is a set of operations that require certain data from the course environment. Most of these are un Utils.pm. I've been forced to pass $ce into them, so that they can get their data out. But some things are so intrinsically linked to the course environment that they might as well be methods in this class.

STATUS METHODS

status_abbrev_to_name($status_abbrev)

Given the abbreviation for a status, return the name. Returns undef if the abbreviation is not found.

status_name_to_abbrevs($status_name)

Returns the list of abbreviations for a given status. Returns an empty list if the status is not found.

status_has_behavior($status_name, $behavior)

Return true if $status_name lists $behavior.

status_abbrev_has_behavior($status_abbrev, $behavior)

Return true if the status abbreviated by $status_abbrev lists $behavior.