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

method names clash by importing: next step

Thread Next
Dmitry Karasik
February 18, 2009 18:02
method names clash by importing: next step
Message ID:

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:

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 or or whatever can be, if needed, should be added

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

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

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.

	Dmitry Karasik

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About