[system] / trunk / webwork-modperl / lib / WeBWorK / CourseEnvironment.pm Repository:
ViewVC logotype

Diff of /trunk/webwork-modperl/lib/WeBWorK/CourseEnvironment.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.324  
changed lines
  Added in v.695

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9