[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 283 - (download) (as text) (annotate)
Wed May 22 18:44:14 2002 UTC (17 years, 9 months ago) by malsyned
File size: 1469 byte(s)



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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9