[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 401 Revision 494
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
69 82
70 bless $self, $class; 83 bless $self, $class;
71 return $self; 84 return $self;
72} 85}
73 86
74sub hash2string { 871;
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 88
93sub array2string { 89__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 90
112# ----- utils ----- 91=head1 SYNOPSIS
113 92
114sub readFile { 93 use WeBWorK::CourseEnvironment;
115 my $fileName = shift; 94 $courseEnv = WeBWorK::CourseEnvironment->new($webworkRoot, $courseName);
116 open INPUTFILE, "<", $fileName 95
117 or return; #die "Couldn't open environment file $fileName: $!"; 96 $timeout = $courseEnv->{sessionKeyTimeout};
118 my $result = join "\n", <INPUTFILE>; 97 $mode = $courseEnv->{pg}->{options}->{displayMode};
119 close INPUTFILE; 98 # etc...
120 return $result;
121}
122 99
1231; 100=head1 DESCRIPTION
101
102The WeBWorK::CourseEnvironment module reads the system-wide F<global.conf> and
103course-specific F<course.conf> files used by WeBWorK to calculate and store
104settings needed throughout the system. The F<.conf> files are perl source files
105that can contain any code allowed under the default safe compartment opset.
106After evaluation of both files, any package variables are copied out of the
107safe compartment into a hash. This hash becomes the course environment.
108
109=head1 CONSTRUCTION
110
111=over
112
113=item new (ROOT, COURSE)
114
115The C<new> method finds the file F<conf/global.conf> relative to the given ROOT
116directory. After reading this file, it uses the C<$courseFiles{environment}>
117variable, if present, to locate the course environment file. If found, the file
118is read and added to the environment.
119
120=back
121
122=head1 ACCESS
123
124There are no formal accessor methods. However, since the course environemnt is
125a hash of hashes and arrays, is exists as the self hash of an instance
126variable:
127
128 $courseEnvironment->{someKey}->{someOtherKey};
129
130=head1 AUTHOR
131
132Written by Sam Hathaway, sh002i (at) math.rochester.edu.
133
134=cut

Legend:
Removed from v.401  
changed lines
  Added in v.494

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9