Skip to content

Commit 8d80aa4

Browse files
author
Chris White
committed
Find perl even if it lacks $Config{_exe} suffix
Also, cleanup in Makefile.PL, and reporting version in dotted-decimal format even though it's not stored that way. All test/testhere/testpacked tests pass on my 5.26.1 and 5.10.1.
1 parent 57d9258 commit 8d80aa4

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

Makefile.PL

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,36 @@ use warnings;
44
use ExtUtils::MakeMaker;
55
use Config;
66

7-
# Get the filename of the Perl interpreter running this. From perlvar.
8-
my $secure_perl_path = $Config{perlpath};
9-
if ($^O ne 'VMS') {
10-
$secure_perl_path .= $Config{_exe}
11-
unless $secure_perl_path =~ m/$Config{_exe}$/i;
12-
}
7+
# Get the filename of the Perl interpreter running this. Modified from perlvar.
8+
# The -x test is for cygwin or other systems where $Config{perlpath} has no
9+
# extension and $Config{_exe} is nonempty. E.g., symlink perl->perl5.10.1.exe.
10+
# There is no "perl.exe" on such a system.
11+
sub get_perl_filename {
12+
my $secure_perl_path = $Config{perlpath};
13+
if ($^O ne 'VMS') {
14+
$secure_perl_path .= $Config{_exe}
15+
unless (-x $secure_perl_path) ||
16+
($secure_perl_path =~ m/$Config{_exe}$/i);
17+
}
18+
return $secure_perl_path;
19+
} # get_perl_filename()
20+
21+
my $secure_perl_path = get_perl_filename();
1322

1423
sub MY::postamble { # TODO also handle Windows nmake syntax (SET vs. export)
1524
return <<EOT;
1625
authortest:
1726
\tRELEASE_TESTING=1 prove -l xt"
1827
1928
testhere: # Run the tests from lib rather than blib
20-
\tperl -Ilib -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
29+
\t"$secure_perl_path" -Ilib -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
2130
22-
testpacked: pack # Test the packed version
31+
testpacked: pack # Test the packed version.
2332
\tPERLPP_NOUSE=1 PERLPP_PERLOPTS="blib/perlpp" \\
24-
\tperl -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
33+
\t"$secure_perl_path" -Ilib -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
2534
EOT
35+
# Note: testpacked uses -Ilib so that I don't have to conditionally
36+
# use Text::PerlPP in t/lib/PerlPPTest.pm.
2637
} #postamble
2738

2839
WriteMakefile(
@@ -39,15 +50,15 @@ WriteMakefile(
3950
},
4051
BUILD_REQUIRES => {
4152
'App::FatPacker' => '0',
42-
'IPC::Run3' => '0',
43-
'Test::More' => '0',
4453
},
4554
TEST_REQUIRES => {
4655
'Capture::Tiny' => '0',
4756
'Carp' => '0',
4857
'Config' => '0',
4958
'File::Spec' => '0',
59+
'IPC::Run3' => '0',
5060
'rlib' => '0',
61+
'Test::More' => '0',
5162
'Text::ParseWords' => '0',
5263
'Text::Diff' => '0', # for t/03-idempotency.t
5364
},

lib/Text/PerlPP.pm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package Text::PerlPP;
55

6+
# Semantic versioning, packed per Perl rules. Must always be at least one
7+
# digit left of the decimal, and six digits right of the decimal.
68
our $VERSION = '0.500001';
79

810
use 5.010001;
@@ -805,8 +807,9 @@ sub Main {
805807
return EXIT_OK; # TODO report param err vs. proc err?
806808
}
807809

808-
if($self->{Opts}->{PRINT_VERSION}) {
809-
print "PerlPP version $Text::PerlPP::VERSION\n";
810+
if($self->{Opts}->{PRINT_VERSION}) { # print version, raw and dotted
811+
$Text::PerlPP::VERSION =~ m<^([^\.]+)\.(\d{3})(\d{3})>;
812+
printf "PerlPP version %d.%d.%d ($VERSION)\n", $1, $2, $3;
810813
if($self->{Opts}->{PRINT_VERSION} > 1) {
811814
print "Script: $0\nText::PerlPP: $INC{'Text/PerlPP.pm'}\n";
812815
}

t/lib/PerlPPTest.pm

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,29 @@ sub run_perlpp {
5252
#do { (my $args = Dumper($lrArgs)) =~ s/^/##/gm;
5353
#say STDERR "## args:\n$args"; };
5454

55-
if($ENV{PERLPP_PERLOPTS}) {
56-
#my $cmd = join(' ', get_perl_filename(), $ENV{PERLPP_PERLOPTS},
57-
# @$lrArgs);
58-
my $cmd = [get_perl_filename(), shellwords($ENV{PERLPP_PERLOPTS}),
59-
@$lrArgs];
55+
if($ENV{PERLPP_PERLOPTS}) { # Run external perl
56+
state $printed_perl;
57+
58+
my $perl = get_perl_filename();
59+
BAIL_OUT("Cannot find executable perl (tried $perl)") unless -x $perl;
60+
61+
unless($printed_perl) { # Report it once for the sake of the logs
62+
say STDERR "# External perl: {$perl}";
63+
$printed_perl = 1;
64+
}
65+
66+
my $cmd = [$perl, shellwords($ENV{PERLPP_PERLOPTS}), @$lrArgs];
67+
6068
#say STDERR '# running external perl: {', join('|',@$cmd), '}';
6169
$retval = run3($cmd, $refStdin, $refStdout, $refStderr);
6270
#say STDERR "# returned $retval; status $?";
71+
6372
# TODO figure out $?, retval, &c.
6473
# TODO tell the caller if the user hit Ctl-C on the inner perl
6574
# invocation so the caller can abort if desired.
6675
# That seems to be status 2, on my test system.
6776

68-
} else {
77+
} else { # Run perl code under this perl
6978
#say STDERR "# running perlpp internal";
7079
#say STDERR "# redirecting stdin";
7180
open local(*STDIN), '<', $refStdin or die $!;
@@ -90,12 +99,16 @@ sub run_perlpp {
9099
return $retval;
91100
} #run_perlpp
92101

93-
# Get the filename of the Perl interpreter running this. From perlvar.
102+
# Get the filename of the Perl interpreter running this. Modified from perlvar.
103+
# The -x test is for cygwin or other systems where $Config{perlpath} has no
104+
# extension and $Config{_exe} is nonempty. E.g., symlink perl->perl5.10.1.exe.
105+
# There is no "perl.exe" on such a system.
94106
sub get_perl_filename {
95107
my $secure_perl_path = $Config{perlpath};
96108
if ($^O ne 'VMS') {
97109
$secure_perl_path .= $Config{_exe}
98-
unless $secure_perl_path =~ m/$Config{_exe}$/i;
110+
unless (-x $secure_perl_path) ||
111+
($secure_perl_path =~ m/$Config{_exe}$/i);
99112
}
100113
return $secure_perl_path;
101114
} # get_perl_filename()

0 commit comments

Comments
 (0)