-
Notifications
You must be signed in to change notification settings - Fork 213
/
minicpan
46 lines (37 loc) · 1.32 KB
/
minicpan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name 'minicpan';
description 'fallback to local minicpan when a dist is not found';
author 'Tatsuhiko Miyagawa';
api_version 0.1;
my $minicpan_rc = File::Spec->catfile($ENV{HOME}, ".minicpanrc");
my $minicpan_home = find_home($minicpan_rc) || File::Spec->catfile($ENV{HOME}, "minicpan");
hook search_module => 100, sub {
my $args = shift;
my $pkgs = File::Spec->catfile($minicpan_home, "modules", "02packages.details.txt.gz");
unless (-e $pkgs) {
$args->{app}->diag("! $pkgs not found. Configure $minicpan_rc correctly. mnicpan plugin is disabled.\n");
return;
}
push @{$args->{uris}}, sub {
require IO::Zlib;
my $fh = IO::Zlib->new($pkgs, 'rb') or return;
$args->{app}->chat("Scanning $pkgs to find $args->{module}...\n");
while (<$fh>) {
my($module, $ver, $dist) = split /\s+/, $_;
if ($module eq $args->{module}) {
$args->{app}->chat("Found $module on minicpan index: $dist\n");
return "file://" . File::Spec->catfile($minicpan_home, "authors", "id", $dist);
}
}
return;
};
return;
};
sub find_home {
my $rc = shift;
return unless -e $rc;
open my $fh, "<$rc" or return;
while (<$fh>) {
/^local:\s+(.*?)\s*$/ and return $1;
}
return;
}