in reply to Breaking XS for testing?

You could replace @INC with a single code ref that rejects attempts to require certain packages, otherwise it searches @INC itself. Note that this answer demonstrates that I know that you can put a code ref into @INC but that I don't know if such code refs can prevent subsequent entries from being search or if you can temporarilly override @INC and re-require within the ref'd code.

- tye        

  • Comment on Re: Breaking XS for testing? (@INC code ref)

Replies are listed 'Best First'.
Re^2: Breaking XS for testing? (@INC code ref)
by xdg (Monsignor) on Mar 06, 2006 at 22:50 UTC

    The problem with that is that I still want the pure-Perl part of Scalar::Util to work. My test file was just a idealized case to show that it can be done.

    In the real case, I want to load parts of Scalar::Util that have Perl fall-backs, try to load weaken, detect if it fails, and then have a sensible response (in this case, issuing a warning and continuing). So I need to interrupt XS loading only, without affecting @INC. Otherwise, I'd probably have gone tried that.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      I was assuming a sane "fallback if no XS version available" scheme such as I've seen many times, where something like Scalar::Util_XS is a separate module that is only optionally installed. But Scalar::Util doesn't use this level of sanity and instead implements a lot of special installation machinery in order to allow it to install just parts of itself, so you have to learn its own flavor of magic in order to deal with it.

      It looks like overriding DynaLoader::bootstrap() would suffice:

      require Dynaloader; my $orig= \&DynaLoader::bootstrap; *DynaLoader::bootstrap= sub { ... };

      - tye