NAME
Devel::PreProcessor - Module inlining and other Perl source manipulations
SYNOPSIS
From a command line,
sh> perl Devel/PreProcessor.pm -Flags sourcefile > targetfile
Or in a Perl script,
use Devel::PreProcessor qw( Flags );
select(OUTPUTFH);
Devel::PreProcessor::parse_file( $source_pathname );
DESCRIPTION
This package processes Perl source files and outputs a modified version acording to several user-setable option flags, as detailed below.
Each of the flag names listed below can be used as above, with a hyphen on the command line, or as one of the arguments in an import statement. Each of these flags are mapped to the scalar package variable of the same name.
- Includes
-
If true, parse_file will attempt to replace
use
andrequire
statements with inline declarations containg the source of the relevant library found in the current @INC. The resulting script should operate identically and no longer be dependant on external libraries (but see compatibility note below).If a
use libs ...
statement is encountered in the source, the library path arguments are evaluated and pushed onto @INC at run-time to enable inclusion of libraries from these paths. - ShowFileBoundaries
-
If true, comment lines will be inserted delimiting the start and end of each inlined file.
- StripPods
-
If true, parse_file will not include POD from the source files. All groups of lines resembling the following will be discarded:
=(pod|head1|head2) ... =cut
- StripBlankLines
-
If true, parse_file will skip lines that are empty, or that contain only whitespace.
- StripComments
-
If true, parse_file will not include full-line comments from the source files. Only lines that start with a pound sign are discarded; this behaviour might not match Perl's parsing rules in some cases, such as multiline strings.
- Conditionals
-
If true, parse_file will utilize a simple conditional inclusion scheme, as follows.
#__CONDITIONAL__ if expr ... #__CONDITIONAL__ endif
The provided Perl expression is evaluated, and unless it is true, everything up to the next endif declaration is replaced with empty lines. In order to allow the default behavour to be provided when running the raw files, comment out lines in non-default branches with the following:
#__CONDITIONAL__ ...
Empty lines are used in place of skipped blocks to make line numbers come out evenly, but conditional use or require statements will throw the count off, as we don't pad by the size of the file that would have been in-lined.
The conditional functionality can be combined with Perl's
-s
switch, which allows you to set flags on the command line, such as:perl -s Devel/PreProcessor.pm -Conditionals -Switch filter.test
You can use any name for your switch, and the matching scalar variable will be set true; the following code will only be used if you supply the argument as shown below.
#__CONDITIONAL__ if $Switch #__CONDITIONAL__ print "you hit the switch!\n"; #__CONDITIONAL__ endif
EXAMPLES
To inline all used modules:
perl -s Devel/PreProcessor.pm -Includes foo.pl > foo_complete.pl
To count the lines of Perl source in a file, run the preprocessor from a shell with the following options
perl -s Devel/PreProcessor.pm -StripComments -StripPods -StripBlankLines foo.pl | wc -l
BUGS AND CAVEATS
- Compatibility: Includes
-
Libraries inlined with Includes may not be appropriate on another system, eg, if Config is inlined, the script may fail if run on a platform other than that on which it was built.
- Bug: Use statements can't span lines
-
Should support newline in import blocks for multiline use statements.
- Limitation: No support for unimporting with "no" statements.
-
Should be mapped to unimport statements. Correct handling of pragmas to be determined.
- Limitation: Autosplit files not included
-
It should be possible to find and include autosplit file fragments.
- Limitation: XSUB files not included
-
There's not much we can do about XSub/PLL files.
- Bug: __DATA__ lost
-
We should really preserve the __DATA__ block from the original source file.
PREREQUISITES AND INSTALLATION
This package should run on any standard Perl 5 installation.
You may retrieve this package from the below URL: http://www.evoscript.com/dist/Devel-PreProcessor-1998.0919.tar.gz
To install this package, download and unpack the distribution archive, then:
perl Makefile.PL
make test
make install
STATUS AND SUPPORT
This release of Devel::PreProcessor is intended for public review and feedback. It has been tested in several environments and no major problems have been discovered, but it should be considered "alpha" pending that feedback.
Name DSLI Description
-------------- ---- ---------------------------------------------
Devel::
::PreProcessor adpf Module inlining and other Perl source manipulations
Further information and support for this module is available at <www.evoscript.com>.
Please report bugs or other problems to <bugs@evoscript.com>.
AUTHORS AND COPYRIGHT
Copyright 1998, 1999 Evolution Online Systems, Inc. <www.evolution.com>
You may use this software for free under the terms of the Artistic License.
Contributors: M. Simon Cavalletto <simonm@evolution.com>, with feature suggestions from Del Merritt <dmerritt@intranetics.com> and Win32 debugging assistance from Randy Roy.
Derived from filter.pl, as provided by ActiveWare <www.activestate.com>