Commit d2e825bc authored by Bernard Quatermass's avatar Bernard Quatermass

Make config $HOME relative for non-root

parent 9b5c0426
......@@ -4,7 +4,7 @@
# VERSION
version 1.2
version 1.3
# SYNOPSIS
......@@ -23,8 +23,8 @@ An example of use might be
# fetch a row, return a hash
my $row = $dbh->fetch_row( 'select * from testusers where name = ?', $name );
where the configuration file (which will default to `/etc/DBConnect.conf`) has the
following typical layout
where the configuration file (which will default to `$HOME/etc/db.cfg` if it exists
for non-root users or `/etc/DBConnect.conf` otherwise) has the following typical layout
# DBConnect configuration file layout
......
Name: perl-DBIWrap
Version: 1.2
Version: 1.3
Release: 1%{?dist}
Summary: Helper wrapper for DBI access
......@@ -52,6 +52,9 @@ make test
%changelog
* Mon Dec 03 2018 Bernard Quatermass <toolsmith@quatermass.co.uk>> - 1.3-1
- Make default config file $HOME relative if present
* Wed Oct 03 2018 Bernard Quatermass <toolsmith@quatermass.co.uk>> - 1.2-3
- match source to package name and move to autosetup
......
......@@ -14,7 +14,7 @@ package DBIWrap;
use strict;
$DBIWrap::VERSION='1.2';
$DBIWrap::VERSION='1.3';
use IO::Handle;
......@@ -65,6 +65,20 @@ __load_config
return $cfg;
}
sub
__get_cfg_name
{
if ($> != 0)
{
# see if the user has one
return $ENV{'HOME'}.'/etc/db.cfg'
if $ENV{'HOME'}
&& -d $ENV{'HOME'}
&& -f $ENV{'HOME'}.'/etc/db.cfg';
}
return '/etc/DBConnect.conf';
}
sub
DBConnect
......@@ -73,7 +87,7 @@ DBConnect
$class = shift;
$dsn = shift;
$cfgname = shift || '/etc/DBConnect.conf';
$cfgname = shift || __get_cfg_name();
$cfg = __load_config( $cfgname );
$dsn = $cfg->{'default'}
if ! $dsn;
......@@ -287,7 +301,7 @@ B<DBIWrap> - Convenience wrapper around B<DBI>
=head1 VERSION
version 1.2
version 1.3
=head1 SYNOPSIS
......@@ -306,8 +320,8 @@ An example of use might be
# fetch a row, return a hash
my $row = $dbh->fetch_row( 'select * from testusers where name = ?', $name );
where the configuration file (which will default to C</etc/DBConnect.conf>) has the
following typical layout
where the configuration file (which will default to C<$HOME/etc/db.cfg> if it exists
for non-root users or C</etc/DBConnect.conf> otherwise) has the following typical layout
# DBConnect configuration file layout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment