Minor improvements
[koha.git] / C4 / Context.pm
index b1efd7b..2d9e9e2 100644 (file)
@@ -20,6 +20,7 @@
 package C4::Context;
 use strict;
 use DBI;
+use C4::Boolean;
 
 use vars qw($VERSION $AUTOLOAD),
        qw($context),
@@ -170,7 +171,7 @@ sub new
        my $self = {};
 
        # check that the specified config file exists
-       undef $conf_fname unless (-e $conf_fname);
+       undef $conf_fname unless (defined $conf_fname && -e $conf_fname);
        # Figure out a good config file to load if none was specified.
        if (!defined($conf_fname))
        {
@@ -325,6 +326,13 @@ EOT
        return $retval;
 }
 
+sub boolean_preference ($) {
+       my $self = shift;
+       my $var = shift;                # The system preference to return
+       my $it = preference($self, $var);
+       return defined($it)? C4::Boolean::true_p($it): undef;
+}
+
 # AUTOLOAD
 # This implements C4::Config->foo, and simply returns
 # C4::Context->config("foo"), as described in the documentation for
@@ -357,7 +365,6 @@ sub _new_dbh
        my $db_host   = $context->{"config"}{"hostname"};
        my $db_user   = $context->{"config"}{"user"};
        my $db_passwd = $context->{"config"}{"pass"};
-
        return DBI->connect("DBI:$db_driver:$db_name:$db_host",
                            $db_user, $db_passwd);
 }