File:  [LON-CAPA] / loncom / interface / lontest.pm
Revision 1.5: download - view: text, annotated - select for diffs
Wed Jun 26 14:01:50 2002 UTC (21 years, 11 months ago) by www
Branches: MAIN
CVS tags: version_0_4, stable_2002_july, STABLE, HEAD
Also lists hashes if in course.

    1: # The LearningOnline Network with CAPA
    2: # A debugging harness.
    3: #
    4: # $Id: lontest.pm,v 1.5 2002/06/26 14:01:50 www Exp $
    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: #
   28: #
   29: 
   30: package Apache::lontest;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use GDBM_File;
   35: 
   36: # section takes one env var name as input, and returns
   37: # what section the given env var is in, which is the part
   38: # of the env var before the first period.
   39: # Returns the section, or blank string for 'no section',
   40: # which is normal for the standard ENV vars like REQUEST_URI.
   41: sub section
   42: {
   43:     my ($name) = @_;
   44:     return $1 if $name =~ m/\A([^.]*)\./;
   45:     return '';
   46: }
   47: 
   48:  sub handler {
   49:      my $r = shift;
   50:      $r->content_type('text/html');
   51:      $r->send_http_header;
   52:      return OK if $r->header_only;
   53: 
   54:      $r->print('<html><body>');
   55: 
   56:      my $envkey;
   57:  
   58:      $->print("<hr><h1>Debugging</h1><hr>\n");
   59:      $->print("<font face='Courier'>");
   60:      
   61:      my $i=0;
   62:      my $interval = 20; # change this to change how many keys/table
   63:      my $prevSection = ''; # keeps track of the section we're in.
   64:      foreach $envkey (sort keys %ENV) {
   65: 	 if (not ($i % $interval))
   66:          {
   67: 	     $r->print('</table>') unless $i eq 0;
   68: 	     $r->print('<table border="0">')
   69:          }
   70: 	 my $sec = section($envkey);
   71: 
   72: 	 if ($prevSection ne $sec) # new section, print header
   73: 	 {
   74: 	     $r->print('<tr><td colspan="2">');
   75: 	     $r->print("<br><br><h2 style='color: #008800'><u>$sec</u></h2>");
   76: 	     $r->print('</td></tr>');
   77: 	     $prevSection = $sec;
   78: 	 }
   79: 
   80: 	 my $envVal = $ENV{$envkey};
   81: 	 $envVal =~ s/(.{50})/\1\<wbr\>/g;
   82: 	 $envkey =~ s/(.{30})/\1\<wbr\>/g;
   83: 	 
   84: 	 $r->print("<tr><td valign='top'><b>$envkey</b></td>");
   85:          $r->print("<td valign='top'>$envVal</td></tr>\n");
   86: 	 $i++;
   87:      }
   88: 
   89:      $r->print('</table></font><h1>Total Number of Elements: '.$i.'</h1>');
   90: 
   91: # ------------------------------------------------ If in a course, print hashes
   92:    if ($ENV{'request.course.id'}) {
   93: 
   94:      my %parmhash;
   95:      my %hash;
   96: 
   97:      my $fn=$ENV{'request.course.fn'};
   98: 
   99:      if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) &&
  100: 		(tie(%parmhash,'GDBM_File',
  101: 		     $ENV{'request.course.fn'}.'_parms.db',
  102: 		     &GDBM_READER,0640))) {
  103:      $r->print('<h2>Big Hash</h2>');
  104:          foreach (sort keys %hash) {
  105: 	     $r->print("\n<br>".$_.': '.$hash{$_});
  106:          }
  107:      $r->print('<h2>Parm Hash</h2>');
  108:          foreach (sort keys %parmhash) {
  109: 	     $r->print("\n<br>".$_.': '.$parmhash{$_});
  110:          }
  111:          untie %hash;
  112:          untie %parmhash;
  113:      }
  114: 
  115: 
  116:  }
  117:  
  118: # ------------------------------------------------------------------- End Debug
  119:      $r->print('</body></html>');        
  120:  }
  121: 
  122: 
  123: 1;
  124: __END__
  125: 
  126: 
  127: 
  128: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>