.lib/perl5/Autofetch.pm

Sat, 17 Feb 2018 02:05:23 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 17 Feb 2018 02:05:23 -0500
changeset 685
691e15efff36
parent 682
31d13f6d3a30
child 690
d005acd0e883
permissions
-rw-r--r--

add a few more files to copy, simplify

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;
681
a478dd55388a more portable
Meredith Howard <mhoward@roomag.org>
parents: 678
diff changeset
5 use File::Spec::Functions qw(catfile rel2abs);
676
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
681
a478dd55388a more portable
Meredith Howard <mhoward@roomag.org>
parents: 678
diff changeset
12 sub cachepath {
a478dd55388a more portable
Meredith Howard <mhoward@roomag.org>
parents: 678
diff changeset
13 catfile($ENV{HOME}, '.cache', 'lib', rel2abs($_[0]) =~ y|/ |-_|r);
a478dd55388a more portable
Meredith Howard <mhoward@roomag.org>
parents: 678
diff changeset
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
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
18 sub import {
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
19 return if our $INSTALLED++;
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
20
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
21 my $path = cachepath($0);
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
22 my $incpath = catfile($path, 'lib', 'perl5');
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
24 push @INC, $incpath, sub {
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
25 my (undef, $file) = @_;
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
27 fetch($path, modulefy($file));
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
29 return IO::File->new(catfile($incpath, $file));
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
30 };
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
31 }
678
4c569c2420f1 oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents: 676
diff changeset
32
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 1;

mercurial