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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |