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

sartak at bestpractical.com sartak at bestpractical.com
Wed Jul 23 23:58:09 EDT 2008


Author: sartak
Date: Wed Jul 23 23:58:09 2008
New Revision: 14454

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/Replica/Native.pm
   Prophet/trunk/t/publish-pull.t

Log:
 r64974 at onn:  sartak | 2008-07-23 23:57:53 -0400
 Add support for intuiting database uuid when instantiating a replica
 If we have the same database uuid, then you can pull from http://sartak.org/misc/sd without needed to specify the db uuid


Modified: Prophet/trunk/lib/Prophet/Replica/Native.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/Native.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/Native.pm	Wed Jul 23 23:58:09 2008
@@ -96,14 +96,53 @@
 
 sub BUILD {
     my $self = shift;
-    $self->{url}
-        =~ s/^prophet://;  # url-based constructor in ::replica should do better
-    $self->{url} =~ s{/$}{};
-    $self->_probe_or_create_db();
+    my $args = shift;
+
+    for ($self->{url}, @{ $self->{_alt_urls} }) {
+        s/^prophet://;  # url-based constructor in ::replica should do better
+        s{/$}{};
+    }
+
+    $self->_try_alt_urls($args);
+    $self->_probe_or_create_db;
 }
 
 sub state_handle { return shift; }
 
+sub _try_alt_urls {
+    my $self = shift;
+    my $args = shift;
+
+    return unless @{ $self->{_alt_urls} };
+
+    # try each URL in turn. since the "url" attribute is usually specified
+    # directly by the user (and the others are calculated from that), we
+    # save the error caused by the "url" attribute to throw if all
+    # alternates fail
+
+    my $error;
+    for my $url ($self->{url}, @{ $self->{_alt_urls} }) {
+        my $new_self = eval {
+            my $obj = $self->new(%$args, url => $url, _alt_urls => []);
+            $obj->_probe_or_create_db;
+            $obj;
+        };
+
+        if ($new_self) {
+            # XXX: yes this is a little offensive. but we can't outright replace
+            # $self this late in the game, and we cannot foresee which
+            # attributes will need clearing, so this is the simplest way to
+            # make sure everything is consistent
+            %$self = %$new_self;
+            return 1;
+        }
+
+        $error ||= $@;
+    }
+
+    die $error if $error;
+}
+
 sub _probe_or_create_db {
     my $self = shift;
 

Modified: Prophet/trunk/t/publish-pull.t
==============================================================================
--- Prophet/trunk/t/publish-pull.t	(original)
+++ Prophet/trunk/t/publish-pull.t	Wed Jul 23 23:58:09 2008
@@ -30,11 +30,8 @@
     my $cli  = Prophet::CLI->new();
     $cli->app_handle->handle->set_db_uuid($alice_uuid);
 
-    TODO: {
-        local $TODO = "not finished yet";
-        run_ok( 'prophet', ['pull', '--from', "file:$alice_published", '--force'] );
-        run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/new/], "publish database uuid intuition works" );
-    }
+    run_ok( 'prophet', ['pull', '--from', "file:$alice_published", '--force'] );
+    run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/new/], "publish database uuid intuition works" );
 };
 
 TODO: {



More information about the Bps-public-commit mailing list