.lib/perl5/Autofetch.pm

Fri, 26 Nov 2021 00:12:00 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 26 Nov 2021 00:12:00 -0600
changeset 959
4a5aaef00594
parent 852
cf73e0ff4258
permissions
-rw-r--r--

try a personal config

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) = @_;
852
cf73e0ff4258 Try 'cpm' before 'cpanm'
Meredith Howard <mhoward@roomag.org>
parents: 690
diff changeset
9 return if
cf73e0ff4258 Try 'cpm' before 'cpanm'
Meredith Howard <mhoward@roomag.org>
parents: 690
diff changeset
10 system('cpm', 'install', -L => $path, $module) == 0;
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 system 'cpanm', -nq, -l => $path, $module;
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 }
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13
681
a478dd55388a more portable
Meredith Howard <mhoward@roomag.org>
parents: 678
diff changeset
14 sub cachepath {
690
d005acd0e883 also portability improvements
Meredith Howard <mhoward@roomag.org>
parents: 682
diff changeset
15 catfile(glob('~'), '.cache', 'lib', rel2abs($_[0]) =~ y|/ |-_|r);
681
a478dd55388a more portable
Meredith Howard <mhoward@roomag.org>
parents: 678
diff changeset
16 }
678
4c569c2420f1 oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents: 676
diff changeset
17
4c569c2420f1 oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents: 676
diff changeset
18 sub modulefy { $_[0] =~ s/\.pm$//r =~ s|/|::|gr }
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
20 sub import {
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
21 return if our $INSTALLED++;
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
22
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
23 my $path = cachepath($0);
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
24 my $incpath = catfile($path, 'lib', 'perl5');
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
26 push @INC, $incpath, sub {
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
27 my (undef, $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 fetch($path, modulefy($file));
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30
682
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
31 return IO::File->new(catfile($incpath, $file));
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
32 };
31d13f6d3a30 make inline-friendly
Meredith Howard <mhoward@roomag.org>
parents: 681
diff changeset
33 }
678
4c569c2420f1 oh, add the cache path too
Meredith Howard <mhoward@roomag.org>
parents: 676
diff changeset
34
676
1b5b084bccbb add Autofetch
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 1;

mercurial