home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- require 'operl.pl';
-
- # define new class 'hello' as subclass of 'root'
- &defclass ('hello', 'root');
-
- # 'init' method will be invoked on creating an object
- &defmethod('hello', 'init', '$i = 0;');
-
- # method 'add1' adds 1 to $i
- &defmethod('hello', 'add1', '$i++;');
-
- # method 'show' shows the value of $i
- &defmethod('hello', 'show', 'print "-> " . $i . "\n";');
-
- $o1 = &newobject('hello');
- $o2 = &newobject('hello');
-
- print "first object=" . $o1 . "\n";
- print "second object=" . $o2 . "\n";
-
- print "Apply several operations on $o1\n";
- &send($o1, 'add1');
- &send($o1, 'show');
- &send($o1, 'add1');
- &send($o1, 'show');
- &send($o1, 'add1');
- &send($o1, 'show');
- &send($o1, 'add1');
- &send($o1, 'show');
-
- print "See? There is no change in $o2\n";
- &send($o2, 'show');
-
- &dumpclass();
-