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->{sessionKeyTimeout};
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.
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};
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.
Given the abbreviation for a status, return the name. Returns undef if the abbreviation is not found.
Returns the list of abbreviations for a given status. Returns an empty list if the status is not found.
Return true if $status_name lists $behavior.
Return true if the status abbreviated by $status_abbrev lists $behavior.