App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/Paths.pm  view on Meta::CPAN

    $self->setup_resdirs;

    # Check for packaged image.
    for ( qw( OCI Docker AppImage PPL ) ) {
	next unless exists $ENV{uc($_)."_PACKAGED"}
	  && $ENV{uc($_)."_PACKAGED"};
	$packager = $_;
	last;
    }

};

# We need this to be able to re-establish the resdirs, e.g. after a change
# of CHORDPRO_LIB.
method setup_resdirs {
    $resdirs = [];
    my @try = ();
    push( @try, $self->path($ENV{CHORDPRO_LIB}) )
      if defined($ENV{CHORDPRO_LIB});
    push( @try, $configdir ) if $configdir;
    push( @try, $INC{'ChordPro.pm'} =~ s/\.pm$/\/res/r );

    for ( @try ) {
	next unless $_;
	my $path = $self->normalize($_);
	warn("Paths: resdirs try $_ => $path\n") if $self->debug > 1;
	next unless $path && fs_test( d => $path );
	push( @$resdirs, $path );
    }

    if ( $self->debug ) {
	for ( 0..$#{$resdirs} ) {
	    warn("Paths: resdirs[$_] = $resdirs->[$_]\n");
	}
    }

    unless ( @$resdirs ) {
	warn("Paths: Cannot find resources, prepare for disaster\n");
    }
}

method debug {
    # We need to take an env var into account, since the Paths
    # singleton is created far before any config processing.
    $ENV{CHORDPRO_DEBUG_PATHS} || $::config->{debug}->{paths} || 0;
}

# Is absolute.

method is_absolute ( $p ) {
    fn_is_absolute( $p );
}

# Is bare (no volume/dir).

method is_here ( $p ) {
    my ( $v, $d, $f ) = fn_splitpath($p);
    $v eq '' && ( $d eq '' || $d =~ /^\.[\\\/]/ );
}

# Normalize - full path, forward slashes, ~ expanded.

method normalize ( $p, %opts ) {
    $p = $home . "/$1" if $p =~ /~[\\\/](.*)/;
    realpath($p)
}

# This is only used in ::runtimeinfo for display purposes.

method display ( $p ) {
    return "<undef>" unless defined $p;
    $p = $self->normalize($p);
    if ( index( $p, $home ) == 0 ) {
	substr( $p, 0, length($home), '~' );
    }
    return $p;
}

method path ( $p = undef ) {
    if ( defined($p) ) {
	local $ENV{PATH} = $p;
	my @p = File::Spec->path();
	# On MSWindows, '.' is always prepended.
	shift(@p) if is_msw;
	return @p;
    }
    return File::Spec->path();
}

# Prepend/append dirs to path.

method pathprepend( @d ) {
    $ENV{PATH} = $self->pathcombine( @d, $ENV{PATH} );
}

method pathappend( @d ) {
    $ENV{PATH} = $self->pathcombine( $ENV{PATH}, @d );
}

method pathcombine( @d ) {
    join( $pathsep, @d );
}

# Locate an executable file (program) using PATH.

method findexe ( $p, %opts ) {
    my $try = $p;
    my $found;
    if ( is_msw ) {
	$try .= ".exe";
    }

    if ( fn_is_absolute($p)
	 && ChordPro::Files::fs_test( fx => $p ) ) {
	warn("Paths: findexe $p => ", $self->display($p), "\n")
	  if $self->debug;
	return $p;
    }

    for ( $self->path ) {
	my $e = fn_catfile( $_, $try );



( run in 0.479 second using v1.01-cache-2.11-cpan-5b529ec07f3 )