Perl6::Slurp::Interpret - Interpret slurped files
use Perl6::Slurp::Interpret; my $colums = "Name, Birthdate"; my $table = "Customer"; #### Use with regular file ... #### my $interpreted = eval_slurp( $filename ); #### Use e.g. with Inline::Files #### use Inline::Files; my $sql = eval_slurp( \*SQL ); # Or any other token name # Now do something useful with $sql __SQL__ SELECT $columns FROM $table
WARNING: This module allows code injection. Use with Caution
Perl6::Slurp::Interpret exports two functions, eval_slurp and quote_slurp. Both functions slurp in a file and quote them. eval_slurp takes the additional step of eval'ing in the caller's namespace, e.g. global symbols will be interpolated.
The module was predominantly designed with Inline::Files in mind. It can be used as seperatng content from code but not at the expense multiple external files. It is a more elegant approach to the <<"HEREDOC" practice commonly found in Perl programs.
The power of such an approach should be striking to anyone who has written scripts that interact to any number of external programs or processes. eval_slurp'd files can be passed to function or system calls.
eval_slurp passes all it's arguments to Perl6::Slurp. So it is possible to slurp anything that Perl6::Slurp slurps. Perl6::Slurp's magic works...and the result is eval'd in the current scope.
It's a one line function. That's it.
This modules presents a serious security risk since it evals an external, possibly user supplied file. Do not use this module if you:
* Do not know what you are doing.
* Cannot insure that friendliness of the slurped file or environment.
* Create a quoted and an unquoted version?
** eval_slurp_quoted ... evals Perl code.
* Make the eval in the namespace more robust.
Inline::Files, Perl6::Slurp, Inline::TT
Copyright (C) 2007 by Christopher Brown
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.