develooper Front page | perl.perl5.porters | Postings from February 2009

method names clash by importing: next step

Thread Next
From:
Dmitry Karasik
Date:
February 18, 2009 18:02
Subject:
method names clash by importing: next step
Message ID:
20090218200058.GA53421@tetsuo.karasik.eu.org
Hello,

I've been investigating the problem of clasing between methods and
imported names, and was trying to come up with a non-invasive
solution. I've succeed, but up to a point.

First, I created a patch that does what was discussed before: it introduces an
xs "mro::method_import($package,$flag)", which if set to 0 changes method
lookup so that imported names are ignored, unless declared with :method:

http://karasik.eu.org/software/patches/p5-noimport.patch

The patch doesn't do any change in perl behavior whatsoever, unless activated
with method_import(0). Also, method_import is the only UI I've added, so the
change in base.pm or parent.pm or whatever can be, if needed, should be added
later.

Second, there's a set of tests, that I hope can demonstrate
what the change is about:

http://karasik.eu.org/software/patches/p5-noimport.t

However, I've run into a problem: when the noimport mode is activated, results
of method lookup do not get added into the cache, so every time a method is
called, in worst case it traverses through all of the class hierarchy. This is
also a problem for me because I can't decide which of the ways to add the
secondary caching is best: should the GV struct be extended to hold a new
(CV* method_cv), or should each package keep two stashes, or, as I'm inclined to
think is better, an OBJECT would be able to keep an extra stash. I think that
extending a scalar structure that way is beneficial also because we can later
easily implement dynamic, per-object (not per-class!) methods using this
machinery.

Actually such a change shouldn't (hopefully) be big, and I was tempted to start
immediately on implementing it, however I'm a bit cautios here, and would like
to discuss the change first. Possibly there were discussions about similar
changes, and there's a consensus about some things that shouldn't be touched, I
don't know.  At the very least I'd like to ask if about what would be best way to
implement a per-object stash, possibly the existing magic tables could be
adapted for this purpose?

Anyway, I'd love to hear comments.

-- 
Sincerely,
	Dmitry Karasik


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About