Skip to content
Browse files

Add system with string rather than list examples.

  • Loading branch information...
1 parent 032a84e commit b12a95bbb9a0370aaff796f1062f696988675cb6 Rocky Bernstein committed Aug 30, 2012
Showing with 38 additions and 16 deletions.
  1. +17 −8 README.pod
  2. +18 −8 lib/Perl/Syntax.pm
  3. +3 −0 t/01-test.t
View
25 README.pod
@@ -7,17 +7,22 @@ Perl::Syntax -- Syntax Check Perl files and strings
=head1 Summary
This module syntax checks Perl files and strings. It is identical
-to running C<perl -c ...>, but you have more control over the output that
-Perl produces.
+to running C<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
@@ -26,10 +31,14 @@ 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=my/output-file.txt perl-program.pl
+ 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 I<output-file.txt> will have either the messages Perl normally produces on
-C<STDERR>:
+File I</tmp/output-file.txt> will have either the messages Perl
+normally produces on C<STDERR>:
XXXX syntax OK
@@ -57,9 +66,9 @@ or
=head1 Bugs/Caveats
-Inside Perl, it is important not to use the one argument string form
-of I<system()>, because that will sometimes not fork code and then you
-might find your C<STDERR> messed up.
+There doesn't seem to be much benefit here over using C<perl -c> with
+C<STDERR> redirected. What I really want is a kind of eval that just
+does the syntax checking.
=head1 Author
View
26 lib/Perl/Syntax.pm
@@ -31,6 +31,7 @@ unless (caller) {
my $basename = File::Basename::basename(__FILE__);
chdir $dirname;
my @prefix = ("$^X", '-I..', "-MPerl::Syntax");
+ system("$^X -I.. -MPerl::Syntax $basename");
system(@prefix, $basename);
printf("Perl file $basename does %ssyntax check okay.\n",
$?>>8 ? 'not ' : '');
@@ -64,17 +65,22 @@ Perl::Syntax -- Syntax Check Perl files and strings
=head1 Summary
This module syntax checks Perl files and strings. It is identical
-to running C<perl -c ...>, but you have more control over the output that
-Perl produces.
+to running C<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
@@ -83,10 +89,14 @@ 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=my/output-file.txt perl-program.pl
+ 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 I<output-file.txt> will have either the messages Perl normally produces on
-C<STDERR>:
+File I</tmp/output-file.txt> will have either the messages Perl
+normally produces on C<STDERR>:
XXXX syntax OK
@@ -114,9 +124,9 @@ or
=head1 Bugs/Caveats
-Inside Perl, it is important not to use the one argument string form
-of I<system()>, because that will sometimes not fork code and then you
-might find your C<STDERR> messed up.
+There doesn't seem to be much benefit here over using C<perl -c> with
+C<STDERR> redirected. What I really want is a kind of eval that just
+does the syntax checking.
=head1 Author
View
3 t/01-test.t
@@ -27,6 +27,9 @@ test_rc(0, "1+2 is a syntactically valid Perl expression" );
system(@prefix, '-e', '1+');
test_rc(1, "1+ is not a syntactically invalid Perl expression" );
+system("$EXECUTABLE_NAME -I../lib -MPerl::Syntax $short_name");
+test_rc(0, "run system with a string" );
+
diag("Testing Temporary file contents");
my ($fh, $tempfile) = tempfile('SyntaxXXXX', SUFFIX=>'.log',

0 comments on commit b12a95b

Please sign in to comment.
Something went wrong with that request. Please try again.