|
|
1 | ################################################################################ |
|
|
2 | # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project |
|
|
3 | # $Id$ |
|
|
4 | ################################################################################ |
|
|
5 | |
| 1 | package WeBWorK::CourseEnvironment; |
6 | package WeBWorK::CourseEnvironment; |
|
|
7 | |
|
|
8 | =head1 NAME |
|
|
9 | |
|
|
10 | WeBWorK::CourseEnvironment - Read configuration information from global.conf |
|
|
11 | and course.conf files. |
|
|
12 | |
|
|
13 | =cut |
| 2 | |
14 | |
| 3 | use strict; |
15 | use strict; |
| 4 | use warnings; |
16 | use warnings; |
| 5 | use Safe; |
17 | use Safe; |
| 6 | use WeBWorK::Utils qw(readFile); |
18 | use WeBWorK::Utils qw(readFile); |
| … | |
… | |
| 11 | # $courseName name of the course being used |
23 | # $courseName name of the course being used |
| 12 | sub new { |
24 | sub new { |
| 13 | my $invocant = shift; |
25 | my $invocant = shift; |
| 14 | my $class = ref($invocant) || $invocant; |
26 | my $class = ref($invocant) || $invocant; |
| 15 | my $webworkRoot = shift; |
27 | my $webworkRoot = shift; |
|
|
28 | my $webworkURLRoot = shift; |
| 16 | my $courseName = shift; |
29 | my $courseName = shift || ""; |
| 17 | my $safe = Safe->new; |
30 | my $safe = Safe->new; |
| 18 | |
31 | |
| 19 | # set up some defaults that the environment files will need |
32 | # set up some defaults that the environment files will need |
| 20 | $safe->reval("\$webworkRoot = '$webworkRoot'"); |
33 | $safe->reval("\$webworkRoot = '$webworkRoot'"); |
|
|
34 | $safe->reval("\$webworkURLRoot = '$webworkURLRoot'"); |
| 21 | $safe->reval("\$courseName = '$courseName'"); |
35 | $safe->reval("\$courseName = '$courseName'"); |
| 22 | |
36 | |
| 23 | # determine location of globalEnvironmentFile |
37 | # determine location of globalEnvironmentFile |
| 24 | my $globalEnvironmentFile = "$webworkRoot/conf/global.conf"; |
38 | my $globalEnvironmentFile = "$webworkRoot/conf/global.conf"; |
| 25 | |
39 | |
| … | |
… | |
| 71 | bless $self, $class; |
85 | bless $self, $class; |
| 72 | return $self; |
86 | return $self; |
| 73 | } |
87 | } |
| 74 | |
88 | |
| 75 | 1; |
89 | 1; |
|
|
90 | |
|
|
91 | __END__ |
|
|
92 | |
|
|
93 | =head1 SYNOPSIS |
|
|
94 | |
|
|
95 | use WeBWorK::CourseEnvironment; |
|
|
96 | $courseEnv = WeBWorK::CourseEnvironment->new($webworkRoot, $courseName); |
|
|
97 | |
|
|
98 | $timeout = $courseEnv->{sessionKeyTimeout}; |
|
|
99 | $mode = $courseEnv->{pg}->{options}->{displayMode}; |
|
|
100 | # etc... |
|
|
101 | |
|
|
102 | =head1 DESCRIPTION |
|
|
103 | |
|
|
104 | The WeBWorK::CourseEnvironment module reads the system-wide F<global.conf> and |
|
|
105 | course-specific F<course.conf> files used by WeBWorK to calculate and store |
|
|
106 | settings needed throughout the system. The F<.conf> files are perl source files |
|
|
107 | that can contain any code allowed under the default safe compartment opset. |
|
|
108 | After evaluation of both files, any package variables are copied out of the |
|
|
109 | safe compartment into a hash. This hash becomes the course environment. |
|
|
110 | |
|
|
111 | =head1 CONSTRUCTION |
|
|
112 | |
|
|
113 | =over |
|
|
114 | |
|
|
115 | =item new (ROOT, COURSE) |
|
|
116 | |
|
|
117 | The C<new> method finds the file F<conf/global.conf> relative to the given ROOT |
|
|
118 | directory. After reading this file, it uses the C<$courseFiles{environment}> |
|
|
119 | variable, if present, to locate the course environment file. If found, the file |
|
|
120 | is read and added to the environment. |
|
|
121 | |
|
|
122 | =back |
|
|
123 | |
|
|
124 | =head1 ACCESS |
|
|
125 | |
|
|
126 | There are no formal accessor methods. However, since the course environemnt is |
|
|
127 | a hash of hashes and arrays, is exists as the self hash of an instance |
|
|
128 | variable: |
|
|
129 | |
|
|
130 | $courseEnvironment->{someKey}->{someOtherKey}; |
|
|
131 | |
|
|
132 | =head1 AUTHOR |
|
|
133 | |
|
|
134 | Written by Sam Hathaway, sh002i (at) math.rochester.edu. |
|
|
135 | |
|
|
136 | =cut |