Sun, 15 Jul 2018 17:25:15 -0500
Fix for mucomplete + endwise
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) = @_; | |
9 | system 'cpanm', -nq, -l => $path, $module; | |
10 | } | |
11 | ||
681 | 12 | sub cachepath { |
690
d005acd0e883
also portability improvements
Meredith Howard <mhoward@roomag.org>
parents:
682
diff
changeset
|
13 | catfile(glob('~'), '.cache', 'lib', rel2abs($_[0]) =~ y|/ |-_|r); |
681 | 14 | } |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
15 | |
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
16 | sub modulefy { $_[0] =~ s/\.pm$//r =~ s|/|::|gr } |
676 | 17 | |
682 | 18 | sub import { |
19 | return if our $INSTALLED++; | |
20 | ||
21 | my $path = cachepath($0); | |
22 | my $incpath = catfile($path, 'lib', 'perl5'); | |
676 | 23 | |
682 | 24 | push @INC, $incpath, sub { |
25 | my (undef, $file) = @_; | |
676 | 26 | |
682 | 27 | fetch($path, modulefy($file)); |
676 | 28 | |
682 | 29 | return IO::File->new(catfile($incpath, $file)); |
30 | }; | |
31 | } | |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
32 | |
676 | 33 | 1; |