Parent Directory
|
Revision Log
Revision 313 - (view) (download) (as text)
| 1 : | malsyned | 313 | package WeBWorK::ContentGenerator; |
| 2 : | malsyned | 305 | |
| 3 : | malsyned | 313 | # This is a superclass for Apache::WeBWorK's content generators. |
| 4 : | # You are /definitely/ encouraged to read this file, since there are | ||
| 5 : | # "abstract" functions here which show aproximately what form you would | ||
| 6 : | # want over-ridden sub-classes to follow. go() is a particularly pertinent | ||
| 7 : | # example. | ||
| 8 : | |||
| 9 : | malsyned | 305 | # new(Apache::Request, WeBWorK::CourseEnvironment) |
| 10 : | sub new($$$) { | ||
| 11 : | malsyned | 313 | my $proto = shift; |
| 12 : | my $class = ref($proto) || $proto; | ||
| 13 : | malsyned | 305 | my $self = {}; |
| 14 : | ($self->{r}, $self->{courseEnvironment}) = @_; | ||
| 15 : | bless $self, $class; | ||
| 16 : | return $self; | ||
| 17 : | } | ||
| 18 : | |||
| 19 : | malsyned | 313 | # This is a quick and dirty function to print out all (or almost all) of the |
| 20 : | # fields in a form in a specified format. As you can see from the print | ||
| 21 : | # statement, it just prints out $begining$name$middle$value$end for every | ||
| 22 : | # field who's name doesn't match $qr_omit, a quoted regex. | ||
| 23 : | # In it's current incarnation, it should be called from subclasses only, | ||
| 24 : | # by saying $self->print_form_data. Of course, you could construct a | ||
| 25 : | # hashref with ->{r} being an Apache::Request, I suppose. | ||
| 26 : | malsyned | 305 | |
| 27 : | malsyned | 313 | sub print_form_data { |
| 28 : | my ($self, $begin, $middle, $end, $qr_omit) = @_; | ||
| 29 : | |||
| 30 : | $r=$self->{r}; | ||
| 31 : | my @form_data = $r->param; | ||
| 32 : | foreach my $name (@form_data) { | ||
| 33 : | next if ($qr_omit and $name =~ /$qr_omit/); | ||
| 34 : | my @values = $r->param($name); | ||
| 35 : | foreach my $value (@values) { | ||
| 36 : | print $begin, $name, $middle, $value, $end; | ||
| 37 : | } | ||
| 38 : | } | ||
| 39 : | } | ||
| 40 : | |||
| 41 : | # Abstract as they get, this go() is meant to be over-ridden by | ||
| 42 : | # absolutely /anything/ that subclasses it. Most subclasses, however, | ||
| 43 : | # will find it a useful thing to copy and modify, rather than writing from | ||
| 44 : | # scratch. | ||
| 45 : | |||
| 46 : | sub go() { | ||
| 47 : | malsyned | 305 | my $self = shift; |
| 48 : | malsyned | 313 | $r = shift; |
| 49 : | malsyned | 305 | $r->content_type($ct); |
| 50 : | foreach $key (keys %headers) { | ||
| 51 : | malsyned | 313 | $r->header_out($key, $headers{$key}); |
| 52 : | malsyned | 305 | } |
| 53 : | $r->send_http_header; | ||
| 54 : | |||
| 55 : | return OK if $r->header_only; | ||
| 56 : | |||
| 57 : | malsyned | 313 | print "You shouldn't see this. This is only a prototype."; |
| 58 : | } | ||
| 59 : | |||
| 60 : | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |