Changeset 1127 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/Base.pm


Ignore:
Timestamp:
Dec 21, 2010, 2:37:35 AM (13 years ago)
Author:
Bruno Cornec
Message:
  • Modify pb_check_req interface to return the found value and allow direct call
  • Use pb_check_req to avoid some hardcoded path
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Base.pm

    r1120 r1127  
    3737
    3838our @ISA = qw(Exporter);
    39 our @EXPORT = qw(pb_mkdir_p pb_system pb_rm_rf pb_get_date pb_log pb_log_init pb_get_uri pb_get_content pb_set_content pb_display_file pb_syntax_init pb_syntax pb_temp_init pb_get_arch pb_check_requirements $pbdebug $pbLOG $pbdisplaytype $pblocale);
     39our @EXPORT = qw(pb_mkdir_p pb_system pb_rm_rf pb_get_date pb_log pb_log_init pb_get_uri pb_get_content pb_set_content pb_display_file pb_syntax_init pb_syntax pb_temp_init pb_get_arch pb_check_requirements pb_check_req $pbdebug $pbLOG $pbdisplaytype $pblocale);
    4040
    4141=pod
     
    423423}
    424424
     425=item B<pb_check_req>
     426
     427This function checks existence of a command and return its full pathname.
     428The command name is passed as first parameter.
     429The second parameter should be 0 if the command is mandatory, 1 if optional.
     430
     431=cut
     432
    425433sub pb_check_req {
    426434
    427435my $file = shift;
    428436my $opt = shift || 1;
    429 my $found = 0;
     437my $found = undef;
    430438
    431439pb_log(2,"Checking availability of $file...");
    432440# Check for all dirs in the PATH
    433441foreach my $p (split(/:/,$ENV{'PATH'})) {
    434     $found = 1 if (-x "$p/$file");
    435 }
    436 if ($found eq 0) {
     442    if (-x "$p/$file") {
     443        $found =  "$p/$file";
     444        last;
     445    }
     446}
     447
     448if (not $found) {
    437449    pb_log(2,"KO\n");
    438450    if ($opt eq 1) {
     
    443455} else {
    444456    pb_log(2,"OK\n");
     457    return($found");
    445458}
    446459}
Note: See TracChangeset for help on using the changeset viewer.