--- trunk/webwork-modperl/lib/WeBWorK.pm 2003/06/06 21:47:51 1051 +++ trunk/webwork-modperl/lib/WeBWorK.pm 2003/06/18 20:03:03 1204 @@ -18,13 +18,15 @@ use WeBWorK::Authen; use WeBWorK::Authz; use WeBWorK::ContentGenerator::Feedback; +use WeBWorK::ContentGenerator::GatewayQuiz; use WeBWorK::ContentGenerator::Hardcopy; +use WeBWorK::ContentGenerator::Instructor::Assigner; use WeBWorK::ContentGenerator::Instructor::Index; use WeBWorK::ContentGenerator::Instructor::PGProblemEditor; +use WeBWorK::ContentGenerator::Instructor::ProblemList; use WeBWorK::ContentGenerator::Instructor::ProblemSetEditor; use WeBWorK::ContentGenerator::Instructor::ProblemSetList; use WeBWorK::ContentGenerator::Instructor::UserList; -use WeBWorK::ContentGenerator::Instructor::ProblemList; use WeBWorK::ContentGenerator::Instructor::UserList; use WeBWorK::ContentGenerator::Login; use WeBWorK::ContentGenerator::Logout; @@ -35,6 +37,14 @@ use WeBWorK::ContentGenerator::Test; use WeBWorK::CourseEnvironment; use WeBWorK::DB; +use WeBWorK::Timing; + +#sub dispatch($) { +# print STDERR "Executing &WeBWorK::dispatch\n"; +# return DECLINED; +#} +#1; +#__END__ sub dispatch($) { my ($apache) = @_; @@ -58,6 +68,9 @@ $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); return REDIRECT; # *** any post data gets lost here -- fix that. + # (actually, it's not a problem, since all URLs generated + # from within the system have trailing slashes, and we don't + # need POST data from outside the system anyway!) } # Create the @components array, which contains the path specified in the URL @@ -66,14 +79,17 @@ my $pg_root = $r->dir_config('pg_root'); # From a PerlSetVar in httpd.conf my $course = shift @components; + my $ceTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch get ce"); + $ceTimer->start; + # Try to get the course environment. my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $pg_root, $course);}; if ($@) { # If there was an error getting the requested course - # TODO: display an error page. For now, 404 it. - warn $@; - return DECLINED; + die "Failed to read course environment for $course: $@"; } + $ceTimer->stop; + # If no course was specified, redirect to the home URL unless (defined $course) { $r->header_out(Location => $ce->{webworkURLs}->{home}); @@ -82,22 +98,30 @@ # Freak out if the requested course doesn't exist. For now, this is just a # check to see if the course directory exists. - if (!-e $ce->{webworkDirs}->{courses} . "/$course") { - warn "Course directory for $course not found at " - . $ce->{webworkDirs}->{courses} . "/$course" ."\n"; - return DECLINED; + my $courseDir = $ce->{webworkDirs}->{courses} . "/$course"; + unless (-e $courseDir) { + die "Course directory for $course ($courseDir) not found. Perhaps the course does not exist?"; } + my $dbTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch init db"); + $dbTimer->start; + # Bring up a connection to the database (for Authen/Authz, and eventually # to be passed to content generators, when we clean this file up). my $db = WeBWorK::DB->new($ce); + $dbTimer->stop; + ### Begin dispatching ### + my $dispatchTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch begin dispatching"); + $dispatchTimer->start; + + my $result; # WeBWorK::Authen::verify erases the passwd field and sets the key field # if login is successful. if (!WeBWorK::Authen->new($r, $ce, $db)->verify) { - return WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; } else { # After we are authenticated, there are some things that need to be # sorted out, Authorization-wize, before we start dispatching to individual @@ -110,62 +134,77 @@ my $arg = shift @components; if (!defined $arg) { # We want the list of problem sets - return WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; } elsif ($arg eq "hardcopy") { + my $hardcopyArgument = shift @components; + $WeBWorK::timer1 = WeBWorK::Timing->new("hardcopy: $hardcopyArgument"); + $WeBWorK::timer1->start; $hardcopyArgument = "" unless defined $hardcopyArgument; - return WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument); + my $result = WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument); + $WeBWorK::timer1 ->stop; + $WeBWorK::timer1 ->save; + return $result; } elsif ($arg eq "instructor") { my $instructorArgument = shift @components; if (!defined $instructorArgument) { - return WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; } elsif ($instructorArgument eq "users") { - return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; } elsif ($instructorArgument eq "sets") { my $setID = shift @components; if (defined $setID) { my $setArg = shift @components; if (!defined $setArg) { - return WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID); + $result = WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID); } elsif ($setArg eq "problems") { - return WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID); + $result = WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID); } elsif ($setArg eq "users") { - return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go($setID); + $result = WeBWorK::ContentGenerator::Instructor::Assigner->new($r, $ce, $db)->go($setID); } } else { - return WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; } } elsif ($instructorArgument eq "pgProblemEditor") { - return WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components); + $result = WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components); } } elsif ($arg eq "options") { - return WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; } elsif ($arg eq "feedback") { - return WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; } elsif ($arg eq "logout") { - return WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; } elsif ($arg eq "test") { - return WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; + $result = WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; + } elsif ($arg eq "quiz_mode" ) { + # Gateway quiz capability -- very similar to problem set (initially) + $result = WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components); } else { # We've got the name of a problem set. my $problem_set = $arg; my $ps_arg = shift @components; if (!defined $ps_arg) { # list the problems in the problem set - return WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set); + $result = WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set); } else { # We've got the name of a problem my $problem = $ps_arg; - return WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem); + + $WeBWorK::timer0 = WeBWorK::Timing->new("Problem $course:$problem_set/$problem"); + $WeBWorK::timer0->start; + my $result = WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem); + $WeBWorK::timer0->stop; + $WeBWorK::timer0->save; + return $result; + + } } - } - # If the dispatcher doesn't know any modules that want to handle - # the current path, it'll claim that the path does not exist by - # declining the request. - return DECLINED; + $dispatchTimer->stop; + + return $result; } 1;