I am taking raw Perl in a form (maybe, I might go back to file based code in this case but I'm interested in exploring it this way first). I want do the equivalent of `perl -c` on it because I want to see it's valid without evaling it; which might pollute namespaces or cause other problems. I'm at a bit of a loss where to go with this. In pseudo-code-

my $snippet = $c->request->param("filter"); my $package = __PACKAGE__ . "::" . get_uuid_name(); my $code = "package $package; use strict; use warnings;"; $code .= $snippet; $code .= ";\n1;"; # ... ? my $perl = qx/ which perl /; my $result = qx/ perl -c $code /; # CAN this work? If so, how? I'm a s +hell-tard.

Or can I "safely" eval it and remove it from the @INC by something like delete $INC{$generated_package_name}? I might like to do that so I could deparse or plumb the namespace anyway...?

I realize this is a bit of a fuzzy SOPW but I'm just exploring so looking for any bones, table scraps, or clues.

I'm also thinking of forcing it into a sub so the wrapper puts the user supplied code into "package ...; sub run { my ( $vars, $you, $get ) = @_; YOUR CODE HERE }" etc. I think is safer/easier but I want to allow the user to initialize things in the package for efficiency, sub-classing, whatnot.


In reply to How to do a "perl -c(w)" check instead of an "eval $string" on a code string by Your Mother

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.