home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / asp / global.asa < prev    next >
Encoding:
Text File  |  2003-09-03  |  7.0 KB  |  195 lines

  1.  
  2. use DemoASP;
  3.  
  4. # import basename() into global.asa namespace
  5. use File::Basename qw(basename);
  6.  
  7. # when PerlSetVar UseStrict setting on, need to declare
  8. # global variables with "use vars"
  9. use vars qw($FontFace $GlobalFont %EG $title);
  10.  
  11. # static read only global
  12. $GlobalFont = 'face=verdana,helvetica';
  13.  
  14. # this is run every request for all scripts that share this global.asa
  15. sub Script_OnStart {
  16.     $Response->Debug("Script_OnStart $0 in global.asa");
  17.     $Session->{Started}++;
  18.     $title = '';
  19. }
  20.  
  21. sub Script_OnEnd {
  22.     $Response->Debug("Script_OnEnd $0 in global.asa");
  23.     $Session->{Ended}++;
  24. }
  25.  
  26. # modify data on the way out
  27. sub Script_OnFlush {
  28.     if($Response->{ContentType} eq 'text/html') {
  29.     my $data = $Response->{BinaryRef};
  30.     $$data =~ s/(\<(body|td).*?\>)/$1\<font $GlobalFont\>/isg;
  31.     }
  32.     my $data = $Response->{BinaryRef};
  33.     $Response->Debug("Script_OnFlush: about to flush ".length($$data)." bytes to client");
  34. }
  35.  
  36. sub Session_OnStart {
  37.     $Session->{Count} = 10;
  38.     $Session->{onstart} = time();
  39.     $Application->{'Session'.$Session->SessionID} = '?';
  40.     $Response->AppendToLog("Session_OnStart! in ./eg/global.asa ". $Session->SessionID);
  41. }
  42.  
  43. sub Session_OnEnd {
  44.     my $t_session_active = time() - $Session->{onstart};
  45.     $Application->{'Session'.$Session->SessionID} = $t_session_active;
  46.     $Response->AppendToLog("Session_OnEnd! in ./eg/global.asa ". $Session->SessionID);
  47. }
  48.  
  49. sub Application_OnStart {
  50.     $Response->AppendToLog("Application_OnStart! in ./eg/global.asa");
  51.     $Application->{Count} = 20;
  52. }
  53.  
  54. sub Application_OnEnd {
  55.     $Response->AppendToLog("Application_OnEnd! in ./eg/global.asa");
  56. }
  57.  
  58. # you can share globals between scripts as of v.10, as all scripts, including 
  59. # the global.asa are compiled into the same module
  60. %EG = (
  61.     '.htaccess' => 'Configuration parameters that make Apache::ASP tick.',
  62.  
  63.        'application.asp' => 'Uses $Application for incrementing a counter.',
  64.  
  65.        'binary_write.htm' => '$Response->BinaryWrite() demo for an asp script serving a gif.',
  66.  
  67.        'cgi.htm' => 'Shows compatibility with the CGI.pm library',
  68.  
  69.        'counting.htm' => 'Simple asp syntax shown by wrapping a for loop around html and inserting a '.
  70.                 'scalar value.',
  71.  
  72.        'dynamic_includes.htm' => 'Shows an included file called as a subroutine.',
  73.  
  74.        'error_document.htm' => 'Shows a custom error message using the $Response->ErrorDocument() API extension',
  75.  
  76.        'filter.filter' => "Demonstrates Apache::ASP's ability to act both as a source and destination filter with Apache::Filter.",
  77.  
  78.        'file_upload.asp' => 'File upload data can be read from the $Request->Form(), '.
  79.                 'and is implemented via CGI.pm',
  80.  
  81.     'footer.inc' => 'Footer include for most of the scripts listed.',
  82.  
  83.        'form.asp' => 'Shows simple use of $Request->Form() and how to get raw input data '.
  84.             ' from $Request->BinaryRead()',
  85.  
  86.        'formfill.asp' =>
  87.        'Shows use of FormFill feature, which auto fills HTML forms from '.
  88.        '$Request->Form() data.  One must install HTML::FillInForm to use this feature. ',
  89.  
  90.        'global.asa' => 'The global.asa is the nervous system of an ASP application and '.
  91.             'is where you define your event handlers.',
  92.  
  93.        'global_asa_demo.asp' => 'Shows how the global.asa can be used to track users in an '.
  94.             'application',
  95.  
  96.        'header.inc' => 'Header include for most of the scripts listed here.',
  97.  
  98.        'include.htm' => 'Shows how you can decompose a script into common included files',
  99.  
  100. #       'ordered_collections.ixhtm' => 
  101. #       'Used with Tie::IxHash, shows the natural ordering of the $Request->Form() collection '.
  102. #       'by how the browser submitted the data, useful for some.',
  103.  
  104.        'register_cleanup.asp' => 'Demonstrates use of the API extension $Server->RegisterCleanup(). '.
  105.         'Execute code after a response completes in a fail safe way with this routine. ',
  106.  
  107.        'response.asp' => 'Messy script showing much of the $Response object\'s functionality, '.
  108.         'including cookies and buffering.',
  109.  
  110.        'row.inc' => 'File dynamically included in the dynamic_includes.htm example',
  111.  
  112.        'server.htm' => 'Shows much of the $Server object\'s functionality',
  113.  
  114.        'server_variables.htm' => '$Response->ServerVariables() are the equivalent of %ENV in ASP',
  115.  
  116.        'session.asp' => 
  117.        'Shows use of the $Session object, and also demos one implementation '.
  118.        'of cookieless sessions.',
  119.  
  120.        'session_query_parse.asp' =>
  121.        "Demonstrates automatic cookieless session support with the SessionQueryParse* ".
  122.        "settings.",
  123.  
  124.        'source.asp' => 'Handy source code viewer used to let you easily view the source of '.
  125.                'the other asp scripts.',
  126.  
  127.        'ssi_filter.ssi' => 'Shows full SSI in action via Apache::Filter & Apache::SSI. You must compile '.
  128.             'your apache with stacked handlers and install these modules to see '.
  129.        '        this script',
  130.  
  131.        'syntax_error.asp' => 'Demonstrates asp debugging with Debug 2 by creating a perl syntax error ',
  132.  
  133.        'table.inc' => 'Another include used to demo dynamic_includes.htm',
  134.  
  135.        'test.gif' => 'Source gif for the binary_write.htm example',
  136.  
  137.        'transfer.htm' => '$Server->Transfer() use in action, for speedy redirect type behavior.',
  138.        
  139.        'xml_subs.asp' => 
  140.        'XMLSubsMatch XML Extensions demonstrated, which all custom tags '.
  141.        'to be created by the developer.',
  142.  
  143.        'xml_subs_strict.asp' =>
  144.        'XMLSubsStrict setting causes XMLSubs to accept only string literals '.
  145.        'for arguments, conforming to XML standard more strictly, and '.
  146.        'controlling XMLSubs execution to compile time arguments.',
  147.        
  148.  
  149.        'xslt.xml' => 'XSLT transformation of XML script, using XML::XSLT, and a DBM based cache with the XSLTCache setting. Also possible for the XSLTParser setting is XML::Sablotron for faster XSLT rendering.',
  150. );
  151.  
  152. $SIG{__DIE__} = \&Carp::confess;
  153.  
  154. # note if you include XMLSubs in the global.asa, make sure to 
  155. # switch the package context to the XMLSubs namespace to avoid
  156. # any odd variable scoping problems
  157. package my;
  158.  
  159. sub my::include {
  160.     my($args, $text) = @_;
  161.  
  162.     # reference the $Response object in the package namespace 
  163.     # since we are in the my:: package and not the GlobalPackage/global.asa
  164.     $main::Response->Include($args->{src}, title => $args->{title});
  165. }
  166.  
  167. sub my::ttb {
  168.     my($args, $text) = @_;
  169.     print "<font face=courier size=-1><b>$text</b></font>";
  170. }
  171.  
  172. sub my::table {
  173.     my($args, $text) = @_;
  174.     my $title = delete $args->{title};
  175.  
  176.     my %args = (
  177.          # set defaults, and override with %$args
  178.          border => 0,
  179.          bgcolor => 'white',
  180.          width => '300',
  181.          cellpadding => 3,
  182.          cellspacing => 0,
  183.          %$args
  184.         );
  185.  
  186.     print '<table '.join(' ', 
  187.              map { "$_=$args{$_}" } keys %args,
  188.             ). '>';
  189.     print ($title ? "<tr><td bgcolor=black><font color=white>$title</font></td></tr>" : '');
  190.     print "\n";
  191.     print "<tr><td>";
  192.     print $text;
  193.     print "</td></tr></table>";
  194. }
  195.