Skip to content

Commit

Permalink
lib/File/ConfigDir.pm: fix local::lib handling
Browse files Browse the repository at this point in the history
Fix the utterly broken handling of local::lib and allow
configuration directories ("etc") in hierarchy below
PERL_LOCAL_LIB_ROOT.
Do not use local::lib before the class-method "active_paths"
is available.

Signed-off-by: Jens Rehsack <sno@netbsd.org>
  • Loading branch information
rehsack committed Apr 27, 2018
1 parent 279cbcc commit 3100376
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ WriteMakefile1(
build => {requires => {%BUILD_DEPS}},
test => {requires => {%TEST_DEPS}},
runtime => {
suggests => {
'local::lib' => '1.008008',
},
recommends => {
'File::HomeDir' => '0.50',
'List::MoreUtils' => '0.0.419',
Expand Down
18 changes: 11 additions & 7 deletions lib/File/ConfigDir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,20 @@ C<etc> directory below it.
=cut

my $haveLocalLib;

BEGIN
{
# uncoverable branch false
defined $haveLocalLib or $haveLocalLib = eval "use local::lib (); local::lib->can('active_paths');";
defined $haveLocalLib or $haveLocalLib = 0;
}

my $locallib_cfg_dir = sub {
my @cfg_base = @_;
my @dirs;

if ( $INC{'local/lib.pm'}
&& $ENV{PERL_MM_OPT}
&& $ENV{PERL_MM_OPT} =~ m/.*INSTALL_BASE=([^"']*)['"]?$/)
{
(my $cfgdir = $ENV{PERL_MM_OPT}) =~ s/.*INSTALL_BASE=([^"']*)['"]?$/$1/;
push(@dirs, File::Spec->catdir($cfgdir, "etc", @cfg_base));
}
$haveLocalLib and push(@dirs, map { File::Spec->catdir($_, "etc", @cfg_base) } local::lib->active_paths);

@dirs;
};
Expand Down Expand Up @@ -404,6 +407,7 @@ my $haveFileHomeDir;

BEGIN
{
# uncoverable branch false
defined $haveFileHomeDir or $haveFileHomeDir = eval "use File::HomeDir; 1";
defined $haveFileHomeDir or $haveFileHomeDir = 0;
}
Expand Down
13 changes: 7 additions & 6 deletions t/01-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
use strict;
use warnings;

eval {
require local::lib;
#local::lib->import();
};
use File::Temp qw(tempdir);

my $dir = tempdir(CLEANUP => 1);

eval "use local::lib '$dir'; 1;";

use Test::More;

Expand All @@ -16,15 +17,15 @@ my @supported_functions = (
qw(config_dirs system_cfg_dir desktop_cfg_dir),
qw(core_cfg_dir site_cfg_dir vendor_cfg_dir),
qw(local_cfg_dir here_cfg_dir singleapp_cfg_dir vendorapp_cfg_dir),
qw(xdg_config_dirs xdg_config_home user_cfg_dir),
qw(xdg_config_dirs xdg_config_home user_cfg_dir locallib_cfg_dir),
);
foreach my $fn (@supported_functions)
{
my $faddr;
ok($faddr = File::ConfigDir->can($fn), "Can $fn");
my @dirs = &{$faddr}();
note("$fn: " . join(",", @dirs));
if ($fn =~ m/(?:xdg_)?config_dirs/ or $fn =~ m/(?:machine|desktop)_cfg_dir/)
if ($fn =~ m/(?:xdg_)?config_dirs/ or $fn =~ m/(?:machine|desktop|locallib)_cfg_dir/)
{
ok(scalar @dirs >= 1, "config_dirs") or diag(join(",", @dirs)); # we expect at least system_cfg_dir
}
Expand Down

0 comments on commit 3100376

Please sign in to comment.