Skip to content

Commit cf369d4

Browse files
author
Chris White
committed
Added parameter passing to the script from cmdline
Implements the -s option to fill `%DEF` from the command line.
1 parent 510bfe2 commit cf369d4

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

perlpp.pl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,20 @@ sub Main {
434434
StartOB();
435435
print "package PPP_${Package};\nuse strict;\nuse warnings;\n";
436436

437-
# TODO transfer parameters from the command line to the processed file.
437+
# Transfer parameters from the command line (-s) to the processed file.
438438
# Per commit 7bbe05c, %DEF is for those parameters.
439-
print "my %DEF = ();\n";
439+
print "my %DEF = (\n";
440+
for my $defname (keys %{$opts{DEFS}}) {
441+
print " $defname => ", ${$opts{DEFS}}{$defname}, "\n";
442+
}
443+
print ");\n";
440444

445+
# Initial code from the command line, if any
441446
print $opts{EVAL}, "\n" if $opts{EVAL};
442447

448+
# The input file
443449
ProcessFile( $opts{INPUT_FILENAME} );
450+
444451
my $script = EndOB(); # The generated Perl script
445452

446453
if ( $opts{DEBUG} ) {

t/cmdline.t

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Tests of perlpp command-line options
33
use strict;
44
use warnings;
5-
use Test::More;
5+
use Test::More 'no_plan';
66
use IPC::Run3;
77
use constant CMD => 'perl perlpp.pl';
88

@@ -18,9 +18,15 @@ my @testcases=(
1818
['--eval \'my $foo=42;\'','<?= $foo ?>', qr/^42$/],
1919
['-d -e \'my $foo=42;\'','<?= $foo ?>', qr/^my \$foo=42;/m],
2020
['--debug --eval \'my $foo=42;\'','<?= $foo ?>', qr/^print\s+\$foo\s*;/m],
21+
['-s foo=1', '<?= $DEF{foo} ?>',qr/^1$/],
22+
['-s foo=\"blah\"', '<?= $DEF{foo} ?>',qr/^blah$/],
23+
# Have to escape the double-quotes so perl sees it as a string
24+
# literal instead of a bareword.
2125
); #@testcases
2226

23-
plan tests => scalar @testcases;
27+
#plan tests => scalar @testcases;
28+
# TODO count the out_re and err_re in @testcases, since the number of
29+
# tests is the sum of those counts.
2430

2531
for my $lrTest (@testcases) {
2632
my ($opts, $testin, $out_re, $err_re) = @$lrTest;

0 commit comments

Comments
 (0)