[Bps-public-commit] r12456 - Prophet/branches/luid/lib/Prophet
jesse at bestpractical.com
jesse at bestpractical.com
Sat May 17 05:41:39 EDT 2008
Author: jesse
Date: Sat May 17 05:41:39 2008
New Revision: 12456
Added:
Prophet/branches/luid/lib/Prophet/Config.pm
Modified:
Prophet/branches/luid/lib/Prophet/App.pm
Prophet/branches/luid/lib/Prophet/Record.pm
Log:
* revert that last splodey commit
Modified: Prophet/branches/luid/lib/Prophet/App.pm
==============================================================================
--- Prophet/branches/luid/lib/Prophet/App.pm (original)
+++ Prophet/branches/luid/lib/Prophet/App.pm Sat May 17 05:41:39 2008
@@ -4,10 +4,15 @@
package Prophet::App;
use base qw/Class::Accessor/;
use Path::Class;
-__PACKAGE__->mk_accessors(qw/_resdb_handle/);
+__PACKAGE__->mk_accessors(qw/_resdb_handle _config/);
use constant DEFAULT_REPLICA_TYPE => 'prophet';
+=head1 NAME
+
+Prophet::App
+
+=cut
sub _handle {
my $self = shift;
@@ -89,5 +94,31 @@
$@ = '';
}
+=head2 config
+
+If called with no arguments, returns the L<Prophet::Config> instance.
+
+If called with one arguments, returns the value of that config setting.
+
+If called with two arguments, sets the value of that config setting.
+
+=cut
+
+sub config {
+ my $self = shift;
+
+ unless ($self->_config) {
+ require Prophet::Config;
+ $self->_config(Prophet::Config->new);
+ }
+
+ return $self->_config if @_ == 0;
+
+ my $key = shift;
+ return $self->_config->get($key) if @_ == 0;
+
+ my $value = shift;
+ return $self->_config->set($key => $value);
+}
1;
Added: Prophet/branches/luid/lib/Prophet/Config.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/luid/lib/Prophet/Config.pm Sat May 17 05:41:39 2008
@@ -0,0 +1,121 @@
+use warnings;
+use strict;
+
+package Prophet::Config;
+
+use Path::Class;
+
+=head1 NAME
+
+Prophet::Config
+
+=head1 SYNOPSIS
+
+ In ~/.prophetrc:
+
+ prefer_luids: 1
+
+=head1 DESCRIPTION
+
+This class represents configuration of Prophet and the application built on top
+of it.
+
+=head1 METHODS
+
+=head2 new
+
+Takes no arguments. Automatically loads the config for you. This is actually
+a singleton so multiple calls to new get the same config.
+
+=cut
+
+my $singleton;
+sub new {
+ my $class = shift;
+ return $singleton if $singleton;
+
+ my $self = $singleton = bless {}, $class;
+ $self->load_config_files;
+ return $self;
+}
+
+=head2 prophet_config_file
+
+The file which controls configuration for all Prophet apps. C<$HOME/.prophetc>.
+
+=cut
+
+sub prophet_config_file { dir($ENV{HOME}, ".prophetrc") }
+
+=head2 app_config_file
+
+The file which controls configuration for this application.
+C<$PROPHET_REPO/prophetrc>.
+
+=cut
+
+sub app_config_file { dir($ENV{PROPHET_REPO}, "prophetrc") }
+
+=head2 load_config_files [files]
+
+Loads the given config files. If no files are passed in, it will use the
+default of L</prophet_config_file> and L</app_config_file>.
+
+=cut
+
+sub load_config_files {
+ my $self = shift;
+ my @config = @_;
+ @config = ($self->prophet_config_file, $self->app_config_file) if !@config;
+
+ for my $file (@config) {
+ $self->load_config_file($file);
+ }
+}
+
+=head2 load_config_file file
+
+Loads the given config file.
+
+=cut
+
+sub load_config_file {
+ my $self = shift;
+ my $file = shift;
+
+ for my $line ($file->slurp) {
+ s/\#.*//; # strip comments
+ if ($line =~ /^([^:]+):\s*(.*)$/) {
+ $self->{$1} = $2;
+ }
+ }
+}
+
+=head2 get
+
+Gets a specific config setting.
+
+=cut
+
+sub get {
+ my $self = shift;
+ my $key = shift;
+
+ return $self->{$key};
+}
+
+=head2 set
+
+Sets a specific config setting.
+
+=cut
+
+sub set {
+ my $self = shift;
+ my $key = shift;
+ my $value = shift;
+
+ return $self->{$key} = $value;
+}
+1;
+
Modified: Prophet/branches/luid/lib/Prophet/Record.pm
==============================================================================
--- Prophet/branches/luid/lib/Prophet/Record.pm (original)
+++ Prophet/branches/luid/lib/Prophet/Record.pm Sat May 17 05:41:39 2008
@@ -137,7 +137,6 @@
}
=head2 load { uuid => $UUID } or { luid => $UUID }
-=head2 load { luid => $UUID }
Loads a Prophet record off disk by its uuid or luid.
@@ -344,17 +343,4 @@
return $luid;
}
-=head2 find_or_create_luid
-
-Finds the luid for the records uuid, or creates a new one. Returns the luid.
-
-=cut
-
-sub find_or_create_luid {
- my $self = shift;
- my $luid = $self->handle->find_or_create_luid(uuid => $self->uuid);
- $self->luid($luid);
- return $luid;
-}
-
1;
More information about the Bps-public-commit
mailing list