tokuhirom / plenv

Perl binary manager
Other
516 stars 71 forks source link

Respect .perl-version through symlinks? #174

Open Swandog opened 3 years ago

Swandog commented 3 years ago

I'm trying to do something with plenv, and I don't know if I'm approaching it the right way, so I would appreciate some advice.

I have some scripts that I've written. I tend to maintain them in their own git repositories. But I want to make them able to run just by typing the command name. So I give them a shebang of #!/usr/bin/env perl, I set up a ~/bin, added it to my $PATH, and made symlinks to the executable scripts. So far, so good; I can run the commands just by typing their names.

Now, for unimportant reasons, I want to try and use different perls to develop each script. So I try putting a .perl-version file in each repository. Now, when I try running the file in the repository, it runs great; it gets the perl version specified by the .perl-version file.

But here's my problem: when I try running the program using the bare command, it doesn't get the version I want. As far as I can tell, this is because plenv looks for the .perl-version in the directory where the symlink is located (i.e. bin), and not the directory where the actual target is located (the repository).

Am I approaching this the wrong way? What's the best approach to do something like this? I can't put .perl-version in the bin directory because it will be different for different files. Should I make multiple bin directories for different perl versions? Should I write wrapper shell scripts that append the right version for each command? I'd like to avoid having to add each repository to my $PATH...

An example, in case my description was confusing:

pop-os:/home/kswanson/test>find .
.
./bin
./bin/A.pl
./bin/B.pl
./src
./src/A
./src/A/.perl-version
./src/A/script
./src/A/script/A.pl
./src/B
./src/B/.perl-version
./src/B/script
./src/B/script/B.pl
pop-os:/home/kswanson/test>ls -l bin/
total 0
lrwxrwxrwx 1 kswanson kswanson 20 Jul  5 20:11 A.pl -> ../src/A/script/A.pl*
lrwxrwxrwx 1 kswanson kswanson 20 Jul  5 20:11 B.pl -> ../src/B/script/B.pl*
pop-os:/home/kswanson/test>cat src/A/.perl-version 
5.32.1
pop-os:/home/kswanson/test>cat src/A/script/A.pl 
#!/usr/bin/env perl

use English;
print qq($PERL_VERSION\n);
pop-os:/home/kswanson/test>src/A/script/A.pl 
v5.32.1
pop-os:/home/kswanson/test>cat src/B/.perl-version 
5.34.0
pop-os:/home/kswanson/test>cat src/B/script/B.pl 
#!/usr/bin/env perl

use English;
print qq($PERL_VERSION\n);
pop-os:/home/kswanson/test>src/B/script/B.pl 
v5.34.0
pop-os:/home/kswanson/test>export PATH=$(pwd)/bin:$PATH
pop-os:/home/kswanson/test>A.pl 
v5.30.3
pop-os:/home/kswanson/test>B.pl 
v5.30.3

In this case, I would like if the last two commands printed out v5.32.1 and v5.34.0, respectively