[Bps-public-commit] r14835 - in Prophet/trunk: . lib/Prophet/CLI/Command

spang at bestpractical.com spang at bestpractical.com
Tue Aug 5 20:17:36 EDT 2008


Author: spang
Date: Tue Aug  5 20:17:32 2008
New Revision: 14835

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI/Command.pm
   Prophet/trunk/lib/Prophet/CLI/Command/Delete.pm
   Prophet/trunk/lib/Prophet/CLI/Command/History.pm
   Prophet/trunk/lib/Prophet/CLI/Command/Show.pm
   Prophet/trunk/lib/Prophet/CLI/Command/Update.pm

Log:
 r47747 at loki:  spang | 2008-08-06 00:08:59 +0100
 make commands that want a uuid explode more gracefully when none is given


Modified: Prophet/trunk/lib/Prophet/CLI/Command.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command.pm	Tue Aug  5 20:17:32 2008
@@ -22,6 +22,22 @@
     die $reason . "\n";
 }
 
+=head2 require_uuid
+
+Checks to make sure the uuid attribute is set. Prints an error and dies
+if it is not set.
+
+=cut
+
+sub require_uuid {
+    my $self    = shift;
+
+    if (!$self->uuid) {
+        my $type = $self->type;
+        my $name = (split /::/, $self->meta->name)[-1];
+        die "\u$type \l$name requires a luid or uuid (use --id to specify).\n";
+    }
+}
 
 =head2 edit_text [text] -> text
 

Modified: Prophet/trunk/lib/Prophet/CLI/Command/Delete.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Delete.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Delete.pm	Tue Aug  5 20:17:32 2008
@@ -6,7 +6,9 @@
 sub run {
     my $self = shift;
 
+    $self->require_uuid;
     my $record = $self->_load_record;
+
     if ( $record->delete ) {
         print $record->type . " " . $record->uuid . " deleted.\n";
     } else {

Modified: Prophet/trunk/lib/Prophet/CLI/Command/History.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/History.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/History.pm	Tue Aug  5 20:17:32 2008
@@ -6,7 +6,9 @@
 sub run {
     my $self = shift;
 
+    $self->require_uuid;
     my $record = $self->_load_record;
+
     print "History for record " . $record->luid . " (" . $record->uuid . ")\n\n";
     for my $changeset ($record->changesets) {
         my @changes = grep { $_->record_uuid eq $record->uuid }

Modified: Prophet/trunk/lib/Prophet/CLI/Command/Show.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Show.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Show.pm	Tue Aug  5 20:17:32 2008
@@ -7,6 +7,7 @@
 sub run {
     my $self = shift;
 
+    $self->require_uuid;
     my $record = $self->_load_record;
 
     print $self->stringify_props(

Modified: Prophet/trunk/lib/Prophet/CLI/Command/Update.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Update.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Update.pm	Tue Aug  5 20:17:32 2008
@@ -13,7 +13,9 @@
 sub run {
     my $self = shift;
 
+    $self->require_uuid;
     my $record = $self->_load_record;
+
     my $result = $record->set_props( props => $self->edit_record($record) );
     if ($result) {
         print $record->type . " " . $record->luid . " (".$record->uuid.")"." updated.\n";



More information about the Bps-public-commit mailing list