PAR::SetupProgname - Setup $ENV{PAR_PROGNAME}


PAR documentation Contained in the PAR distribution.

Index


Code Index:

NAME

Top

PAR::SetupProgname - Setup $ENV{PAR_PROGNAME}

SYNOPSIS

Top

PAR guts, beware. Check PAR

DESCRIPTION

Top

Routines to setup the PAR_PROGNAME environment variable. Read the PAR::Environment manual.

The set_progname() subroutine sets up the PAR_PROGNAME environment variable

SEE ALSO

Top

The PAR homepage at http://par.perl.org.

PAR, PAR::Environment

AUTHORS

Top

Audrey Tang <cpan@audreyt.org>, Steffen Mueller <smueller@cpan.org>

http://par.perl.org/ is the official PAR website. You can write to the mailing list at <par@perl.org>, or send an empty mail to <par-subscribe@perl.org> to participate in the discussion.

Please submit bug reports to <bug-par@rt.cpan.org>. If you need support, however, joining the <par@perl.org> mailing list is preferred.

COPYRIGHT

Top


PAR documentation Contained in the PAR distribution.
package PAR::SetupProgname;
$PAR::SetupProgname::VERSION = '1.002';

use 5.006;
use strict;
use warnings;
use Config ();

# for PAR internal use only!
our $Progname = $ENV{PAR_PROGNAME} || $0;

# same code lives in PAR::Packer's par.pl!
sub set_progname {
    require File::Spec;

    if (defined $ENV{PAR_PROGNAME} and $ENV{PAR_PROGNAME} =~ /(.+)/) {
        $Progname = $1;
    }
    $Progname = $0 if not defined $Progname;

    if (( () = File::Spec->splitdir($Progname) ) > 1 or !$ENV{PAR_PROGNAME}) {
        if (open my $fh, $Progname) {
            return if -s $fh;
        }
        if (-s "$Progname$Config::Config{_exe}") {
            $Progname .= $Config::Config{_exe};
            return;
        }
    }

    foreach my $dir (split /\Q$Config::Config{path_sep}\E/, $ENV{PATH}) {
        next if exists $ENV{PAR_TEMP} and $dir eq $ENV{PAR_TEMP};
        my $name = File::Spec->catfile($dir, "$Progname$Config::Config{_exe}");
        if (-s $name) { $Progname = $name; last }
        $name = File::Spec->catfile($dir, "$Progname");
        if (-s $name) { $Progname = $name; last }
    }
}


1;

__END__