[Bps-public-commit] r16540 - in Prophet/trunk: .

spang at bestpractical.com spang at bestpractical.com
Sun Oct 26 17:05:34 EDT 2008


Author: spang
Date: Sun Oct 26 17:05:33 2008
New Revision: 16540

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/Config.pm

Log:
 r50900 at loki:  spang | 2008-10-25 22:30:13 -0400
 fall back on a default user-wide config file if PROPHET_APP_CONFIG isn't set and no database config exists


Modified: Prophet/trunk/lib/Prophet/Config.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Config.pm	(original)
+++ Prophet/trunk/lib/Prophet/Config.pm	Sun Oct 26 17:05:33 2008
@@ -1,15 +1,16 @@
 package Prophet::Config;
 use Moose;
 use MooseX::AttributeHelpers;
+use File::Spec;
 use Path::Class;
 
-
 has app_handle => (
     is => 'ro',
     weak_ref => 1,
     isa => 'Prophet::App',
     required => 0
 );
+
 has config_files => ( 
     is => 'rw',
     isa => 'ArrayRef' ,
@@ -33,10 +34,15 @@
     return $_[0]->config->{_aliases};
 }
 
-sub app_config_file { 
+sub app_config_file {
     my $self = shift;
 
-    $ENV{'PROPHET_APP_CONFIG'} || file( $self->app_handle->handle->fs_root => "prophetrc" ) ;
+    return $self->file_if_exists($ENV{'PROPHET_APP_CONFIG'}) ||
+        $self->file_if_exists(
+            File::Spec->catfile(
+                $self->app_handle->handle->fs_root => 'prophetrc' ))
+        || $self->file_if_exists(
+            File::Spec->catfile( $ENV{'HOME'} => '.prophetrc' ));
 }
 
 #my $singleton;
@@ -82,6 +88,20 @@
     return defined($friendly) ? $friendly : $uuid;
 }
 
+=head2 file_if_exists FILENAME
+
+Returns the given filename if it exists on the filesystem, and an
+empty string otherwise.
+
+=cut
+
+sub file_if_exists {
+    my $self = shift;
+    my $file = shift;
+
+    return (-e $file) ? $file : '';
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 
@@ -95,14 +115,15 @@
 
 =head1 SYNOPSIS
 
-    In ~/.prophetrc:
+    In the Prophet config file (see L</app_config_file>):
 
-        prefer_luids: 1
+      prefer_luids: 1
+      summary_format_ticket = %4s },$luid | %-11.11s,status | %-70.70s,summary
 
 =head1 DESCRIPTION
 
-This class represents configuration of Prophet and the application built on top
-of it.
+This class represents the configuration of Prophet and the application built on
+top of it.
 
 =head1 METHODS
 
@@ -114,8 +135,9 @@
 
 =head2 app_config_file
 
-The file which controls configuration for this application.
-C<$PROPHET_REPO/prophetrc>.
+The file which controls configuration for this application
+(the $PROPHET_APP_CONFIG environmental variable, C<$PROPHET_REPO/prophetrc>,
+or C<$HOME/.prophetrc>, in that order).
 
 =head2 load_from_files [files]
 
@@ -136,7 +158,7 @@
 
 =head2 list
 
-List all configuration options
+Lists all configuration options.
 
 =head2 display_name_for_uuid UUID
 



More information about the Bps-public-commit mailing list