Diab Jerius avatar Diab Jerius committed e55d915

fix broken config file reading

the logic to determine when to read config files was broken; recent changes
prevented the the default file from being read.

it's now possible to ignore all config files.

Comments (0)

Files changed (1)

 		    );
     };
 
+    use constant FILE_REQUIRED => 1;
+    use constant FILE_NOT_REQUIRED => 2;
+    use constant FALLBACK => 3;
+
+
     sub new {
 
 	my ( $class, $file, $default ) = @_;
 	my $self;
 
 	# first check local file
-	if ( ! defined $file )
+	if ( defined $file )
 	{
-	    # first check local dir
-	    $self = _read_config( $default, 0 );
+	    $self = _read_config( $file, FILE_REQUIRED );
 	}
 
 	# if config is specified, it's an error if it doesn't exist
-	else
+	elsif ( defined $default )
 	{
-	    $self = _read_config( $file, 1 );
+	    # first check local dir
+	    $self = _read_config( $default, FILE_NOT_REQUIRED );
 	}
 
-	# if nothing has been read or read_root_config requested, read root 
+	# if nothing has been read or read_root_config requested, read root
 	if ( ! $self || $self->{_}{read_root_config} )
 	{
-	    require File::HomeDir;
-	    my $root = _read_config( catfile( File::HomeDir->my_home, $default ), 0 );
+	    if ( defined $default ) {
+
+		require File::HomeDir;
+		$default = catfile( File::HomeDir->my_home, $default );
+
+	    }
+
+	    my $root = _read_config( $default, FALLBACK );
 
 	    if ( $self )
 	    {
 
     sub _read_config {
 
-	my ( $file, $must_exist ) = @_;
+	my ( $file, $status ) = @_;
 
 	my $config = { '_' => {} };
 
-	unless ( -f $file ) {
+	unless ( defined $file && -f $file ) {
 
 	    die( "configuration file ($file) does not exist\n" )
-	      if $must_exist;
+	      if $status == FILE_REQUIRED;
 
-	    return $config;
+	    return $config if $status == FALLBACK;
+
+	    return;
 	}
 
 	::info "Reading configuration file $file\n";
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.