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

You can't go and change the package the parent Perl code was compiled into. You have to create new code and have it executed by Perl. Perl code gets compiled into ops, not API calls. package itself doesn't even result in an op because it's compiler directive. It changes the package Perl code gets compiled into.

Replies are listed 'Best First'.
Re^6: XS: use module into package
by Anonymous Monk on Jun 13, 2011 at 19:55 UTC
    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.

      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".

      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).