dsheroh has asked for the wisdom of the Perl Monks concerning the following question:
The Immediate Question: When inserting a code reference into @INC (as described a bit more than halfway down the require docs), what should you return from your code to indicate to require that the request has been fully handled and it should not continue checking @INC in search of the file?
Based on the docs, it seems to me that return (undef, \&{sub { 0 }} ); should do the trick (second value returned is a sub reference which returns 1 for each line of source code provided and 0 at EOF), but neither this nor any of the variations on it that I've tried have convinced require that its job has been done.
The Overall Picture:
In an attempt to allow the local version to get by with only respecifying the changed subs, I've gone off and written a sub which goes at the head of @INC and, when module Foo is used/required, first loads Foo, then loads Local::Foo on top of it. This much works (aside from some warnings about redefined subroutines which no warnings 'redefine' doesn't seem to silence).
Unfortunately, after I've finished this, the normal require processing then loads module Foo a second time, reverting everything back to the non-Local version (and generating another batch of warnings, this time for every sub in Foo), which kind of defeats the purpose of the whole thing.
As for whether this should be done at all, we do plan in the redesign to add a lot more data-driven configurability and some hooks for callbacks in order to minimize the need for wholesale replacement of subs, but things are expected to vary enough from one installation to another that the capability still needs to be there.
This does sound an awful lot like OO polymorphism, and my first stab at it was based on using OOP and either constructors or factories which detect the presence of Local subclasses and return them instead of the base class, but I don't expect to see a top-to-bottom pure-OO architecture in the new version, so we'll likely need something that works with both OO and non-OO code, which is how I got started down the current path. (No pun intended.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Telling require "I've handled it"
by JavaFan (Canon) on Oct 29, 2010 at 14:32 UTC | |
by dsheroh (Monsignor) on Oct 29, 2010 at 15:12 UTC | |
by dsheroh (Monsignor) on Nov 01, 2010 at 10:15 UTC | |
by JavaFan (Canon) on Nov 01, 2010 at 10:36 UTC | |
|
Re: Telling require "I've handled it"
by jethro (Monsignor) on Oct 29, 2010 at 16:35 UTC | |
by dsheroh (Monsignor) on Nov 01, 2010 at 10:22 UTC | |
by jethro (Monsignor) on Nov 02, 2010 at 01:08 UTC | |
|
Re: Telling require "I've handled it"
by Anonymous Monk on Oct 29, 2010 at 16:47 UTC | |
by dsheroh (Monsignor) on Oct 29, 2010 at 19:39 UTC | |
by dsheroh (Monsignor) on Nov 01, 2010 at 11:46 UTC |