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 47 48 49 50 51
|
Description: Handle unset $HOME
If File::HomeDir->my_home returns undef, e.g. when $HOME is not set on
Linux, we see the following warnings during build or at runtime:
.
Use of uninitialized value in concatenation (.) or string at /build/libdbix-class-schema-config-perl-0.001013/blib/lib/DBIx/Class/Schema/Config.pm line 133.
Use of uninitialized value in concatenation (.) or string at t/03_config_paths.t line 8.
Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/DBIx/Class/Schema/Config.pm line 133.
.
Let's add $home/.dbic to config_paths only when we actually have a homedir,
both in the code and the respective test.
Origin: vendor
Author: gregor herrmann <gregoa@debian.org>
Last-Update: 2019-08-13
Forwarded: https://rt.cpan.org/Ticket/Display.html?id=130294
Bug: https://rt.cpan.org/Ticket/Display.html?id=130294
--- a/lib/DBIx/Class/Schema/Config.pm
+++ b/lib/DBIx/Class/Schema/Config.pm
@@ -130,7 +130,12 @@
__PACKAGE__->mk_classaccessor('config_paths');
__PACKAGE__->mk_classaccessor('config_files');
__PACKAGE__->mk_classaccessor('_config');
-__PACKAGE__->config_paths([( get_env_vars(), './dbic', File::HomeDir->my_home . '/.dbic', '/etc/dbic')]);
+__PACKAGE__->config_paths([( get_env_vars(), './dbic', '/etc/dbic')]);
+
+# add $HOME/.dbic, if $HOME exists, and as the penultimate element
+my $home = File::HomeDir->my_home;
+splice @{__PACKAGE__->config_paths()}, -1, 0, "$home/.dbic" if defined $home;
+
__PACKAGE__->config_files([ ] );
1;
--- a/t/03_config_paths.t
+++ b/t/03_config_paths.t
@@ -5,9 +5,15 @@
use base 'DBIx::Class::Schema::Config';
use File::HomeDir;
+my $wanted = [ './dbic', "/etc/dbic" ];
+
+# add $HOME/.dbic, if $HOME exists, and as the penultimate element
+my $home = File::HomeDir->my_home;
+splice @{$wanted}, -1, 0, "$home/.dbic" if defined $home;
+
is_deeply(
__PACKAGE__->config_paths,
- [ './dbic', File::HomeDir->my_home . "/.dbic", "/etc/dbic" ],
+ $wanted,
"_config_paths looks sane.");
__PACKAGE__->config_paths( [ ( './this', '/var/www/that' ) ] );
|