Text::PerlPP - Perl preprocessor: process Perl code within any text file
perlpp [options] [--] [filename]
If no [filename] is given, input will be read from stdin.
Run perlpp --help for a quick reference, or perlpp --man for full docs.
perlpp --help
perlpp --man
Output to filename instead of STDOUT.
In the generated script, set $D{name} to value. The hash %D always exists, but is empty if no -D options are given on the command line.
$D{name}
%D
The name will also be replaced with the value in the text of the file. If value cannot be evaluated, no substitution is made for name.
If you omit the =value, the value will be the constant true (see "The generated script", below), and no text substitution will be performed.
true
This also saves the value, or undef, in the generation-time hash %Text::PerlPP::Defs. This can be used, e.g., to select include filenames depending on -D arguments.
undef
%Text::PerlPP::Defs
See "Definitions", below, for more information.
Evaluate the statement before any other Perl code in the generated script.
Don't evaluate Perl code, just write the generated code to STDOUT. By analogy with the -E option of gcc.
-E
Normally, errors in a !command sequence will terminate further processing. If -k is given, an error message will be printed to stderr, but the script will keep running.
!command
As -D, but:
Does not substitute text in the body of the document;
Saves into %Text::PerlPP::Sets at generation time; and
%Text::PerlPP::Sets
Saves into %S in the generated script.
%S
Full documentation, viewed in your default pager if configured.
Usage help, printed to STDOUT.
Shows just the usage summary
Show the version number of perlpp
-D and -s items may be evaluated in any order --- do not rely on left-to-right evaluation in the order given on the command line.
If your shell strips quotes, you may need to escape them: value must be a valid Perl expression. So, under bash, this works:
perlpp -D name=\"Hello, world!\"
The backslashes (\" instead of ") are required to prevent bash from removing the double-quotes. Alternatively, this works:
\"
"
perlpp -D 'name="Hello, World"'
with the whole argument to -D in single quotes.
Also note that the space after -D is optional, so
perlpp -Dfoo perlpp -Dbar=42
both work.
The code you specify in the input file is in a Perl environment with the following definitions in place:
package PPP_foo; use 5.010; use strict; use warnings; use constant { true => !!1, false => !!0 };
where foo is the input filename, if any, transformed to only include [A-Za-z0-9_].
This preamble requires Perl 5.10, which perlpp itself requires. On the plus side, requring v5.10 gives you // (the defined-or operator) and the builtin say. The preamble also keeps you safe from some basic issues.
//
say
Please report any bugs or feature requests through GitHub, via https://github.com/interpreters/perlpp/issues.
You can find documentation for this module with the perldoc command.
perldoc Text::PerlPP
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Text-PerlPP
CPAN Ratings
http://cpanratings.perl.org/d/Text-PerlPP
Search CPAN
http://search.cpan.org/dist/Text-PerlPP/
Turns out there are about 2^googol modules that do similar things. We think this one works pretty nicely, but here are some others in case you disagree. In no particular order: Text::EP3, Text::Template, Basset::Template, ExtUtils::PerlPP, HTML::EP, PML, Preproc::Tiny, ePerl, iperl.
Andrey Shubin (d-ash at Github; andrey.shubin@gmail.com) and Chris White (cxw42 at Github; cxwembedded@gmail.com).
Copyright 2013-2018 Andrey Shubin and Christopher White.
This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
To install Text::PerlPP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::PerlPP
CPAN shell
perl -MCPAN -e shell install Text::PerlPP
For more information on module installation, please visit the detailed CPAN module installation guide.