File Coverage

blib/lib/PAR/SetupProgname.pm
Criterion Covered Total %
statement 18 31 58.0
branch 6 18 33.3
condition 3 9 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 32 64 50.0


line stmt bran cond sub pod time code
1             package PAR::SetupProgname;
2             $PAR::SetupProgname::VERSION = '1.002';
3              
4 4     4   68 use 5.006;
  4         14  
5 4     4   21 use strict;
  4         7  
  4         86  
6 4     4   26 use warnings;
  4         18  
  4         109  
7 4     4   21 use Config ();
  4         6  
  4         1484  
8              
9             =head1 NAME
10              
11             PAR::SetupProgname - Setup $ENV{PAR_PROGNAME}
12              
13             =head1 SYNOPSIS
14              
15             PAR guts, beware. Check L
16              
17             =head1 DESCRIPTION
18              
19             Routines to setup the C environment variable.
20             Read the C manual.
21              
22             The C subroutine sets up the C
23             environment variable
24              
25             =cut
26              
27             # for PAR internal use only!
28             our $Progname = $ENV{PAR_PROGNAME} || $0;
29              
30             # same code lives in PAR::Packer's par.pl!
31             sub set_progname {
32 7     7 0 44 require File::Spec;
33              
34 7 100 66     47 if (defined $ENV{PAR_PROGNAME} and $ENV{PAR_PROGNAME} =~ /(.+)/) {
35 3         9 $Progname = $1;
36             }
37 7 50       27 $Progname = $0 if not defined $Progname;
38              
39 7 50 33     100 if (( () = File::Spec->splitdir($Progname) ) > 1 or !$ENV{PAR_PROGNAME}) {
40 7 50       330 if (open my $fh, $Progname) {
41 7 50       175 return if -s $fh;
42             }
43 0 0         if (-s "$Progname$Config::Config{_exe}") {
44 0           $Progname .= $Config::Config{_exe};
45 0           return;
46             }
47             }
48              
49 0           foreach my $dir (split /\Q$Config::Config{path_sep}\E/, $ENV{PATH}) {
50 0 0 0       next if exists $ENV{PAR_TEMP} and $dir eq $ENV{PAR_TEMP};
51 0           my $name = File::Spec->catfile($dir, "$Progname$Config::Config{_exe}");
52 0 0         if (-s $name) { $Progname = $name; last }
  0            
  0            
53 0           $name = File::Spec->catfile($dir, "$Progname");
54 0 0         if (-s $name) { $Progname = $name; last }
  0            
  0            
55             }
56             }
57              
58              
59             1;
60              
61             __END__