I found another way with The-bind()-Function of Inline which works fine for multiple code blocks and recovers from previous bad configuration. Unfortunately there is a caveat mentioned in the documentation, which I did not understand:

Although bind() is a powerful feature, it is not recommended for use i +n Inline based modules. In fact, it won't work at all for installable + modules.

This is how I use bind() with code and configuration:

use Inline; Inline->bind( CUDA => $code, BUILD_NOISY => 1, clean_after_build => 0, warnings => 10, );

And it is happy inside eval or try/catch (Try::Tiny).

I was thinking about this and realised that one can have multiple Inline code blocks. I have tried it and also within eval and try/catch and they work except that if a configuration fails (for my tests) then it sticks with it and does not seem to re-configure. Using bind() as above seems to recover from previous bad compilations.

Inline's preferred way is to specify the code in a BEGIN block and then use Inline => ... which does not allow for inlining code dynamically. bind() does.

PS: I have also asked the author a question here


In reply to Re^2: catch "use Inline::C" death - multiple+dynamic code blocks by bliako
in thread catch "use Inline::C" death by bliako

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.