.lib/perl5/Autofetch.pm

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

mercurial