-
-
31 Aug 2012 01:47:57 UTC
- Distribution: Perl-Syntax
- Module version: 1.00
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (1)
- Testers (449 / 90 / 7)
- Kwalitee
Bus factor: 0- % Coverage
- License: open_source
- Perl: v5.8.8
- Activity
24 month- Tools
- Download (6.02KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- rlib
- version
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
Name
Perl::Syntax -- Syntax Check Perl files and strings
Summary
This module syntax checks Perl files and strings. It is identical to running
perl -c ...
, but output doesn't go by default to STDOUT.You run his like this from a command line:
$ perl -MPerl::Syntax perl-program.pl $ perl -MPerl::Syntax -e 'your perl code'
which is like:
$ perl -c perl-program.pl 2>/dev/null $ perl -MPerl::Syntax -e 'your perl code' 2>/dev/null
Or from inside Perl:
system($^X, '-M', 'Perl::Syntax', $perl_program); system("$^X -M Perl::Syntax $perl_program"); # check $?
By default, no output is produced. You will get a zero return code if everything checks out or nonzero if there was a syntax error.
To capture output to a file, you can specify a file name by adding an equal sign after "Perl::Syntax" like this:
perl -MPerl::Syntax=/tmp/output-file.txt perl-program.pl
or inside PerL:
system($^X, '-M', 'Perl::Syntax=/tmp/outfile-file.txt', $perl_program);
File /tmp/output-file.txt will have either the messages Perl normally produces on
STDERR
:XXXX syntax OK
or
syntax error at XXXX line DDDD ... ...
Examples
use English; my @prefix = ($EXECUTABLE_NAME, '-MPerl::Syntax'); # test this Perl code to see if it is syntactically correct; system(@prefix, __FILE__); print "Yep, we're good" unless $? >> 8; # test of invalid Perl code: system(@prefix, '-e', '$Incomplete + $Expression +'; print "Try again" if $? >> 8; # Show capturing output system($EXECUTABLE_NAME, '-MPerl::Syntax=/tmp/Syntax.log', __FILE__); # results are in /tmp/Syntax.log
Bugs/Caveats
There doesn't seem to be much benefit here over using
perl -c
withSTDERR
redirected. What I really want is a kind of eval that just does the syntax checking.Author
Rocky Bernstein
See Also
-c
switch from perlrun#Command-SwitchesCopyright
Copyright (C) 2012 Rocky Bernstein <rocky@cpan.org>
This program is distributed WITHOUT ANY WARRANTY, including but not limited to the implied warranties of merchantability or fitness for a particular purpose.
The program is free software. You may distribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation (either version 2 or any later version) and the Perl Artistic License as published by O'Reilly Media, Inc. Please open the files named gpl-2.0.txt and Artistic for a copy of these licenses.
Module Install Instructions
To install Perl::Syntax, copy and paste the appropriate command in to your terminal.
cpanm Perl::Syntax
perl -MCPAN -e shell install Perl::Syntax
For more information on module installation, please visit the detailed CPAN module installation guide.