[comp.lang.perl] operl - an experimental object-oriented package for perl

sakoh@sraco2.us.sra.co.jp (Hiroshi &) (02/21/91)

Hello, folks.

Now we have an object-oriented perl! (please allow me to call it OPERL).
Does it sound funny or insane :-) ?
As usual oo-languages, you can define classes and create instances.
Each instance can maintain its internal states independently.
Of course, it supports inheritance.

Since It's totally written in perl, you don't have to change perl
itself at all.
Although I tested the package on perl3.41, perl3.44 and perl4.0 only,
it should work on earlier versions if package feature works correctly.

Distribution kit is uuencoded since operl.pl contains control characters.

Sorry for no documents, however, you might find the way to use this package
easily at a glance (please refer to the samples).

There should be many way to improve the package.
Any comments are welcome.

By the way, I'd like to pass a scalar variable as an argument of 'package'
on execution time. 
Is it a bad idea to have like:

	sub sub1 {
		package $context;
		....
	}

??

It would improve the performance of this package,
since I could avoid to use extra eval.

Hiroshi Sakoh
sakoh@sra.co.jp or uunet!sraco1!sakoh

---<cut here>--------------------------------------------
begin 664 operl.shar
M(R$O8FEN+W-H"B,@5&AI<R!I<R!A('-H96QL(&%R8VAI=F4N("!296UO=F4@
M86YY=&AI;F<@8F5F;W)E('1H:7,@;&EN92P*(R!T:&5N('5N<&%C:R!I="!B
M>2!S879I;F<@:70@:6X@82!F:6QE(&%N9"!T>7!I;F<@(G-H(&9I;&4B+@HC
M"B,@5W)A<'!E9"!B>2`@;VX@5V5D($9E8B`R,"`Q-CHU,CHR-"!-4U0@,3DY
M,0HC($-O;G1E;G1S.B`@8F%G+G!L('-E="YP;"!P;VEN="YP;"!S=&%C:RYP
M;"!O<&5R;"YP;"!S86UP;&4Q('-A;7!L93(@<V%M<&QE,PHC"7-A;7!L930@
M<V%M<&QE-0H@"F5C:&\@>"`M(&)A9RYP;`IS960@)W,O7D`O+R<@/B`B8F%G
M+G!L(B`\/"=`+R]%*D\J1B!B86<N<&PO+R<*(R$O=7-R+V)I;B]P97)L"G)E
M<75I<F4@)V]P97)L+G!L)SL*"B9D969C;&%S<R`H)V)A9R<L)W)O;W0G*3L*
M)F1E9FUE=&AO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-T86-K(#$](B`N("9S
M96YD*"1S,2P@)W1O<"<I("X@(EQN(CL*"B9S96YD*"1S,2P@)W!O<"<I.PIP
M<FEN="`B=&]P(&]F('-T86-K(#$](B`N("9S96YD*"1S,2P@)W1O<"<I("X@
M(EQN(CL*0"\O12I/*D8@<V%M<&QE-"\O"F-H;6]D('4]<G=X+&<]<G=X+&\]
M<G@@<V%M<&QE-`H@"F5C:&\@>"`M('-A;7!L934*<V5D("=S+UY`+R\G(#X@
M(G-A;7!L934B(#P\)T`O+T4J3RI&('-A;7!L934O+R<*(R$O=7-R+V)I;B]P
M97)L"G)E<75I<F4@)W!O:6YT+G!L)SL*"B1M<V=T<F%C92`](#$[(",@;65S
M<V%G92!T<F%C92!O;@H*(R!C<F5A=&4@82!P;VEN="!`("@Q,"P@,C`I("XN
M+B!S964@)VEN:70G(&UE=&AO9`HD<#$@/2`F;F5W;V)J96-T*"=P;VEN="<L
M(#$P+"`R,"D["B9S96YD*"1P,2P@)W-H;W=?<V5L9B<I.PH*)G-E;F0H)'`Q
M+"`G;6]V92<L(#$P,"P@,3`P*3L*)G-E;F0H)'`Q+"`G<VAO=U]S96QF)RD[
M"@HF<V5N9"@D<#$L("=R;6]V92<L(#(P+"`R,"D["B9S96YD*"1P,2P@)W-H
M;W=?<V5L9B<I.PI`+R]%*D\J1B!S86UP;&4U+R\*8VAM;V0@=3UR=W@L9SUR
9=W@L;SUR>"!S86UP;&4U"B`*97AI="`P"F4U
`
end
--
 sakoh@sra.co.jp
"Whereof one cannot speak, thereof one must remain silent."  ---Wittgenstein
"Sometimes noise is significant."                            ---William Hewlett

tchrist@convex.COM (Tom Christiansen) (02/21/91)

$perl++? (study, study, study): die contented;

--tom
-- 
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn

 Tom Christiansen                tchrist@convex.com      convex!tchrist

rbj@uunet.UU.NET (Root Boy Jim) (02/22/91)

sakoh@sraco2.us.sra.co.jp (Hiroshi &) writes:
>
>Now we have an object-oriented perl! (please allow me to call it OPERL).
>Does it sound funny or insane :-) ?

Sounds Irish.

>Distribution kit is uuencoded since operl.pl contains control characters.

Why, pray tell, does source code contain unprintables?

Like C and postscript, perl makes it possible to represent
unprintables by using \ escapes. It is bad form to do otherwise.

I invite you to recode and repost your submission.
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

sakoh@sraco2.us.sra.co.jp (Hiroshi &) (02/22/91)

in article <123551@uunet.UU.NET>
	rbj@uunet.UU.NET (Root Boy Jim) wrote:

   >>Why, pray tell, does source code contain unprintables?
   >>
   >>Like C and postscript, perl makes it possible to represent
   >>unprintables by using \ escapes. It is bad form to do otherwise.

Actually ,the formerly posted source code contains portion like : q^A ... q^A 
(where ^A represents control-A) for some reason.
I dont't think we can use q\001 ... q\001 instead.

But you are right. That nuisance should be avoided as much as possible.
Here I recode and repost my submission.
There are no unprintable characters now.

Thank you for your advice.

* I don't want to claim that we should incorporate
* OO features into perl itself.
* I've just present this package as a tiny proof of flexibility of perl
* and for fun :-)

Hiroshi Sakoh
sakoh@sra.co.jp or uunet!sraco1!sakoh

---<cut here>-----------------------------------------------
#!/bin/sh
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by sraco2! on Fri Feb 22 00:58:00 MST 1991
# Contents:  bag.pl operl.pl point.pl set.pl stack.pl sample1 sample2 sample3
#	sample4 sample5 sample6
 
echo x - bag.pl
sed 's/^@//' > "bag.pl" <<'@//E*O*F bag.pl//'
#!/usr/bin/perl
require 'operl.pl';

&defclass ('bag','root');
&defmethod('bag','put',      '$elements{$_[0]}++;');
&defmethod('bag','how_many', '$elements{$_[0]};');
&defmethod('bag','kinds',    'keys(%elements);');
&defmethod('bag','delete', 
	'delete $elements{$_[0]} if --$elements{$_[0]} <= 0;');
&defmethod('bag','has',      'defined($elements{$_[0]})');
&defmethod('bag','size',     'foreach $n (%elements) {$sum += $n;};$sum;');
&defmethod('bag','dump',
    'while (($key, $val) = each %elements) {print "$key = $val\n";}');

1;
@//E*O*F bag.pl//
chmod u=r,g=r,o=r bag.pl
 
echo x - operl.pl
sed 's/^@//' > "operl.pl" <<'@//E*O*F operl.pl//'
#!/usr/bin/perl
#
# $Header: operl.pl,v 1.7 91/02/20 15:43:19 sakoh Locked $
# An experimental object-oriented package for perl.
#
package operl;
require 'dumpvar.pl';
#
# an object id = $root . $salt;
#
$root = 'operl_';  # object id root
$salt = 'a';       # object id salt;

#
# &defclass(class, superclass)
#
sub main'defclass {
    local($class) = shift;  # class name
    local($super) = shift;  # super class name

    if (defined($superclass{$super})) {
	$superclass{$class} = $super;
    } else {
	print "no such super class:" . $super . "\n";
    }
}

#
# &defmethod(class, method, body)
#
sub main'defmethod {
    local($class)  = shift; # class name
    local($method) = shift; # method name
    local($body)   = shift; # method body
    local($defs);
    local($result);

    if (!defined($superclass{$class})) {
        print "no such class:" . $class . "\n";
        return -1;
    }
    $methods{$class} .= "$method:";
    $defs = qq!sub $class'$method {! .
	     q!local($context) = shift; ! .
             q!eval "package $context;" . '$self = ' . "$context;"! .
             qq!. q\001! .
             $body . qq!\001;};!;
    $result = eval $defs;
    print $@ . "\n" unless $@ eq '';
    $result;
}

#
# &newobject(class)
#
sub main'newobject {
    local($class) = shift; # class name
    local($newobj);

    if (!defined($superclass{$class})) {
        print "no such class:" . $class . "\n";
        return -1;
    }

    $newobj = $root . $salt++;
    $myclass{$newobj} = $class;

    &main'send($newobj, 'init', @_); # call init with args
    return $newobj;
}

#
# &send(object, method, arg1, arg2, ...)
#
sub main'send {
    local($object) = shift; # objec
    local($method) = shift; # method name
    local($class, $result, $xyz);

    if ($main'msgtrace != 0) {
	$msglevel ++;
	warn "[$msglevel]:&send($object, $method, @_)";
    }
    if ($object !~ /^operl_/o) {
        warn "no such object:" . $object . "\n";
	$msglevel -- if $main'msgtrace != 0;
        return -1;
    }
    $class =  $myclass{$object};

    while (index($methods{$class}, "$method:") < 0) {
	if ($class eq 'root') {
	    warn "unknown message:" . $method . "\n";
	    $msglevel -- if $main'msgtrace != 0;
            return undef;
        }
        $class = $superclass{$class}; # chain to super class
    }
    $xyz = "$class'$method"; # subroutine to be invoked
    $result = do $xyz($object, @_);   # subroutine call
    print $@ . "\n" unless $@ eq '';
    if ($main'msgtrace != 0) {
	warn " ==> " . (($result eq undef) ? 'undef' : $result) . "\n";
	$msglevel --;
    }
    $result;
}

#
# &dumpclass()
#
sub main'dumpclass {
    while (($key, $val) = each %superclass) {
	print $key . " is a subclass of " . $val . "\n";
    }
}

#
# important built-in : 'root' class
#
$superclass{'root'} = 'root';     # 'root' is the super class of itself.
&main'defmethod('root', 'init', ''); # do nothing
&main'defmethod('root', 'class',
q!
    $operl'myclass{$self};
 !);
&main'defmethod('root', 'show_parents',
q!  local($class) = $operl'myclass{$self};
    while ($class ne 'root') {
	print $class . " -> ";
        $class = $operl'superclass{$class}; # chain to the super class
    }
    print "root\n";
 !);
&main'defmethod('root', 'show_self',
q!    print "class:" . $operl'myclass{$self} . "\n";
      print "methods:" . $operl'methods{$operl'myclass{$self}} . "\n";
      &main'dumpvar($self);
 !); # self dump

1;
@//E*O*F operl.pl//
chmod u=rw,g=r,o=r operl.pl
 
echo x - point.pl
sed 's/^@//' > "point.pl" <<'@//E*O*F point.pl//'
#!/usr/bin/perl
require 'operl.pl';

&defclass ('point','root');
&defmethod('point','init',
    '$xx = defined($_[0]) ? $_[0] : 0; $yy = defined($_[1]) ? $_[1] : 0;');
&defmethod('point','move',
    '$xx = defined($_[0]) ? $_[0] : $xx; $yy = defined($_[1]) ? $_[1] : $yy;');
&defmethod('point','movex', '$xx = defined($_[0]) ? $_[0] : $xx;');
&defmethod('point','movey', '$yy = defined($_[0]) ? $_[0] : $yy;');
&defmethod('point','rmove',
    '$xx += defined($_[0]) ? $_[0] : 0; $yy += defined($_[1]) ? $_[1] : 0;');
&defmethod('point','rmovex', '$xx += defined($_[0]) ? $_[0] : 0;');
&defmethod('point','rmovey', '$yy += defined($_[0]) ? $_[0] : 0;');
&defmethod('point','x', '$xx;');
&defmethod('point','y', '$yy;');

1;
@//E*O*F point.pl//
chmod u=r,g=r,o=r point.pl
 
echo x - set.pl
sed 's/^@//' > "set.pl" <<'@//E*O*F set.pl//'
#!/usr/bin/perl
require 'bag.pl';

&defclass ('set','bag');
&defmethod('set','put',    '$elements{$_[0]}=1;');
&defmethod('set','size',   'length(%elements);');

1;
@//E*O*F set.pl//
chmod u=r,g=r,o=r set.pl
 
echo x - stack.pl
sed 's/^@//' > "stack.pl" <<'@//E*O*F stack.pl//'
#!/usr/bin/perl
require 'operl.pl';

&defclass ('stack','root');
&defmethod('stack','init','$inx = 0');
&defmethod('stack','push','$stk[$inx++] = $_[0];');
&defmethod('stack','pop',
	   'warn "warn: empty stack.\n" if ($inx <= 0);$inx -- if $inx > 0;');
&defmethod('stack','top',
	   'warn "warn: empty stack.\n" if ($inx <= 0);$stk[$inx - 1]');
&defmethod('stack','length','$inx;');
&defmethod('stack','dump','foreach $item (@stk) {print "(" . $item . ")\n";}');

1;
@//E*O*F stack.pl//
chmod u=r,g=r,o=r stack.pl
 
echo x - sample1
sed 's/^@//' > "sample1" <<'@//E*O*F sample1//'
#!/usr/bin/perl
require 'operl.pl';

&defclass('hello', 'root');
&defclass('hehe', 'hello');
&defclass('fufu', 'hehe');

&dumpclass();

@//E*O*F sample1//
chmod u=rwx,g=rwx,o=rx sample1
 
echo x - sample2
sed 's/^@//' > "sample2" <<'@//E*O*F sample2//'
#!/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();
@//E*O*F sample2//
chmod u=rwx,g=rwx,o=rx sample2
 
echo x - sample3
sed 's/^@//' > "sample3" <<'@//E*O*F sample3//'
#!/usr/bin/perl
require 'set.pl';

$set1 = &newobject('set'); # Elements can't duplicate in set class
$bag1 = &newobject('bag'); # Elements can duplicate in bag class

print "** set **\n";
&send($set1, 'put', 'banana');
&send($set1, 'put', 'apple');
&send($set1, 'put', 'orange');
&send($set1, 'put', 'orange');
&send($set1, 'put', 'orange');

print "Orange Total=" . &send($set1, 'how_many', 'orange') . "\n";
&send($set1, 'dump');
&send($set1, 'show_self');

&send($set1, 'delete', 'orange');

print "Orange Total=" . &send($set1, 'how_many', 'orange') . "\n";
&send($set1, 'dump');
&send($set1, 'show_self');

print "** bag **\n";
&send($bag1, 'put', 'banana');
&send($bag1, 'put', 'apple');
&send($bag1, 'put', 'orange');
&send($bag1, 'put', 'orange');
&send($bag1, 'put', 'orange');

print "Orange Total=" . &send($bag1, 'how_many', 'orange') . "\n";
&send($bag1, 'dump');
&send($bag1, 'show_self');

&send($bag1, 'delete', 'orange');

print "Orange Total=" . &send($bag1, 'how_many', 'orange') . "\n";
&send($bag1, 'dump');
&send($bag1, 'show_self');
@//E*O*F sample3//
chmod u=rwx,g=rwx,o=rx sample3
 
echo x - sample4
sed 's/^@//' > "sample4" <<'@//E*O*F sample4//'
#!/usr/bin/perl
require 'stack.pl';

# create two instances of class 'stack'
$s1 = &newobject('stack');
$s2 = &newobject('stack');

# push items onto stack $s1
&send($s1, 'push', 10);
&send($s1, 'push', 20);
&send($s1, 'push', 30);

print "top of stack 1=" . &send($s1, 'top') . "\n";
print "--- dump of stack 1 ---\n";
&send($s1, 'dump');

&send($s2, 'push', 'Hello, world.');
print "top of stack 2=" . &send($s2, 'top') . "\n";

print "--- show me ---\n";
&send($s1, 'show_self');
print "--- show me ---\n";
&send($s2, 'show_self');

&send($s1, 'pop');
print "top of stack 1=" . &send($s1, 'top') . "\n";

&send($s1, 'pop');
print "top of stack 1=" . &send($s1, 'top') . "\n";

&send($s1, 'pop');
print "top of stack 1=" . &send($s1, 'top') . "\n";
@//E*O*F sample4//
chmod u=rwx,g=rwx,o=rx sample4
 
echo x - sample5
sed 's/^@//' > "sample5" <<'@//E*O*F sample5//'
#!/usr/bin/perl
require 'point.pl';

$msgtrace = 1; # message trace on

# create a point @ (10, 20) ... see 'init' method
$p1 = &newobject('point', 10, 20);
&send($p1, 'show_self');

&send($p1, 'move', 100, 100);
&send($p1, 'show_self');

&send($p1, 'rmove', 20, 20);
&send($p1, 'show_self');
@//E*O*F sample5//
chmod u=rwx,g=rwx,o=rx sample5
 
echo x - sample6
sed 's/^@//' > "sample6" <<'@//E*O*F sample6//'
#!/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";');

# define new class 'hello2' as subclass of 'hello'
&defclass ('hello2', 'hello');

# method 'add2' adds 2 to itself (send add1 to self twice)
# you can refer to the current object as $self
&defmethod('hello', 'add2', <<'METHOD' );
	&main'send($self, 'add1');
	&main'send($self, 'add1');
METHOD

$o1 = &newobject('hello2');

&send($o1, 'show');
&send($o1, 'add2');
&send($o1, 'show');
@//E*O*F sample6//
chmod u=rwx,g=rwx,o=rx sample6
 
exit 0
--
 sakoh@sra.co.jp
"Whereof one cannot speak, thereof one must remain silent."  ---Wittgenstein
"Sometimes noise is significant."                            ---William Hewlett

kayvan@apple.com (Kayvan Sylvan) (02/23/91)

Cool!!!

I like it a lot!!!

Larry has created a monster, and there are other people all around the
world adding arms and legs and various other body parts to it...

			---Kayvan

| Kayvan Sylvan       Unix/C, GNU tools   879 Lewiston Drive   408-978-1407  |
| Sylvan Associates   GUIs, Databases     San Jose, CA 95136  Think Globally |
|                     Networking, X       apple!satyr!kayvan   Act Locally   |
| === Currently looking for contracts === Hire me now! Avoid the rush! ===   |