WeBWorK::CourseEnvironment - Read configuration information from defaults.config and course.conf files.
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->{sessionTimeout};
my $mode = $courseEnv->{pg}->{options}->{displayMode};
# etc...
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.
$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.
The course environment is a hash and variables in the course environment can be accessed via its hash keys. For example:
$ce->{someKey}{someOtherKey};
Usage: $ce->status_abbrev_to_name($status_abbrev)
Given the abbreviation for a status, return the name. Returns undef if the abbreviation is not found.
Usage: $ce->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.
Usage: $ce->status_has_behavior($status_name, $behavior)
Return true if $status_name lists $behavior.
Usage: status_abbrev_has_behavior($status_abbrev, $behavior)
Return true if the status abbreviated by $status_abbrev lists $behavior.
Usage: $ce->two_factor_authentication_enabled
Returns true if two factor authentication is enabled for this course.