Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I want the XS module I'm writing to use a module into my caller's package. Similar to what this classic eval does:

eval qq{ package $caller_package; use $module_to_use; };

I've looked thru the perl source and documentation looking for the correct XS function, but I wasn't able to find anything.

Is there such a function? Could you point me to the correct docs?

'appreciate your help!

-miguel

Replies are listed 'Best First'.
Re: XS: use module into package
by ikegami (Patriarch) on Jun 13, 2011 at 18:17 UTC

    Use the API's eval_sv or eval_pv instead of eval, passing it the same string.

    Update: s/call_/eval_/g

      But is there a use() function somewhere in the Perl API? I'm trying to avoid using eval.

        I don't think so, but it's moot. The reason you had to use eval in code doesn't go away by loading the module using a different interface. You can't go and change the package the parent Perl code was compiled into.