.lib/perl5/Autofetch.pm

Wed, 14 Feb 2018 12:22:19 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Wed, 14 Feb 2018 12:22:19 -0500
changeset 677
15d353917450
parent 676
1b5b084bccbb
child 678
4c569c2420f1
permissions
-rw-r--r--

try using autofetch

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

mercurial