home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-osu / operl.shar / sample2 < prev    next >
Encoding:
Text File  |  1991-02-25  |  786 b   |  36 lines

  1. #!/usr/bin/perl
  2. require 'operl.pl';
  3.  
  4. # define new class 'hello' as subclass of 'root'
  5. &defclass ('hello', 'root');
  6.  
  7. # 'init' method will be invoked on creating an object
  8. &defmethod('hello', 'init', '$i = 0;');
  9.  
  10. # method 'add1' adds 1 to $i
  11. &defmethod('hello', 'add1', '$i++;');
  12.  
  13. # method 'show' shows the value of $i
  14. &defmethod('hello', 'show', 'print "-> " . $i . "\n";');
  15.  
  16. $o1 = &newobject('hello');
  17. $o2 = &newobject('hello');
  18.  
  19. print "first  object=" . $o1 . "\n";
  20. print "second object=" . $o2 . "\n";
  21.  
  22. print "Apply several operations on $o1\n";
  23. &send($o1, 'add1');
  24. &send($o1, 'show');
  25. &send($o1, 'add1');
  26. &send($o1, 'show');
  27. &send($o1, 'add1');
  28. &send($o1, 'show');
  29. &send($o1, 'add1');
  30. &send($o1, 'show');
  31.  
  32. print "See? There is no change in $o2\n";
  33. &send($o2, 'show');
  34.  
  35. &dumpclass();
  36.