home *** CD-ROM | disk | FTP | other *** search
- # $Id: Application.pl,v 1.2 1996/08/06 07:38:53 pedja Exp $
- # Application.pl: converted from the original Application.wos
- # The original file contains the following notice:
- #
- # You may freely copy, distribute and reuse the code in this example.
- # NeXT disclaims any warranty of any kind, expressed or implied, as to
- # its fitness for any particular use.
- #
- # Written by the masked jiber.
-
- package WO::CyberWind::App;
- use WOPerl;
-
- # Global Application Variables
- #
- # Application variables declared in the following way:
- # id globalVariable;
- # are "global." Global application variables are shared by all sessions.
-
- @IVARS=qw(sessionsCount interactionsCount upSince);
- # sessionsCount:
- # The number of open sessions. Updated in didPrepareForRequest:inContext:
- # interactionsCount:
- # The total number of interactions (across all sessions).
- # Updated in didPrepareForRequest:inContext:
- # upSince:
- # The date and time (NSCalendarDate) when the server received its first
- # request.
-
- # Session Application Variables
- #
- # Application variables declared in the following way:
- # @SESSION=qw(sessionVariable1 sessionVariable2);
- # are called session variables. Each session has its own instance
- # of a session variable.
- #
- # WOF creates a new instance of a session variable every time a new session
- # begins. (A new session begins when the application gets a request for the
- # application URL. For example,
- # http://host/cgi-bin/WebObjects/Examples/WOPerl/CyberWind)
- # When subsequent requests are made, WOF automatically restores
- # the instance of the session variable that belongs to the requesting session.
- #
- # Note that between two requests from a single session, a WebObjects
- # application may serve numerous requests from multiple other sessions.
-
- @SESSION=qw(sessionInteractionsCount sessionNumber);
- # sessionInteractionsCount: The number of interactions in the current session
- # sessionNumber: The session number (identifies the session).
-
- # The awake method of an application script is called once in the
- # application's life. It's invoked as soon as the application receives
- # its first request, but before the application attempts to process the
- # its first request, but before the application attempts to process the
- # request.
-
- sub awake
- {
- my $self=shift;
- # Print a greeting when the app is launched.
- print "Wellcome to CyberWind!\n";
-
- # The following statement will obsolete sessions that have been inactive
- # for more than 2 minutes. When a session is "obsoleted," WOF
- # automatically disposes of variables associated with the obsolete
- # session.
- #
- # This is a scalability strategy. It is not mandatory.
- $WOApp->setSessionTimeOut(120);
-
- # Initialization of global variable used by Footer
- $self->{'upSince'}=NSCalendarDate->date;
- $self->{'upSince'}->setCalendarFormat("%d %b %Y %H:%M:%S");
- $self->{'sessionsCount'}=0;
- return;
- }
-
- # didPrepareForRequest:inContext: is one of the five request handling entry
- # points:
- # - awake
- # - willPrepareForRequest:inContext:
- # - didPrepareForRequest:inContext:
- # - willGenerateResponse:inContext:
- # - didGenerateResponse:inContext:
- #
- # If you implement any of these methods, WOF will invoke them automatically.
- sub didPrepareForRequestInContext
- {
- my $self=shift;
- # This is one reliable way to detect a new session. When a new session
- # starts, all the session variables are set to nil. Thus, if
- # the variable sessionNumber, a session variable, is nil, you know
- # you're in a new session.
- if (!$self->{'sessionNumber'}) {
- $self->{'sessionInteractionsCount'} = 1;
- $self->{'sessionsCount'}++;
- $self->{'sessionNumber'} = $self->{'sessionsCount'};
- }
- return nil;
- }
-
- 'WO::CyberWind::App';
- # EOF
-