perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angus Lees <>
Subject Re: calling methods within EmbperlObject (was: Possible bug with EmbperlObject and [$ sub $])
Date Wed, 20 Dec 2000 23:01:51 GMT
an idea i've been considering was to have some sort of:

 [$ uses 'subs.epl' $]

command that did:

 compile $epl;
 $pkg = package for $epl;
 push @{caller.'::ISA'}, $pkg;

that way you could selectively insert other embperl files into your
inheritance path, and each individual sub can be overridden as with
normal inheritance rules.

it would have to be done at compile time, so that (eg) subs.epl could
in turn inherit from other files without having to call constructors
everywhere. this means that the "uses" list would have to be kept
somewhere and restored when the file was recompiled (and when packages
are unloaded in embperl2, they need some way of being restored
correctly - simply reference count it and only unload if noone is
using you?).

another approach, that seems to be what people intuitively want is to
have each file inherit from other copies of itself further up the
search path. sort of like an implicit [$ uses "../$thisfile" $].

ie: always search the full path (all the way up to STOPDIR) and for
each file found, add all earlier to @ISA. we have to go all the way to
STOPDIR, so the base itself can use this mechanism too (the base will
probably use this feature most often).

in code:

 @search_path = ($STOPDIR .. $actual_epl_filepath);
 # walk reversed search path, compile each and add previous to @ISA
 foreach (@search_path) {
   next unless -r "$_/$epl"
   compile "$_/$epl";
   $pkg = package for "$_/$epl";
   push @{$pkg::ISA}, @pkglist;
   push @pkglist, $pkg;

 (if that makes it any clearer..)

 - Gus

View raw message