[Bps-public-commit] Prophet branch, master, updated. 5a3cb57fea40543549e12b4b59f287dfd6285964

jesse jesse at bestpractical.com
Wed Jun 10 21:10:34 EDT 2009


The branch, master has been updated
       via  5a3cb57fea40543549e12b4b59f287dfd6285964 (commit)
      from  d220860878ff7e9b4331171b5477b490cda89eeb (commit)

Summary of changes:
 Makefile.PL                      |    1 +
 lib/Prophet/App.pm               |    9 +++++
 lib/Prophet/FilesystemReplica.pm |    4 +-
 lib/Prophet/ForeignReplica.pm    |    2 +-
 lib/Prophet/Record.pm            |   10 +-----
 lib/Prophet/Replica/prophet.pm   |    5 +--
 lib/Prophet/Replica/sqlite.pm    |    7 ++--
 lib/Prophet/Server/Dispatcher.pm |    2 +-
 lib/Prophet/UUIDGenerator.pm     |   62 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 82 insertions(+), 20 deletions(-)
 create mode 100644 lib/Prophet/UUIDGenerator.pm

- Log -----------------------------------------------------------------
commit 5a3cb57fea40543549e12b4b59f287dfd6285964
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Wed Jun 10 21:10:19 2009 -0400

    unify our uuid generation codepath

diff --git a/Makefile.PL b/Makefile.PL
index b1e3517..eaba2ce 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -8,6 +8,7 @@ requires('Exporter::Lite');
 requires('Params::Validate');
 requires('IPC::Run3');
 requires('Data::UUID');
+requires('Data::UUID::Base64URLSafe');
 requires('Digest::SHA');
 requires('LWP::UserAgent');     #  LWP::ConnCache too
 requires('URI');
diff --git a/lib/Prophet/App.pm b/lib/Prophet/App.pm
index 71b7e0a..dda9fdd 100644
--- a/lib/Prophet/App.pm
+++ b/lib/Prophet/App.pm
@@ -2,6 +2,7 @@ package Prophet::App;
 use Any::Moose;
 use File::Spec ();
 use Prophet::Config;
+use Prophet::UUIDGenerator;
 use Params::Validate qw/validate validate_pos/;
 
 has handle => (
@@ -31,6 +32,14 @@ has config => (
     documentation => "This is the config instance for the running application",
 );
 
+
+has uuid_generator => (
+    is => 'rw',
+    isa => 'Prophet::UUIDGenerator',
+    default => sub { Prophet::UUIDGenerator->new}
+);
+
+
 use constant DEFAULT_REPLICA_TYPE => 'prophet';
 
 =head1 NAME
diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
index fab2796..f917bc2 100644
--- a/lib/Prophet/FilesystemReplica.pm
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -120,7 +120,7 @@ sub _write_changeset {
 
     my $changeset_index_line = pack( 'Na16NH40',
         $seqno,
-        Data::UUID->new->from_string( $changeset->original_source_uuid ),
+        $self->app_handle->uuid_generator->from_string( $changeset->original_source_uuid ),
         $changeset->original_sequence_no,
         $cas_key );
 
@@ -219,7 +219,7 @@ sub _changeset_index_entry {
     my $index_record = substr( $$chgidx, ( $rev - 1 ) * CHG_RECORD_SIZE, CHG_RECORD_SIZE );
     my ( $seq, $orig_uuid, $orig_seq, $key ) = unpack( 'Na16NH40', $index_record );
 
-    $orig_uuid = Data::UUID->new->to_string($orig_uuid);
+    $orig_uuid = $self->app_handle->uuid_generator->to_string($orig_uuid);
     $self->log_debug( "REV: $rev - seq $seq - originally $orig_seq from "
             . substr( $orig_uuid, 0, 6 )
             . " data key $key" );
diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index b62ce18..ee2287d 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -61,7 +61,7 @@ sub db_uuid { return undef }
 
 sub uuid_for_url {
     my ( $self, $url ) = @_;
-    return Data::UUID->new->create_from_name_str( NameSpace_DNS, $url );
+    return $self->app_handle->uuid_generator->create_string_from_url( $url );
 }
 
 sub prompt_for_login {
diff --git a/lib/Prophet/Record.pm b/lib/Prophet/Record.pm
index 5caee82..0958f0d 100644
--- a/lib/Prophet/Record.pm
+++ b/lib/Prophet/Record.pm
@@ -52,14 +52,6 @@ sub REFERENCES { $REFERENCES }
 our $PROPERTIES = {};
 sub PROPERTIES { $PROPERTIES }
 
-do {
-    my $uuid_generator;
-    sub uuid_generator {
-        require Data::UUID;
-        $uuid_generator ||= Data::UUID->new;
-    }
-};
-
 =head1 METHODS
 
 =head2 new  { handle => Prophet::Replica, type => $type }
@@ -200,7 +192,7 @@ In case of failure, returns undef.
 sub create {
     my $self = shift;
     my %args = validate( @_, { props => 1 } );
-    my $uuid = $self->uuid_generator->create_str;
+    my $uuid = $self->handle->app_handle->uuid_generator->create_str;
 
     my $props = $args{props};
 
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index da22d0f..72b8107 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -10,7 +10,6 @@ use File::Spec  ();
 use File::Path;
 use Cwd ();
 use File::Find;
-use Data::UUID;
 use Prophet::Util;
 use POSIX qw();
 use Memoize;
@@ -324,9 +323,9 @@ sub initialize {
         mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
     }
 
-    $self->set_db_uuid( $args{'db_uuid'} || Data::UUID->new->create_str );
+    $self->set_db_uuid( $args{'db_uuid'} || $self->app_handle->uuid_generator->create_str );
     $self->set_latest_sequence_no("0");
-    $self->set_replica_uuid( Data::UUID->new->create_str );
+    $self->set_replica_uuid(  $self->app_handle->uuid_generator->create_str );
 
     $self->set_replica_version(1);
 
diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index ac9bdcd..c26c2c4 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -3,7 +3,6 @@ use Any::Moose;
 extends 'Prophet::Replica';
 use Params::Validate qw(:all);
 use File::Spec  ();
-use Data::UUID;
 use File::Path;
 use Prophet::Util;
 use JSON;
@@ -294,8 +293,8 @@ CREATE TABLE userdata (
         $self->dbh->do($_) || warn $self->dbh->errstr;
     }
 
-    $self->set_db_uuid( $args{'db_uuid'} || Data::UUID->new->create_str );
-    $self->set_replica_uuid( Data::UUID->new->create_str );
+    $self->set_db_uuid( $args{'db_uuid'} || $self->app_handle->uuid_generator->create_str );
+    $self->set_replica_uuid( $self->app_handle->uuid_generator->create_str );
     $self->set_replica_version(3);
     $self->resolution_db_handle->initialize( db_uuid => $args{resdb_uuid} )
       if !$self->is_resdb;
@@ -470,7 +469,7 @@ sub read_changeset_index {
                     my $data            = $args{changeset_metadata};
                     my $changeset_index_line = pack( 'Na16NH40',
                         $data->[0],
-                        Data::UUID->new->from_string( $data->[1]),
+                        $self->app_handle->uuid_generator->from_string( $data->[1]),
                         $data->[2],
                         $data->[3]);
                     $index .= $changeset_index_line;
diff --git a/lib/Prophet/Server/Dispatcher.pm b/lib/Prophet/Server/Dispatcher.pm
index b4e7133..9403483 100644
--- a/lib/Prophet/Server/Dispatcher.pm
+++ b/lib/Prophet/Server/Dispatcher.pm
@@ -60,7 +60,7 @@ under { method => 'GET' } => sub {
                     my $data            = $args{changeset_metadata};
                     my $changeset_index_line = pack( 'Na16NH40',
                         $data->[0],
-                        Data::UUID->new->from_string( $data->[1]),
+                        $self->app_handle->uuid_generator->from_string( $data->[1]),
                         $data->[2],
                         $data->[3]);
                     $index .= $changeset_index_line;
diff --git a/lib/Prophet/UUIDGenerator.pm b/lib/Prophet/UUIDGenerator.pm
new file mode 100644
index 0000000..e3894c4
--- /dev/null
+++ b/lib/Prophet/UUIDGenerator.pm
@@ -0,0 +1,62 @@
+package Prophet::UUIDGenerator;
+use Data::UUID qw'NameSpace_DNS';
+use Any::Moose;
+
+our $UUIDGEN;
+
+sub _uuid_generator {
+
+        return $UUIDGEN ||= Data::UUID->new();
+}
+
+sub create_str {
+    my $self = shift;
+    return $self->_uuid_generator->create_str();
+}
+
+sub create_string_from_url {
+    my $self = shift;
+    my $url = shift;
+    local $!;
+    $self->_uuid_generator->create_from_name_str(NameSpace_DNS, $url )
+}
+
+sub from_string {
+    my $self = shift;
+    my $str = shift;
+    $self->_uuid_generator->from_string($str);
+}
+ 
+sub to_string {
+    my $self = shift;
+    my $uuid = shift;
+    $self->_uuid_generator->to_string($uuid);
+}
+
+sub from_safe_b64 {}
+
+sub to_safe_b64 {}
+
+
+=head1 NAME
+
+Foo::Bar
+
+=head1 METHODS
+
+=head1 DESCRIPTION
+
+=cut
+
+=head1 METHODS
+
+=cut
+
+
+
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
+1;
+

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list