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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 304 - (download) (as text) (annotate)
Thu May 23 18:35:16 2002 UTC (17 years, 9 months ago) by malsyned
File size: 1568 byte(s)
Added courseName to the $self hash.  That value is obtained from the parameter
passed to new().

    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 
   34   # This comes in as a parameter to new(), not from any file.
   35   $self->{courseName} = $courseName;
   36   bless $self, $class;
   37   return $self;
   38 }
   39 
   40 sub get {
   41   my $self = shift;
   42   my $var = shift;
   43   return $self->{$var};
   44 }
   45 
   46 # ----- utils -----
   47 
   48 sub readFile {
   49   my $fileName = shift;
   50   open INPUTFILE, "<", $fileName or die "Couldn't open environment file $fileName: $!";
   51   my $result = join "\n", <INPUTFILE>;
   52   close INPUTFILE;
   53   return $result;
   54 }
   55 
   56 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9