Annotation of loncom/interface/lontest.pm, revision 1.20
1.3 albertel 1: # The LearningOnline Network with CAPA
2: # A debugging harness.
3: #
1.20 ! jms 4: # $Id: lontest.pm,v 1.19 2006/03/19 21:54:41 albertel Exp $
1.3 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: #
29:
1.20 ! jms 30: =head1 NAME
! 31:
! 32: Apache::lontest;
! 33:
! 34: =head1 SYNOPSIS
! 35:
! 36: Used for debugging and testing the LONCAPA
! 37: system.
! 38:
! 39: This is part of the LearningOnline Network with CAPA project
! 40: described at http://www.lon-capa.org.
! 41:
! 42: =head1 HANDLER SUBROUTINE
! 43:
! 44: handler()
! 45:
! 46: =head1 OTHER SUBROUTINES
! 47:
! 48: =over
! 49:
! 50: =item *
! 51:
! 52: section() :
! 53:
! 54: section takes one env var name as input, and returns
! 55: what section the given env var is in, which is the part
! 56: of the env var before the first period.
! 57: Returns the section, or blank string for 'no section',
! 58: which is normal for the standard env vars like REQUEST_URI.
! 59:
! 60: =item *
! 61:
! 62: print_hash()
! 63:
! 64: =item *
! 65:
! 66:
! 67:
! 68:
! 69: =back
! 70:
! 71: =cut
! 72:
1.1 www 73: package Apache::lontest;
74:
75: use strict;
76: use Apache::Constants qw(:common :http);
1.5 www 77: use GDBM_File;
1.7 www 78: use Apache::loncommon;
1.15 albertel 79: use Apache::lonnet;
1.1 www 80:
1.4 bowersj2 81: sub section
82: {
83: my ($name) = @_;
84: return $1 if $name =~ m/\A([^.]*)\./;
85: return '';
86: }
87:
1.15 albertel 88: sub print_hash {
89: my ($r,$hash)=@_;
90: my $i=0;
91: my $interval = 20; # change this to change how many keys/table
92: my $prevSection = ''; # keeps track of the section we're in.
93:
94: foreach my $envkey (sort(keys(%{$hash}))) {
95: if (not ($i % $interval)) {
96: $r->print('</table>') unless $i eq 0;
97: $r->print('<table border="0">');
98: }
99: my $sec = section($envkey);
100:
101: if ($prevSection ne $sec) { # new section, print header
102: $r->print('<tr><td colspan="2">');
103: $r->print("<br /><br /><h2 style='color: #008800'><u>$sec</u></h2>");
104: $r->print('</td></tr>');
105: $prevSection = $sec;
106: }
107:
108: my $envVal = $hash->{$envkey};
109: $envVal =~ s/(.{50})/$1\<wbr\>/g;
110: $envkey =~ s/(.{30})/$1\<wbr\>/g;
111:
112: $r->print("<tr><td valign='top'><b>$envkey</b></td>");
113: $r->print("<td valign='top'>$envVal</td></tr>\n");
114: $i++;
115: }
116:
117: $r->print('</table></font><h1>Total Number of Elements: '.$i.'</h1>');
118: }
119: sub handler {
120: my $r = shift;
121: &Apache::loncommon::content_type($r,'text/html');
122: $r->send_http_header;
123: return OK if $r->header_only;
124:
1.19 albertel 125: $r->print(&Apache::loncommon::start_page("List Environment",undef,
126: {'function' => 'admin'}));
1.17 albertel 127:
1.15 albertel 128: $r->print("<hr /><h1>Debugging</h1><hr />\n");
129: $r->print("<font face='Courier'>");
1.17 albertel 130: $r->print("<hr /><h2>ENV</h2><hr />\n");
131: &print_hash($r,\%ENV);
132: $r->print("<hr /><h2>env</h2><hr />\n");
1.15 albertel 133: &print_hash($r,\%env);
1.5 www 134: # ------------------------------------------------ If in a course, print hashes
1.16 albertel 135: if ($env{'request.course.id'}) {
1.5 www 136:
1.15 albertel 137: my %parmhash;
138: my %symbhash;
139: my %hash;
140:
1.16 albertel 141: my $fn=$env{'request.course.fn'};
1.15 albertel 142:
143: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
144: $r->print('<h2>Big Hash</h2>');
145: foreach (sort keys %hash) {
146: $r->print("\n<br />".$_.': '.$hash{$_});
147: }
148: untie %hash;
149: } else {
150: $r->print('<h2>Count not tie big hash</h2>');
151: }
152: if (tie(%parmhash,'GDBM_File',
1.16 albertel 153: $env{'request.course.fn'}.'_parms.db',
1.15 albertel 154: &GDBM_READER(),0640)) {
155: $r->print('<h2>Parm Hash</h2>');
156: foreach (sort keys %parmhash) {
1.13 albertel 157: $r->print("\n<br />".$_.': '.$parmhash{$_});
1.15 albertel 158: }
159: untie %parmhash;
160: } else {
1.10 www 161: $r->print('<h2>Could not tie parmhash</h2>');
1.15 albertel 162: }
163: if (tie(%symbhash,'GDBM_File',"$fn\_symb.db",&GDBM_READER(),0640)) {
1.10 www 164: $r->print('<h2>Symb Hash</h2>');
165: foreach (sort keys %symbhash) {
1.15 albertel 166: $r->print("\n<br />".$_.': '.$symbhash{$_});
1.10 www 167: }
168: untie %symbhash;
1.15 albertel 169: } else {
1.10 www 170: $r->print('<h2>Could not tie symbhash</h2>');
1.15 albertel 171: }
172: if (-e $fn.'.state') {
173: $r->print('<h2>State</h2>');
174: my @conditions=();
175: {
176: my $fh=Apache::File->new($fn.'.state');
177: @conditions=<$fh>;
178: }
179: foreach (@conditions) {
180: $r->print('<tt>'.$_.'</tt><br />');
181: }
182: }
183: }
1.1 www 184:
185: # ------------------------------------------------------------------- End Debug
1.18 albertel 186: $r->print(&Apache::loncommon::end_page());
1.12 albertel 187: return OK;
1.1 www 188: }
1.4 bowersj2 189:
1.1 www 190:
191: 1;
192: __END__
193:
194:
195:
196:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>