Wed, 28 Aug 2024 04:44:05 -0500
add assign types gopls hint too
676 | 1 | package Autofetch; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
681 | 5 | use File::Spec::Functions qw(catfile rel2abs); |
676 | 6 | |
7 | sub fetch { | |
8 | my ($path, $module) = @_; | |
852
cf73e0ff4258
Try 'cpm' before 'cpanm'
Meredith Howard <mhoward@roomag.org>
parents:
690
diff
changeset
|
9 | return if |
cf73e0ff4258
Try 'cpm' before 'cpanm'
Meredith Howard <mhoward@roomag.org>
parents:
690
diff
changeset
|
10 | system('cpm', 'install', -L => $path, $module) == 0; |
676 | 11 | system 'cpanm', -nq, -l => $path, $module; |
12 | } | |
13 | ||
681 | 14 | sub cachepath { |
690
d005acd0e883
also portability improvements
Meredith Howard <mhoward@roomag.org>
parents:
682
diff
changeset
|
15 | catfile(glob('~'), '.cache', 'lib', rel2abs($_[0]) =~ y|/ |-_|r); |
681 | 16 | } |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
17 | |
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
18 | sub modulefy { $_[0] =~ s/\.pm$//r =~ s|/|::|gr } |
676 | 19 | |
682 | 20 | sub import { |
21 | return if our $INSTALLED++; | |
22 | ||
23 | my $path = cachepath($0); | |
24 | my $incpath = catfile($path, 'lib', 'perl5'); | |
676 | 25 | |
682 | 26 | push @INC, $incpath, sub { |
27 | my (undef, $file) = @_; | |
676 | 28 | |
682 | 29 | fetch($path, modulefy($file)); |
676 | 30 | |
682 | 31 | return IO::File->new(catfile($incpath, $file)); |
32 | }; | |
33 | } | |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
34 | |
676 | 35 | 1; |