in reply to Re^5: XS: use module into package
in thread XS: use module into package

Well, I was thinking of doing this during compilation, ie in a BEGIN code block or in my import sub. For instance:
package Mycaller; use MyModule; ...

That way MyModule would be called during compilation, even pefore the rest of the calling module has even been parsed.

My intention is to make the caller package use something else... without an eval.

Replies are listed 'Best First'.
Re^7: XS: use module into package
by ikegami (Patriarch) on Jun 13, 2011 at 20:56 UTC
    What about eval do you want to avoid?
      I'm just trying to replicate use as it is internally for perl, so I can make it work with things like use feature 'say', which don't work with an eval qq{package $callerpkg; use feature 'say'}, but do if I use a goto &feature::import.

      Nothing against eval, I just think that the behaviour is inconsistent for lexical "uses".

        I'm just trying to replicate use as it is internally for perl

        use is a compiler directive to immediately do a require and (possibly) import.

        To replicate that, your code would need to be parsing Perl code. Your statement makes no sense.

        but do if I use a goto &feature::import.

        «goto &feature::import» has no resemblance to «eval 'package Package; use Module;'» and has nothing to do with «use»!!!

        This is getting silly. You have yet to communicate what problem you are trying to solve. When you figure it out, you should start a new thread.

        Nothing against eval, I just think that the behaviour is inconsistent for lexical "uses".

        What do you think use does with the code it loads? It evals it.

Re^7: XS: use module into package
by ikegami (Patriarch) on Jun 13, 2011 at 20:36 UTC

    My intention is to make the caller package use something else... without an eval

    Again, package is a compiler directive. That means you need to invoke the compiler (eval).