@@ -4,7 +4,7 @@ PerlPP: Perl preprocessor
4
4
Translates ** Text+Perl** to ** Text** .
5
5
It can be used for any kind of text templating, e.g. code generation.
6
6
No external modules are required, just a single file.
7
- Requires Perl 5.10+.
7
+ Requires Perl 5.10.1 +.
8
8
9
9
PerlPP runs in two passes: it generates a Perl script from your input, and then
10
10
it runs the generated script. If you see ` error at (eval ##) `
@@ -58,11 +58,11 @@ Perl code is included between `<?` and `?>` tags.
58
58
There are several modes, indicated by the character after the ` <? ` :
59
59
60
60
<? 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.
63
63
<?/ code mode, beginning with printing a line break.
64
64
<?# 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.
66
66
67
67
The code mode is started by ` <? ` followed by any number of whitespaces
68
68
or line breaks.
@@ -82,11 +82,11 @@ The Generated Script
82
82
83
83
The generated script:
84
84
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 `
87
87
- 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
90
90
91
91
Other than that, everything in the script comes from your input file(s).
92
92
Use the ** -E** option to see the generated script.
@@ -159,7 +159,7 @@ So `<?/ ... ?>` is effectively a shorthand for `<? print "\n"; ... ?>`.
159
159
160
160
The example
161
161
162
- <?!echo Howdy!?>
162
+ <?! echo Howdy! ?>
163
163
164
164
produces the output
165
165
@@ -203,18 +203,21 @@ In this case words like `fooSomeWord` will become `barSomeWord`.
203
203
204
204
will run ` some_perl_code; ` at the time of script generation. Whatever output
205
205
the 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
+
206
208
This 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:
208
210
209
- <?:macro my $fn="some_name"; Include $fn; ?>
211
+ <?:macro my $fn="some_name"; $PSelf-> Include( $fn) ; ?>
210
212
211
213
has the same effect as
212
214
213
215
<?:include some_name ?>
214
216
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.
218
221
219
222
Capturing
220
223
---------
@@ -298,15 +301,16 @@ Tests with `<?:if NAME ... ?>` and `<?:elsif NAME ... ?>` have two restrictions:
298
301
299
302
For example, ` <?:if FOO eq "something" ?> ` (note the whitespace before ` ?> ` !)
300
303
will 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?> ` .
302
306
303
307
Other Features
304
308
--------------
305
309
306
310
### Custom Preprocessors
307
311
308
312
It'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` .
310
314
This feature is used in [ BigBenBox] ( https://github.com/d-ash/BigBenBox ) for
311
315
generating code in the C programming language.
312
316
@@ -329,14 +333,6 @@ and create corresponding *~/.vim/after/syntax/FILETYPE.vim*
329
333
330
334
FILETYPE can be determined with ` :set ft? `
331
335
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
-
340
336
## Copyright
341
337
342
338
Distributed under the MIT license --- see
0 commit comments