Okay, I have a C application that needs to execute fragments of Perl script provided by the user.

I have successfully embedded the Perl interpreter, and it is working great. The next step is to provide the ability for the user to make calls into my C program to get certain information, take certain actions, etc. I have written an extension using SWIG, and built that into my program as well. After constructing my perl interpreter, with the appropriate xs_init function that adds my DynTrans as a static XSUB, I immediately use:

eval_pv("use DynTrans;", FALSE);
To get my custom functions into the perl interpreter's namespace. This all works correctly, and I can call into my C program from the Perl script.

So, the problem: In order for this to work, I have to have DynTrans.pm in the directory where I run my application. I want to remove this requirement, I want the entire application to be completely self-contained. I have gone so far as to modify my code like this:

perl_setup_module(); eval_pv("use DynTrans;", FALSE); perl_cleanup_module();

The perl_setup_module creates the DynTrans.pm file, and the perl_cleanup_module deletes it, and this also works. However I don't like the fact of needing to drop a temporary file on the user's filesystem.

So, the question: Is there a way that I can make XSUBs availiable to my perl interpreter without having to have the .pm file around at all?
I tried building the entire .pm file into my application with a series of eval_pv() for every line, but of course that didn't work.

What I would really like is a programatic interface into whatever the use DynTrans; perl stuff does. I have read and re-read perlembed, perlxs, perlguts, perlapi, perlcall, several perl books, forums, SuperSearch, etc. and I cannot find a way to do this.

Can anyone save me from the dreaded .pm file? Thanks in advance.


In reply to Extending an embedded Perl interpreter without a .pm file by ShodadVenturi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.