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 / Main.wo / Main.pl < prev    next >
Encoding:
Perl Script  |  1996-08-09  |  3.3 KB  |  77 lines

  1. # $Id: Main.pl,v 1.1 1996/07/26 05:14:52 pedja Exp $
  2. # Main.pl: converted from the original Main.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. # Script files define variables and actions associated with a
  10. # component--usually a page, but sometimes just a part of a page.
  11. # When a WebObjects application is running, these script files
  12. # are used to initialize WOWebScriptComponentControllers.  The component
  13. # controller "adopts" the variables and actions declared in the script.
  14. #
  15. # A WOWebScriptComponentController is transient.
  16. # It's created when an application receives a request for its
  17. # corresponding page, and it goes away when the application returns a
  18. # response.  Later, when a user performs an action from the page, the
  19. # WOWebScriptComponentController is recreated to handle the user's
  20. # action.
  21. #
  22. # For example, when a user opens the URL for the Cyber Wind program, the
  23. # Cyber Wind application receives a request for the Main page.
  24. # A WOWebScriptComponentController is created and initialized with this file.
  25. # Upon its initialization, the awake method is invoked.
  26. #
  27. # WOF creates a response containing the dynamically generated HTML for the
  28. # Main page and then destroys the Main's WOWebScriptComponentController.
  29. # Before destroying the component controller, WOF stores any variables that
  30. # are declared persistent.  (Main doesn't have any persistent variables, so
  31. # no state is preserved in this case.)
  32. #
  33. # When the user clicks in the Main page of CyberWind, on either the
  34. # "See surfshop info" or "Buy a new sailboard" hyperlink, Cyber Wind receives
  35. # a new request from the Main page.  When Cyber Wind gets the request, it
  36. # recreates the WOWebScriptComponentController for Main, so the Main
  37. # component controller can handle the users action.  When its recreated,
  38. # awake is called again.
  39. #
  40. # The awake method is a good place to create variables because it's
  41. # called exactly once for every transaction (for requesting the page, and 
  42. # for processing an action originating in the page).  As an alternative,
  43. # you can declare persistent variables.  That way, WOF will automatically
  44. # save and restore them for you.  However, if the application serves a
  45. # large number of clients and generates a lot of persistent state storage,
  46. # the application will become a hog.
  47. #
  48.  
  49. package WO::CyberWind::Main;
  50. use WOPerl;
  51. @IVARS=qw(options option);
  52.  
  53. sub awake {
  54.   my $self=shift;
  55.   # The options array must be present for WOF to be able to create the
  56.   # HTML for the Main page, and it must be present when Main's
  57.   # component controller identifies what hyperlink the user clicked.
  58.   $self->{'options'}=["See surfshop information", "Buy a new sailboard"];
  59. }
  60.  
  61. # This method is called when one of the hyperlinks is clicked.
  62. # The option object (repetition's item) lets you identify which of the
  63. # hyperlinks was clicked, "Surfshops" or "Buy."
  64. sub chooseOption
  65. {
  66.   my $self=shift;
  67. #  print "option: $self->{'option'}\n";
  68.   if ($self->{'option'} eq $self->{'options'}->[0]) {
  69.     return $WOApp->pageWithName("Surfshops");
  70.   } elsif ($self->{'option'} eq $self->{'options'}->[1]) {
  71.     return $WOApp->pageWithName("Buy");
  72.   } else { return $self; }
  73. }
  74.  
  75. 'WO::CyberWind::Main';
  76. # EOF
  77.