[Bps-public-commit] r12432 - in Prophet/branches/luid: lib/Prophet/Test t
jesse at bestpractical.com
jesse at bestpractical.com
Sat May 17 05:28:54 EDT 2008
Author: jesse
Date: Sat May 17 05:28:52 2008
New Revision: 12432
Modified:
Prophet/branches/luid/lib/Prophet/CLI.pm
Prophet/branches/luid/lib/Prophet/Record.pm
Prophet/branches/luid/lib/Prophet/Test/Participant.pm
Prophet/branches/luid/t/edit.t
Prophet/branches/luid/t/export.t
Prophet/branches/luid/t/real-conflicting-merge.t
Prophet/branches/luid/t/simple-conflicting-merge.t
Log:
* 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/branches/luid/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/branches/luid/lib/Prophet/CLI.pm (original)
+++ Prophet/branches/luid/lib/Prophet/CLI.pm Sat May 17 05:28:52 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/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:28:52 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,8 +136,7 @@
return $self->uuid;
}
-=head2 load { uuid => $UUID }
-=head2 load { luid => $UUID }
+=head2 load { uuid => $UUID } or { luid => $UUID }
Loads a Prophet record off disk by its uuid or luid.
@@ -142,31 +145,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 +209,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 +225,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 +255,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 +281,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,10 +317,16 @@
sub format_summary {
my $self = shift;
my $format = $self->summary_format;
- my $uuid = $self->uuid;
- $format =~ s/%u/$uuid/g;
-
- return sprintf( $format, map { $self->prop($_) || "(no $_)" } $self->summary_props );
+ 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 );
}
@@ -314,7 +338,7 @@
sub find_or_create_luid {
my $self = shift;
- my $luid = $self->handle->find_or_create_luid(uuid => $self->uuid);
+ my $luid = $self->handle->find_or_create_luid( uuid => $self->uuid );
$self->luid($luid);
return $luid;
}
Modified: Prophet/branches/luid/lib/Prophet/Test/Participant.pm
==============================================================================
--- Prophet/branches/luid/lib/Prophet/Test/Participant.pm (original)
+++ Prophet/branches/luid/lib/Prophet/Test/Participant.pm Sat May 17 05:28:52 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/branches/luid/t/edit.t
==============================================================================
--- Prophet/branches/luid/t/edit.t (original)
+++ Prophet/branches/luid/t/edit.t Sat May 17 05:28:52 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/branches/luid/t/export.t
==============================================================================
--- Prophet/branches/luid/t/export.t (original)
+++ Prophet/branches/luid/t/export.t Sat May 17 05:28:52 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/branches/luid/t/real-conflicting-merge.t
==============================================================================
--- Prophet/branches/luid/t/real-conflicting-merge.t (original)
+++ Prophet/branches/luid/t/real-conflicting-merge.t Sat May 17 05:28:52 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/branches/luid/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/branches/luid/t/simple-conflicting-merge.t (original)
+++ Prophet/branches/luid/t/simple-conflicting-merge.t Sat May 17 05:28:52 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