@@ -4,7 +4,7 @@ PerlPP: Perl preprocessor
44Translates ** Text+Perl** to ** Text** .
55It can be used for any kind of text templating, e.g. code generation.
66No external modules are required, just a single file.
7- Requires Perl 5.10+.
7+ Requires Perl 5.10.1 +.
88
99PerlPP runs in two passes: it generates a Perl script from your input, and then
1010it runs the generated script. If you see ` error at (eval ##) `
@@ -58,11 +58,11 @@ Perl code is included between `<?` and `?>` tags.
5858There are several modes, indicated by the character after the ` <? ` :
5959
6060 <? code mode: Perl code is between the tags.
61- <?= echo mode: prints a Perl expression
62- <?: internal-command mode: executed by PerlPP itself (see below)
61+ <?= echo mode: prints a Perl expression.
62+ <?: internal-command mode: executed by PerlPP itself.
6363 <?/ code mode, beginning with printing a line break.
6464 <?# comment mode: everything in <?# ... ?> is ignored.
65- <?! external mode: everything in <?! ... ?> is run as an external command
65+ <?! external mode: everything in <?! ... ?> is run as an external command.
6666
6767The code mode is started by ` <? ` followed by any number of whitespaces
6868or line breaks.
@@ -82,11 +82,11 @@ The Generated Script
8282
8383The generated script:
8484
85- - is in its own package, named based on the input filename
86- - ` use ` s ` 5.010 ` , ` strict ` , and ` warnings `
85+ - is in its own package, named based on the input filename and a unique number
86+ - ` use ` s ` 5.010001 ` , ` strict ` , and ` warnings `
8787- provides constants ` true ` (=` !!1 ` ) and ` false ` (=` !!0 ` ) (with ` use constant ` )
88- - Declares ` my %D ` and initializes ` %D ` based on any ** -D** options you provide
89- - Declares ` my %S ` and initializes ` %S ` based on any ** -s** options you provide
88+ - declares ` my %D ` and initializes ` %D ` based on any ** -D** options you provide
89+ - declares ` my %S ` and initializes ` %S ` based on any ** -s** options you provide
9090
9191Other than that, everything in the script comes from your input file(s).
9292Use the ** -E** option to see the generated script.
@@ -159,7 +159,7 @@ So `<?/ ... ?>` is effectively a shorthand for `<? print "\n"; ... ?>`.
159159
160160The example
161161
162- <?!echo Howdy!?>
162+ <?! echo Howdy! ?>
163163
164164produces the output
165165
@@ -203,18 +203,21 @@ In this case words like `fooSomeWord` will become `barSomeWord`.
203203
204204will run ` some_perl_code; ` at the time of script generation. Whatever output
205205the perl code produces will be included verbatim in the script output.
206+ Within ` some_perl_code ` , the current PerlPP instance is available as ` $PSelf ` .
207+
206208This can be used to dynamically select which files you want to include,
207- using the provided ` Include() ` function . For example:
209+ using the provided ` Include() ` method . For example:
208210
209- <?:macro my $fn="some_name"; Include $fn; ?>
211+ <?:macro my $fn="some_name"; $PSelf-> Include( $fn) ; ?>
210212
211213has the same effect as
212214
213215 <?:include some_name ?>
214216
215- but ` $fn ` can be determined programmatically. Note that it is not currently
216- possible to select the filename to ` Include ` based on defines set with ** -D** ,
217- since those do not take effect until the script has been generated.
217+ but ` $fn ` can be determined programmatically. Note that defines set with
218+ ** -D** or ** -s** do not take effect effect until after the script has been
219+ generated, which is after the macro code runs. However, those are available
220+ as hashes ` $PSelf->{Defs} ` and ` $PSelf->{Sets} ` in macro code.
218221
219222Capturing
220223---------
@@ -298,15 +301,16 @@ Tests with `<?:if NAME ... ?>` and `<?:elsif NAME ... ?>` have two restrictions:
298301
299302For example, ` <?:if FOO eq "something" ?> ` (note the whitespace before ` ?> ` !)
300303will work fine. However, if you want to test ` (FOO+1)*3 ` , you will need
301- to use the full Perl code.
304+ to use the full Perl code ` <? if( (FOO+1)*3 == 42 ) { ... } ?> ` instead of
305+ ` <?:if ?> ` and ` <?:endif?> ` .
302306
303307Other Features
304308--------------
305309
306310### Custom Preprocessors
307311
308312It's possible to create your own pre/post-processors in a ` <?:macro ?> ` block
309- using ` PerlPP:: AddPreprocessor` and ` PerlPP:: AddPostprocessor` .
313+ using ` $PSelf-> AddPreprocessor` and ` $PSelf-> AddPostprocessor` .
310314This feature is used in [ BigBenBox] ( https://github.com/d-ash/BigBenBox ) for
311315generating code in the C programming language.
312316
@@ -329,14 +333,6 @@ and create corresponding *~/.vim/after/syntax/FILETYPE.vim*
329333
330334FILETYPE can be determined with ` :set ft? `
331335
332- ## Developing PerlPP
333-
334- Perlpp should run on any Perl v5.10+. However, it does require ` Getopt::Long `
335- v2.50 or higher, so you might have to grab that from CPAN.
336- To run the tests, you also need to grab ` IPC::Run3 ` .
337-
338- The ` Makefile ` just runs the tests in ` t/ ` ; there is no build step.
339-
340336## Copyright
341337
342338Distributed under the MIT license --- see
0 commit comments