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

jesse at bestpractical.com jesse at bestpractical.com
Tue Oct 14 17:54:01 EDT 2008


Author: jesse
Date: Tue Oct 14 17:54:00 2008
New Revision: 16290

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/App.pm
   Prophet/trunk/lib/Prophet/DatabaseSetting.pm
   Prophet/trunk/lib/Prophet/Replica.pm
   Prophet/trunk/t/database-settings.t

Log:
 r46832 at 16:  jesse | 2008-10-14 18:22:24 +0200
 * cleanup to database settings to let you store references in them
 


Modified: Prophet/trunk/lib/Prophet/App.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/App.pm	(original)
+++ Prophet/trunk/lib/Prophet/App.pm	Tue Oct 14 17:54:00 2008
@@ -2,6 +2,7 @@
 use Moose;
 use Path::Class;
 use Prophet::Config;
+use Params::Validate qw/validate/;
 
 has handle => (
     is      => 'rw',
@@ -120,10 +121,14 @@
     return ( $INC{$path} ? 1 : 0);
 }
 
+
+sub set_database_defaults { 1; }
+
 sub setting {
     my $self = shift;
-    my $uuid = shift;
-    return Prophet::DatabaseSetting->new( handle => $self->handle, uuid => $uuid);
+    my %args = validate(@_, { uuid => 1, default => 1, label => 0 });
+    require Prophet::DatabaseSetting;
+    return Prophet::DatabaseSetting->new( handle => $self->handle, uuid => $args{uuid}, default => $args{default}, label => $args{label});
 }
 
 

Modified: Prophet/trunk/lib/Prophet/DatabaseSetting.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/DatabaseSetting.pm	(original)
+++ Prophet/trunk/lib/Prophet/DatabaseSetting.pm	Tue Oct 14 17:54:00 2008
@@ -2,31 +2,53 @@
 use Moose;
 extends 'Prophet::Record';
 use Params::Validate;
+use JSON;
+
+has default => (
+    is => 'ro'
+);
+
+has label => (
+    isa => 'Maybe[Str]',
+    is => 'rw' 
+);
+
 
 sub new { 
         shift->SUPER::new( type => '__prophet_db_settings', @_);
 }
 
 
+sub initialize {
+    my $self = shift;
+    warn "My default is ".$self->default;
+    warn "My uuid is ". $self->uuid;
+    $self->set($self->default);
+}
 
 sub set {
     my $self = shift;
-    # XXX TODO - better serialization of values. json?
-    my $values = join(';', @_);
+    my $entry;
+    if (exists $_[1]  || !ref($_[0]))  {
+        $entry = [@_];
+    } else { 
+        $entry = shift @_;
+    }
+       my  $content = to_json($entry, { canonical => 1, pretty=> 0, utf8=>1, allow_nonref => 0}  );
     
     
     if ($self->handle->record_exists( uuid => $self->uuid, type => $self->type)) {
-        $self->set_props( props => { content => $values});
+        $self->set_props( props => { content => $content, label => $self->label});
     } else {
-        $self->_create_record( props => { content => $values }, uuid => $self->uuid );
+        $self->_create_record( props => { content => $content, label => $self->label }, uuid => $self->uuid );
     }
 }
 
 
 sub get {
     my $self = shift;
-    my @entries =  split(/;/, $self->prop('content'));
-    return wantarray ? @entries : shift @entries;
+    my $entry = from_json($self->prop('content') , { utf8 => 1 });
+    return $entry;
     # XXX TODO do we really want to just get the first one?
 
 }

Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Tue Oct 14 17:54:00 2008
@@ -61,7 +61,7 @@
 has after_initialize => ( 
     is => 'ro',
     isa => 'CodeRef',
-    default => sub {1 }
+    default => sub { sub {1} } # default returns a coderef
     );
 
 our $MERGETICKET_METATYPE = '_merge_tickets';

Modified: Prophet/trunk/t/database-settings.t
==============================================================================
--- Prophet/trunk/t/database-settings.t	(original)
+++ Prophet/trunk/t/database-settings.t	Tue Oct 14 17:54:00 2008
@@ -53,7 +53,7 @@
     can_ok($status_list, 'get');
 
     # set list of acceptable components
-    $comp_list->set(qw/core ui docs/); 
+    $comp_list->set([qw/core ui docs/]); 
 
 
     # set default values for component
@@ -64,17 +64,17 @@
     $status_list->set('new','open','closed'); 
 
     # enumerate statuses
-    is_deeply([$status_list->get], [qw/new open closed/]);
+    is_deeply($status_list->get, [qw/new open closed/]);
 
     $status_list->set('new', 'closed');
 
-    is_deeply([$status_list->get], [qw/new closed/]);
+    is_deeply($status_list->get, [qw/new closed/]);
 
     # enumerate components
-    is_deeply([$t->component_list->get], [qw/core ui docs/]);
+    is_deeply($t->component_list->get, [qw/core ui docs/]);
     
     # enumerate default component
-    is($t->default_component->get, 'core', "The thing we got was core");
+    is_deeply($t->default_component->get, ['core'], "The thing we got was core");
   
    
     # just for good measure, create a ticket
@@ -99,17 +99,17 @@
     my $t = MyApp::Model::Task->new(handle => $bob_cli->app_handle->handle);
     
     # enumerate statuses
-    is_deeply([$t->status_list->get], [qw/new closed/]);
+    is_deeply($t->status_list->get, [qw/new closed/]);
 
     # enumerate components
-    is_deeply([$t->component_list->get], [qw/core ui docs/]);
+    is_deeply($t->component_list->get, [qw/core ui docs/]);
     
     # enumerate default component
-    is($t->default_component->get, 'core', "The thing we got was core");
+    is_deeply($t->default_component->get, ['core'], "The thing we got was core");
  
     $t->default_component->set('ui');
 
-    is($t->default_component->get, 'ui', "The thing we got was core");
+    is_deeply($t->default_component->get, ['ui'], "The thing we got was core");
 };
 
 as_alice {
@@ -118,9 +118,9 @@
     isa_ok( $cxn, 'Prophet::Replica', "Got the cxn " . $cxn->fs_root );
     
     my $t = MyApp::Model::Task->new(handle => $alice_cli->app_handle->handle);
-    is($t->default_component->get, 'core', "The thing we got was core");
+    is_deeply($t->default_component->get, ['core'], "The thing we got was core");
     run_ok( 'prophet', ['pull', '--from', "file://".$bob_cli->app_handle->handle->fs_root, '--force'] );
-    is($t->default_component->get, 'ui', "The thing we got was core");
+    is_deeply($t->default_component->get, ['ui'], "The thing we got was core");
 
     #   add a status
     $t->status_list->set(qw/new open stalled resolved/);
@@ -142,10 +142,10 @@
     my $t = MyApp::Model::Task->new(handle => $bob_cli->app_handle->handle);
     TODO: { 
     local $TODO = "we don't resolve config conflicts yet";
-    is_deeply([$t->status_list->get], [qw[new open stalled resolved rejected]]);
+    is_deeply($t->status_list->get, [qw[new open stalled resolved rejected]]);
 };
     # current behaviour
-    is_deeply([$t->status_list->get], [qw[new open resolved rejected]]);
+    is_deeply($t->status_list->get, [qw[new open resolved rejected]]);
 };
 
 as_alice {
@@ -156,10 +156,10 @@
     my $t = MyApp::Model::Task->new(handle => $bob_cli->app_handle->handle);
     TODO: { 
     local $TODO = "we don't resolve config conflicts yet";
-    is_deeply([$t->status_list->get], [qw[new open stalled resolved rejected]]);
+    is_deeply($t->status_list->get, [qw[new open stalled resolved rejected]]);
 };
     # current behaviour
-    is_deeply([$t->status_list->get], [qw[new open resolved rejected]]);
+    is_deeply($t->status_list->get, [qw[new open resolved rejected]]);
 };
 
 1;



More information about the Bps-public-commit mailing list