Skip to content

Commit

Permalink
Item9807: Generalize Util::getPerlLocation to extract from any file.
Browse files Browse the repository at this point in the history
along with unit test.  Should be safe for 1.1.1

git-svn-id: http://svn.foswiki.org/trunk@9535 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Oct 8, 2010
1 parent a5516db commit 4e709eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions UnitTestContrib/test/unit/ConfigureTests.pm
Expand Up @@ -802,6 +802,13 @@ sub test_Util_getPerlLocation {
"C:\\Program Files\\Strawberry\\bin\\perl.exe"
);

_makefile( "$tempdir", "loctestf", <<'DONE');
#! /a/b/perl
Test file data
DONE

$this->assert_str_equals( '/a/b/perl', Foswiki::Configure::Util::getPerlLocation("$tempdir/loctestf"));

$Foswiki::cfg{ScriptSuffix} = ".pl";
_doLocationTest( $this, $tempdir, "#!/usr/bin/perl -wT ", "/usr/bin/perl" );

Expand Down
11 changes: 8 additions & 3 deletions core/lib/Foswiki/Configure/Util.pm
Expand Up @@ -533,16 +533,21 @@ sub listDir {
---++ StaticMethod getPerlLocation( )
This routine will read in the first line of the bin/configure
script and recover the location of the perl interpreter.
script and recover the location of the perl interpreter.
Optional parameter is file used to retrieve the shebang. If not
specified, defaults to the configure script
=cut

sub getPerlLocation {

my $file = shift || "$Foswiki::cfg{ScriptDir}/configure$Foswiki::cfg{ScriptSuffix}";

local $/ = "\n";
open( my $fh, '<',
"$Foswiki::cfg{ScriptDir}/configure$Foswiki::cfg{ScriptSuffix}" )
|| return '';
"$file" )
|| return "";
my $Shebang = <$fh>;
chomp $Shebang;
$Shebang =~ s/^#\!\s*(.*?)\s?(:?\s-.*)?$/$1/;
Expand Down

0 comments on commit 4e709eb

Please sign in to comment.