675:55a3eaa98525 | 676:1b5b084bccbb |
---|---|
1 package Autofetch; | |
2 | |
3 use strict; | |
4 use warnings; | |
5 use 5.010; | |
6 | |
7 sub fetch { | |
8 my ($path, $module) = @_; | |
9 system 'cpanm', -nq, -l => $path, $module; | |
10 } | |
11 | |
12 sub cachepath { | |
13 $ENV{HOME} . '/.cache/lib/' . ($_[0] =~ y|/ |-_|r); | |
14 } | |
15 | |
16 sub modulefy { | |
17 $_[0] =~ s/\.pm$//r =~ s|/|::|gr; | |
18 } | |
19 | |
20 push @INC, sub { | |
21 my (undef, $file) = @_; | |
22 state $path = cachepath($0); | |
23 | |
24 fetch($path, modulefy($file)); | |
25 | |
26 return IO::File->new($path . '/lib/perl5/' . $file); | |
27 }; | |
28 | |
29 1; |