home *** CD-ROM | disk | FTP | other *** search
/ Peanuts NeXT Software Archives / Peanuts-2.iso / Developer / webobjects / extensions / win-nt / WOPerl-lite-10e7.exe / Examples / WOPerl / CyberWind / Application.pl next >
Encoding:
Perl Script  |  1996-08-09  |  3.6 KB  |  104 lines

  1. # $Id: Application.pl,v 1.2 1996/08/06 07:38:53 pedja Exp $
  2. # Application.pl: converted from the original Application.wos
  3. # The original file contains the following notice:
  4. #
  5. # You may freely copy, distribute and reuse the code in this example.
  6. # NeXT disclaims any warranty of any kind, expressed or implied, as to
  7. # its fitness for any particular use.
  8. #    
  9. # Written by the masked jiber.
  10.  
  11. package WO::CyberWind::App;
  12. use WOPerl;
  13.  
  14. # Global Application Variables
  15. #
  16. # Application variables declared in the following way:
  17. #    id globalVariable;
  18. # are "global."  Global application variables are shared by all sessions.
  19.  
  20. @IVARS=qw(sessionsCount interactionsCount upSince);
  21. # sessionsCount:
  22. #   The number of open sessions.  Updated in didPrepareForRequest:inContext:
  23. # interactionsCount:
  24. #   The total number of interactions (across all sessions).
  25. #   Updated in didPrepareForRequest:inContext:
  26. # upSince:
  27. #   The date and time (NSCalendarDate) when the server received its first
  28. #   request.
  29.     
  30. # Session Application Variables
  31. #
  32. # Application variables declared in the following way:
  33. #    @SESSION=qw(sessionVariable1 sessionVariable2);
  34. # are called session variables.  Each session has its own instance
  35. # of a session variable.
  36. #
  37. # WOF creates a new instance of a session variable every time a new session
  38. # begins.  (A new session begins when the application gets a request for the
  39. # application URL.  For example, 
  40. #    http://host/cgi-bin/WebObjects/Examples/WOPerl/CyberWind)
  41. # When subsequent requests are made, WOF automatically restores 
  42. # the instance of the session variable that belongs to the requesting session.
  43. #
  44. # Note that between two requests from a single session, a WebObjects
  45. # application may serve numerous requests from multiple other sessions.
  46.  
  47. @SESSION=qw(sessionInteractionsCount sessionNumber);
  48. # sessionInteractionsCount: The number of interactions in the current session
  49. # sessionNumber: The session number (identifies the session).
  50.  
  51. # The awake method of an application script is called once in the
  52. # application's life.  It's invoked as soon as the application receives
  53. # its first request, but before the application attempts to process the
  54. # its first request, but before the application attempts to process the
  55. # request.
  56.  
  57. sub awake
  58. {
  59.   my $self=shift;
  60.   # Print a greeting when the app is launched.
  61.   print "Wellcome to CyberWind!\n";
  62.     
  63.   # The following statement will obsolete sessions that have been inactive
  64.   # for more than 2 minutes.  When a session is "obsoleted," WOF
  65.   # automatically disposes of variables associated with the obsolete
  66.   # session.
  67.   #
  68.   # This is a scalability strategy.  It is not mandatory.
  69.   $WOApp->setSessionTimeOut(120);
  70.     
  71.   # Initialization of global variable used by Footer    
  72.   $self->{'upSince'}=NSCalendarDate->date;
  73.   $self->{'upSince'}->setCalendarFormat("%d %b %Y %H:%M:%S");
  74.   $self->{'sessionsCount'}=0;
  75.   return;
  76. }
  77.  
  78. # didPrepareForRequest:inContext: is one of the five request handling entry
  79. # points:
  80. #    - awake
  81. #    - willPrepareForRequest:inContext:
  82. #    - didPrepareForRequest:inContext:
  83. #    - willGenerateResponse:inContext:
  84. #    - didGenerateResponse:inContext:
  85. #
  86. # If you implement any of these methods, WOF will invoke them automatically.
  87. sub didPrepareForRequestInContext
  88. {
  89.   my $self=shift;
  90.   # This is one reliable way to detect a new session.  When a new session
  91.   # starts, all the session variables are set to nil.  Thus, if
  92.   # the variable sessionNumber, a session variable, is nil, you know
  93.   # you're in a new session.
  94.   if (!$self->{'sessionNumber'}) {
  95.     $self->{'sessionInteractionsCount'} = 1;
  96.     $self->{'sessionsCount'}++;    
  97.     $self->{'sessionNumber'} = $self->{'sessionsCount'};
  98.   }
  99.   return nil;
  100. }
  101.  
  102. 'WO::CyberWind::App';
  103. # EOF
  104.