more portable

Thu, 15 Feb 2018 14:29:14 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Thu, 15 Feb 2018 14:29:14 -0500
changeset 681
a478dd55388a
parent 680
b89661b25b51
child 682
31d13f6d3a30

more portable

.lib/perl5/Autofetch.pm file | annotate | diff | comparison | revisions
--- a/.lib/perl5/Autofetch.pm
+++ b/.lib/perl5/Autofetch.pm
@@ -2,24 +2,28 @@ package Autofetch;
 
 use strict;
 use warnings;
+use File::Spec::Functions qw(catfile rel2abs);
 
 sub fetch {
   my ($path, $module) = @_;
   system 'cpanm', -nq, -l => $path, $module;
 }
 
-sub cachepath { "$ENV{HOME}/.cache/lib/" . ($_[0] =~ y|/ |-_|r) }
+sub cachepath {
+  catfile($ENV{HOME}, '.cache', 'lib', rel2abs($_[0]) =~ y|/ |-_|r);
+}
 
 sub modulefy { $_[0] =~ s/\.pm$//r =~ s|/|::|gr }
 
-my $path = cachepath($0);
+my $path    = cachepath($0);
+my $incpath = catfile($path, 'lib', 'perl5');
 
-push @INC, "$path/lib/perl5", sub {
+push @INC, $incpath, sub {
   my (undef, $file) = @_;
 
   fetch($path, modulefy($file));
 
-  return IO::File->new($path . '/lib/perl5/' . $file);
+  return IO::File->new(catfile($incpath, $file));
 };
 
 1;

mercurial