Parent Directory
|
Revision Log
-Fixed a few interfaces so that they make more sense (I hope) -Added preliminary templating code to ContentGenerator -Added a lot of logic to the dispatcher (WeBWorK.pm). More to come, too. -Moved lots of things over to CGI.pm, for my convenience while prototyping -Added preliminary examples of ProblemSets, ProblemSet, and Problem. Problem.pm will some day go on to do what ProcessProblem8 does right now, so keep your eyes on that one. --Dennis
1 # Apache::WeBWorK - The WeBWorK dispatcher module 2 # Place something like the following in your Apache configuration to load the 3 # WeBWorK module and install it as a handler for the WeBWorK system 4 5 # PerlModule Apache::WeBWorK 6 # PerlRequire /path/to/webwork/conf/init.pl 7 # PerlSetVar webwork_root /path/to/webwork 8 # <Location /webwork> 9 # SetHandler perl-script 10 # PerlHandler Apache::WeBWorK 11 # </Location> 12 13 package Apache::WeBWorK; 14 15 use strict; 16 use Apache::Constants qw(:common REDIRECT); 17 use Apache::Request; 18 use WeBWorK::CourseEnvironment; 19 use WeBWorK::Test; 20 use WeBWorK::Authen; 21 use WeBWorK::Login; 22 use WeBWorK::ProblemSets; 23 use WeBWorK::ProblemSet; 24 use WeBWorK::Problem; 25 26 # registering discontent: wanted to call this dispatch, but mod_perl gave me lip 27 sub handler() { 28 my $r = Apache::Request->new(shift); # have to deal with unpredictable GET or POST data ,and sift through it for the key. So use Apache::Request 29 30 # This stuff is pretty much copied out of the O'Reilly mod_perl book. 31 # It's for figuring out the basepath. I may change this up if I 32 # find a better way to do it. 33 my $path_info = $r->path_info; 34 my $path_translated = $r->lookup_uri($path_info)->filename; 35 my $current_uri = $r->uri; 36 unless ($path_info) { 37 $r->header_out(Location => "$current_uri/"); 38 return REDIRECT; 39 } 40 41 return OK if $r->header_only; 42 43 my($junk, @components) = split "/", $path_info; 44 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf 45 my $course = shift @components; 46 47 # Try to get the course environment. 48 my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $course);}; 49 if ($@) { # If no course exists matching the requested course 50 # TODO: display an error page. For now, 404 it. 51 return DECLINED; 52 } 53 54 # WeBWorK::Authen::verify erases the passwd field and sets the key field 55 # if login is successful. 56 if (!WeBWorK::Authen->new($r, $course_env)->verify) { 57 return WeBWorK::Login->new($r, $course_env)->go; 58 } else { 59 my $arg = shift @components; 60 if (!defined $arg) { # We want the list of problem sets 61 return WeBWorK::ProblemSets->new($r, $course_env)->go; 62 } elsif ($arg eq "prof") { 63 ### 64 } elsif ($arg eq "prefs") { 65 ### 66 } else { # We've got the name of a problem set. 67 my $problem_set = $arg; 68 my $ps_arg = shift @components; 69 70 if (!defined $ps_arg) { 71 # list the problems in the problem set 72 return WeBWorK::ProblemSet->new($r, $course_env)->go($problem_set); 73 } elsif ($ps_arg eq "hardcopy") { 74 ### 75 } 76 else { 77 # We've got the name of a problem 78 my $problem = $ps_arg; 79 return WeBWorK::Problem->new($r, $course_env)->go($problem_set, $problem); 80 } 81 } 82 83 if (1) { 84 return WeBWorK::Test->new($r, $course_env)->go; 85 } 86 } 87 88 # If the dispatcher doesn't know any modules that want to handle 89 # the current path, it'll claim that the path does not exist by 90 # declining the request. 91 return DECLINED; 92 } 93 94 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |