[Bps-public-commit] r12454 - in Prophet/trunk: . lib/Prophet/Test t

jesse at bestpractical.com jesse at bestpractical.com
Sat May 17 05:36:09 EDT 2008


Author: jesse
Date: Sat May 17 05:36:09 2008
New Revision: 12454

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI.pm
   Prophet/trunk/lib/Prophet/Record.pm
   Prophet/trunk/lib/Prophet/Test/Participant.pm
   Prophet/trunk/t/edit.t
   Prophet/trunk/t/export.t
   Prophet/trunk/t/real-conflicting-merge.t
   Prophet/trunk/t/simple-conflicting-merge.t

Log:
 r31171 at dhcp113 (orig r12432):  jesse | 2008-05-17 18:28:52 +0900
 * Changed this to use both uuid and luid and made tests not get splodey. 
 
 added --id which can be either uuid or luid


Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI.pm	Sat May 17 05:36:09 2008
@@ -125,12 +125,22 @@
 sub set_type_and_uuid {
     my $self = shift;
 
+    if (my $id = delete $self->{args}->{id}) {
+        if ($id =~ /^(\d+)$/) { 
+        $self->{args}->{luid} = $id;
+        } else { 
+        $self->{args}->{uuid} = $id;
+
+        }
+
+    }
+
     if ( my $uuid = delete $self->{args}->{uuid} ) {
         $self->uuid($uuid);
     }
     elsif ( my $luid = delete $self->{args}->{luid} ) {
         my $uuid = $self->app_handle->handle->find_uuid_by_luid(luid => $luid);
-        die "Invalid luid '$luid'\n" if !defined($uuid);
+        die "I have no UUID mapped to the local id '$luid'\n" if !defined($uuid);
         $self->uuid($uuid);
     }
     if ( $self->{args}->{type} ) {
@@ -314,7 +324,7 @@
         return;
     }
 
-    print "Created " . $record->record_type . " " . $record->uuid . "\n";
+    print "Created " . $record->record_type . " " . $record->luid . " (".$record->uuid.")"."\n";
 
 }
 
@@ -428,9 +438,7 @@
         print "Record not found\n";
         return;
     }
-
-    print "uuid: " . $record->uuid . "\n";
-    print "luid: " . $record->luid . "\n";
+    print "id: ".$record->luid." (" .$record->uuid.")\n";
     my $props = $record->get_props();
     for ( keys %$props ) {
         print $_. ": " . $props->{$_} . "\n";

Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm	(original)
+++ Prophet/trunk/lib/Prophet/Record.pm	Sat May 17 05:36:09 2008
@@ -26,7 +26,7 @@
 use Params::Validate;
 use Data::UUID;
 use List::MoreUtils qw/uniq/;
-use Prophet::App; # for require_module. Kinda hacky
+use Prophet::App;    # for require_module. Kinda hacky
 
 my $UUIDGEN = Data::UUID->new();
 
@@ -86,19 +86,23 @@
     my %args = validate( @args, { by => 1 } );
     no strict 'refs';
 
-    Prophet::App->require_module($collection_class->record_class);
-    
-    
+    Prophet::App->require_module( $collection_class->record_class );
+
     *{ $class . "::$accessor" } = sub {
-        my $self = shift;
-        my $collection = $collection_class->new( handle => $self->handle, type => $collection_class->record_class->record_type );
-        $collection->matching( sub { $_[0]->prop( $args{by} ) eq $self->uuid } );
+        my $self       = shift;
+        my $collection = $collection_class->new(
+            handle => $self->handle,
+            type   => $collection_class->record_class->record_type
+        );
+        $collection->matching( sub { $_[0]->prop( $args{by} ) eq $self->uuid }
+        );
         return $collection;
     };
 
     # XXX: add validater for $args{by} in $model->record_class
 
-    $class->REFERENCES->{$accessor} = { %args, type => $collection_class->record_class };
+    $class->REFERENCES->{$accessor}
+        = { %args, type => $collection_class->record_class };
 }
 
 =head2 create { props => { %hash_of_kv_pairs } }
@@ -132,7 +136,7 @@
     return $self->uuid;
 }
 
-=head2 load { uuid => $UUID }
+=head2 load { uuid => $UUID } or { luid => $UUID }
 =head2 load { luid => $UUID }
 
 Loads a Prophet record off disk by its uuid or luid.
@@ -142,31 +146,35 @@
 sub load {
     my $self = shift;
 
-    my %args = validate(@_, {
-        uuid => {
-            optional => 1,
-            callbacks => {
-                'uuid or luid present' => sub { $_[0] || $_[1]->{luid} },
+    my %args = validate(
+        @_,
+        {   uuid => {
+                optional  => 1,
+                callbacks => {
+                    'uuid or luid present' => sub { $_[0] || $_[1]->{luid} },
+                },
             },
-        },
-        luid => {
-            optional => 1,
-            callbacks => {
-                'luid or uuid present' => sub { $_[0] || $_[1]->{uuid} },
+            luid => {
+                optional  => 1,
+                callbacks => {
+                    'luid or uuid present' => sub { $_[0] || $_[1]->{uuid} },
+                },
             },
-        },
-    });
+        }
+    );
 
-    if ($args{luid}) {
+    if ( $args{luid} ) {
         $self->luid( $args{luid} );
-        $self->uuid( $self->handle->find_uuid_by_luid(luid => $args{luid}) );
-    }
-    else {
+        $self->uuid( $self->handle->find_uuid_by_luid( luid => $args{luid} ) );
+    } else {
         $self->uuid( $args{uuid} );
         $self->find_or_create_luid();
     }
 
-    return $self->handle->record_exists( uuid => $self->uuid, type => $self->type );
+    return $self->handle->record_exists(
+        uuid => $self->uuid,
+        type => $self->type
+    );
 }
 
 =head2 set_prop { name => $name, value => $value }
@@ -202,7 +210,11 @@
 
     $self->canonicalize_props( $args{'props'} );
     $self->validate_props( $args{'props'} ) || return undef;
-    $self->handle->set_record_props( type => $self->type, uuid => $self->uuid, props => $args{'props'} );
+    $self->handle->set_record_props(
+        type  => $self->type,
+        uuid  => $self->uuid,
+        props => $args{'props'}
+    );
     return 1;
 }
 
@@ -214,7 +226,10 @@
 
 sub get_props {
     my $self = shift;
-    return $self->handle->get_record_props( uuid => $self->uuid, type => $self->type );
+    return $self->handle->get_record_props(
+        uuid => $self->uuid,
+        type => $self->type
+    );
 }
 
 =head2 prop $name
@@ -241,7 +256,10 @@
 sub delete_prop {
     my $self = shift;
     my %args = validate( @_, { name => 1 } );
-    $self->handle->delete_record_prop( uuid => $self->uuid, name => $args{'name'} );
+    $self->handle->delete_record_prop(
+        uuid => $self->uuid,
+        name => $args{'name'}
+    );
 }
 
 =head2 delete
@@ -264,11 +282,12 @@
     for my $key ( uniq( keys %$props, $self->declared_props ) ) {
         return undef unless ( $self->_validate_prop_name($key) );
         if ( my $sub = $self->can( 'validate_prop_' . $key ) ) {
-            $sub->( $self, props => $props, errors => $errors ) || push @errors, "Validation error for '$key': ".($errors->{$key}||'');
+            $sub->( $self, props => $props, errors => $errors ) || push @errors,
+                "Validation error for '$key': " . ( $errors->{$key} || '' );
         }
     }
     if (@errors) {
-        die join('', at errors);   
+        die join( '', @errors );
     }
     return 1;
 }
@@ -299,11 +318,30 @@
 sub format_summary {
     my $self   = shift;
     my $format = $self->summary_format;
-    my $uuid   = $self->uuid;
-    $format =~ s/%u/$uuid/g;
+    if ( $format =~ /%u/ ) {
+        my $uuid = $self->uuid;
+        $format =~ s/%u/$uuid/g;
+    }
+    if ( $format =~ /%l/ ) {
+        my $luid = $self->luid;
+        $format =~ s/%l/$luid/g;
+    }
+    return sprintf( $format,
+        map { $self->prop($_) || "(no $_)" } $self->summary_props );
+
+}
+
+=head2 find_or_create_luid
+
+Finds the luid for the records uuid, or creates a new one. Returns the luid.
 
-    return sprintf( $format, map { $self->prop($_) || "(no $_)" } $self->summary_props );
+=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;
 }
 
 =head2 find_or_create_luid

Modified: Prophet/trunk/lib/Prophet/Test/Participant.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test/Participant.pm	(original)
+++ Prophet/trunk/lib/Prophet/Test/Participant.pm	Sat May 17 05:36:09 2008
@@ -84,8 +84,8 @@
     my ( $ret, $out, $err ) = call_func_ok( [ qw(create --type Scratch), @{ $args->{props} } ] );
 
     #    ok($ret, $self->name . " created a record");
-    if ( $out =~ /Created\s+(.*?)\s+(.*)$/i ) {
-        $args->{result} = $2;
+    if ( $out =~ /Created\s+(.*?)\s+(\d+)\s+\((.*)\)/i ) {
+        $args->{result} = $3;
     }
     $self->record_action( 'create_record', $args );
 }

Modified: Prophet/trunk/t/edit.t
==============================================================================
--- Prophet/trunk/t/edit.t	(original)
+++ Prophet/trunk/t/edit.t	Sat May 17 05:36:09 2008
@@ -7,8 +7,8 @@
 $ENV{'PROPHET_REPO'} = tempdir( CLEANUP => 0 ) . '/repo-' . $$;
 my $prophet = Prophet::CLI->new;
 
-my $uuid;
-my $created_re = qr/Created Robot Master (\S+)(?{ $uuid = $1 })/;
+my ($luid,  $uuid);
+my $created_re = qr/Created Robot Master (\d+)(?{ $luid = $1}) \((\S+)(?{ $uuid = $2 })\)/;
 my $updated_re = qr/Robot Master (\S+)(?{ $uuid = $1 }) updated/;
 my $invoked_editor = 0;
 

Modified: Prophet/trunk/t/export.t
==============================================================================
--- Prophet/trunk/t/export.t	(original)
+++ Prophet/trunk/t/export.t	Sat May 17 05:36:09 2008
@@ -38,7 +38,12 @@
     run_output_matches(
         'prophet',
         ['show', '--type',            'Bug',             '--uuid', $record_id ],
-        [ 'id: ' . $record_id, 'status: stalled', 'from: alice' ],
+        [
+       
+        qr/id: (\d+) \($record_id\)/,
+        
+        
+        'status: stalled', 'from: alice' ],
         'content is correct'
     );
 

Modified: Prophet/trunk/t/real-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/real-conflicting-merge.t	(original)
+++ Prophet/trunk/t/real-conflicting-merge.t	Sat May 17 05:36:09 2008
@@ -32,7 +32,9 @@
     run_output_matches(
         'prophet',
         [ 'show', '--type',            'Bug',             '--uuid', $record_id ],
-        [ 'id: ' . $record_id, 'status: stalled', 'from: alice' ],
+        [
+        qr/id: (\d+) \($record_id\)/,
+        'status: stalled', 'from: alice' ],
         'content is correct'
     );
 };
@@ -42,7 +44,9 @@
     run_output_matches(
         'prophet',
         [ 'show', '--type',            'Bug',          '--uuid', $record_id ],
-        [ 'id: ' . $record_id, 'status: open', 'from: alice' ],
+        [ 
+        qr/id: (\d+) \($record_id\)/,
+        'status: open', 'from: alice' ],
         'content is correct'
     );
 

Modified: Prophet/trunk/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/simple-conflicting-merge.t	(original)
+++ Prophet/trunk/t/simple-conflicting-merge.t	Sat May 17 05:36:09 2008
@@ -32,7 +32,7 @@
     run_output_matches(
         'prophet',
         [ 'show','--type',            'Bug',             '--uuid', $record_id ],
-        [ 'id: ' . $record_id, 'status: stalled', 'from: alice' ],
+        [ qr/id: (\d+) \($record_id\)/, 'status: stalled', 'from: alice' ],
         'content is correct'
     );
 };
@@ -42,7 +42,7 @@
     run_output_matches(
         'prophet',
         ['show', '--type',            'Bug',             '--uuid', $record_id ],
-        [ 'id: ' . $record_id, 'status: stalled', 'from: alice' ],
+        [ qr/id: (\d+) \($record_id\)/, 'status: stalled', 'from: alice' ],
         'content is correct'
     );
 



More information about the Bps-public-commit mailing list