.lib/perl5/Autofetch.pm

Sat, 16 Mar 2019 18:43:43 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 16 Mar 2019 18:43:43 -0400
changeset 749
27f7431c8170
parent 690
d005acd0e883
child 852
cf73e0ff4258
permissions
-rw-r--r--

Fix up gpg stuff

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 {
690
d005acd0e883 also portability improvements
Meredith Howard <mhoward@roomag.org>
parents: 682
diff changeset
13 catfile(glob('~'), '.cache', 'lib', rel2abs($_[0]) =~ y|/ |-_|r);
681
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