in reply to use/import params during require

Are we talking about inside a coderef that's been pushed onto @INC? You could do the require, then redefine Module::import like:

my $orig_import = \&Module::import; *Module::import = sub { my ($module, @list) = @_; # do something here goto $orig_import; };
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: use/import params during require
by bulk88 (Priest) on May 12, 2012 at 16:23 UTC
    No, when the pm file body runs under the require part of use, during the require part, is it possible to see the @_ that will LATER be passed to import(), AFTER the require command is done, DURING the require command? Lets say I am using DynaLoader, and in the global require time space (the one that always ends with "1;") of the PM file want to do
    Local::MyMod->bootstrap( $VERSION, @_);
    and have @_ be the LIST part (or the "import list") of the use command. Is there any way for @_ to be available at global body of the PM file runs during the require part of use or would bootstrap have to be moved into the import sub for the XS BOOT section to see the import list?

      I've played around with caller and Devel::StackTrace, and although code in the "global require time space" (as you put it) can see the frame where it's been required, it can't see the arguments. (Not even by using the DB package.)

      You could potentially fake it - you get given the name of the file that required you, and the line number, so you could try reading your caller's file and parsing it yourself, but that's pretty fragile!

      As you're using XS anyway, it's possible that XS code might have better luck peeking up the call stack. The information must (surely) already be in the op tree, so there may well be a way of teasing it out.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'