Wed, 14 Feb 2018 12:25:53 -0500
oh, add the cache path too
676 | 1 | package Autofetch; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | sub fetch { | |
7 | my ($path, $module) = @_; | |
8 | system 'cpanm', -nq, -l => $path, $module; | |
9 | } | |
10 | ||
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
11 | sub cachepath { "$ENV{HOME}/.cache/lib/" . ($_[0] =~ y|/ |-_|r) } |
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
12 | |
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
13 | sub modulefy { $_[0] =~ s/\.pm$//r =~ s|/|::|gr } |
676 | 14 | |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
15 | my $path = cachepath($0); |
676 | 16 | |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
17 | push @INC, "$path/lib/perl5", sub { |
676 | 18 | my (undef, $file) = @_; |
19 | ||
20 | fetch($path, modulefy($file)); | |
21 | ||
22 | return IO::File->new($path . '/lib/perl5/' . $file); | |
23 | }; | |
678
4c569c2420f1
oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents:
676
diff
changeset
|
24 | |
676 | 25 | 1; |