[Bps-public-commit] r16195 - sd/trunk/lib/App/SD/CLI/Command/Ticket

ruz at bestpractical.com ruz at bestpractical.com
Thu Oct 2 11:26:28 EDT 2008


Author: ruz
Date: Thu Oct  2 11:26:27 2008
New Revision: 16195

Modified:
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm

Log:
* add try againi for 'ticket create'

Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm	Thu Oct  2 11:26:27 2008
@@ -17,6 +17,7 @@
     if (!@prop_set || $self->has_arg('edit')) {
         my $ticket_string_to_edit = $self->create_record_string();
 
+        TRY_AGAIN:
         my $ticket = $self->edit_text($ticket_string_to_edit);
 
         die "Aborted.\n"
@@ -28,7 +29,18 @@
             $self->set_prop($prop => $props_ref->{$prop});
         }
 
-        super();
+        my $error;
+        {
+            local $@;
+            eval { super(); } or $error = $@ || "Something went wrong!";
+        }
+        if ( $error ) {
+            print STDERR "Couldn't create a record, error:\n\n", $error, "\n";
+            die "Aborted.\n" unless $self->prompt_Yn( "Want to return back to editing?" );
+
+            ($ticket_string_to_edit, $error) = ($ticket, '');
+            goto TRY_AGAIN;
+        }
 
         # retrieve the created record from the superclass
         $record = $self->record();
@@ -41,6 +53,16 @@
     }
 };
 
+sub prompt_Yn {
+    my $self = shift;
+    my $msg = shift;
+    print "$msg [Y/n]: ";
+    my $a = <>;
+    chomp $a;
+    return 1 if $a =~ /^(|y|yes)$/i;
+    return 0;
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 



More information about the Bps-public-commit mailing list