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

  1. # $Id: Main.pl,v 1.1 1996/07/26 05:14:20 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 its
  7. #   fitness for any particular use.
  8. #    
  9. #     Written by Nico Popp
  10. #   The Component application presents a group of digits. When a user
  11. #   clicks a digit, the display is refreshed to reflect the user's 
  12. #   selection.
  13. #
  14. #   The Component application is a simple example of using a subcomponent.
  15. #   The subcomponent (or child component) Palette messages the parent  
  16. #   component (Main) using a WOAction object. This works as follows:
  17. #   
  18. #   1. The parent page (Main) references the child component in its
  19. #      declarations file (Main.wod):
  20. #
  21. #      PALETTE:Palette {
  22. #      selection = number;
  23. #      callBack = displaySelection;
  24. #      }; 
  25. #
  26. #   The callback attribute specified in the declaration takes as its
  27. #   value a method that is triggered when the child component sends the
  28. #   callBack object an invoke message. Through this mechanism the child 
  29. #   component is able to message the parent.
  30. #
  31. #   2. The child component's script (Palette.pl) uses the action
  32. #      keyword to declare that the callBack specified in the parent's
  33. #      declarations file is a WOAction object:
  34. #      
  35. #      action callBack;
  36. #
  37. #   3. The child component's script (Palette.pl) sends the WOAction
  38. #      object callBack an invoke message in its click method, 
  39. #      which tells callBack to invoke its associated method, displaySelection.
  40.  
  41. package WO::Component::Main;
  42. use WOPerl;
  43.  
  44. @IVARS=qw(number selection);
  45. # number: the clicked digit    
  46. # selection: the formatted selection
  47.  
  48. #  This method is called by the Palette component, when
  49. #  a digit (hyperlink) has been clicked
  50. sub displaySelection 
  51. {
  52.   my $self=shift;
  53.   # The variable 'number' is tied to the Palette component 'selection'
  54.   # variable (look at Main.wod). So if a digit has been set, 
  55.   # the selection variable is set to the value of the clicked digit.
  56.   if ($self->{'number'}) {
  57.     $self->{'selection'} = "[$self->{'number'}]";
  58.   } else  {
  59.     $self->{'selection'} = "";
  60.   }
  61.   return $self;
  62. }
  63.  
  64. 'WO::Component::Main';
  65. # EOF
  66.