[system] / trunk / webwork2 / lib / WeBWorK / CourseEnvironment.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/CourseEnvironment.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 311 - (download) (as text) (annotate)
Sat May 25 00:40:54 2002 UTC (17 years, 7 months ago) by sh002i
File size: 1604 byte(s)
comments to global.conf, fixed new() in courseenv.
-0sam

    1 package WeBWorK::CourseEnvironment;
    2 
    3 use Safe;
    4 
    5 sub new {
    6   my $proto = shift;
    7   my $class = ref($proto) || $proto;
    8   my $webworkRoot = shift;
    9   my $courseName = shift;
   10 
   11   # determine location of globalEnvironmentFile
   12   my $globalEnvironmentFile = "$webworkRoot/conf/global.conf";
   13 
   14   # read and evaluate the global environment file
   15   my $globalFileContents = readFile($globalEnvironmentFile);
   16   my %globalConf = Safe->new->reval($globalFileContents);
   17 
   18   # if that evaluation failed, we can't really go on -- we need a global environment!
   19   $@ and die "Could not evaluate global environment file $globalEnvironmentFile: $@";
   20 
   21   # determine location of courseEnvironmentFile
   22   my $courseEnvironmentFile = $globalConf{coursesDirectory}
   23     . "/$courseName/"
   24     . $globalConf{courseEnvironmentFilename};
   25 
   26   # read and evaluate the course environment file
   27   my $courseFileContents = readFile($courseEnvironmentFile);
   28   my %courseConf = Safe->new->reval($courseFileContents);
   29 
   30   # if that evaluation failed, we can't really go on -- we need a course environment!
   31   $@ and die "Could not evaluate course environment file $courseEnvironmentFile: $@";
   32 
   33   my $self = { %globalConf, %courseConf };
   34 
   35   # This comes in as a parameter to new(), not from any file.
   36   $self->{courseName} = $courseName;
   37   bless $self, $class;
   38   return $self;
   39 }
   40 
   41 sub get {
   42   my $self = shift;
   43   my $var = shift;
   44   return $self->{$var};
   45 }
   46 
   47 # ----- utils -----
   48 
   49 sub readFile {
   50   my $fileName = shift;
   51   open INPUTFILE, "<", $fileName or die "Couldn't open environment file $fileName: $!";
   52   my $result = join "\n", <INPUTFILE>;
   53   close INPUTFILE;
   54   return $result;
   55 }
   56 
   57 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9