[Bps-public-commit] r16341 - in Prophet/trunk: .

jesse at bestpractical.com jesse at bestpractical.com
Fri Oct 17 22:17:30 EDT 2008


Author: jesse
Date: Fri Oct 17 22:17:29 2008
New Revision: 16341

Added:
   Prophet/trunk/lib/Prophet/CLI/TextEditorCommand.pm
Modified:
   Prophet/trunk/   (props changed)

Log:
 r47002 at 31b:  jesse | 2008-10-18 00:27:27 +0100
  * added a command to let users edit a template in a textfile


Added: Prophet/trunk/lib/Prophet/CLI/TextEditorCommand.pm
==============================================================================
--- (empty file)
+++ Prophet/trunk/lib/Prophet/CLI/TextEditorCommand.pm	Fri Oct 17 22:17:29 2008
@@ -0,0 +1,48 @@
+package Prophet::CLI::TextEditorCommand;
+use Moose::Role;
+use Params::Validate qw/validate/;
+
+sub try_to_edit {
+    my $self = shift;
+    my %args = validate( @_,
+        {   template => 1,
+            record   => 0,
+        });
+
+
+    my $template = ${ $args{template} };
+
+    # do the edit
+    my $updated = $self->edit_text($template);
+
+    die "Aborted.\n" if $updated eq $template;    # user didn't change anything
+
+    $self->process_template(
+        template => $args{template},
+        edited   => $updated,
+        record   => $args{record}
+    );
+}
+
+sub handle_template_errors {
+    my $self = shift;
+    my %args = validate( @_, { error => 1, template_ref => 1, bad_template => 1 } );
+
+    $self->prompt_Yn("Want to return back to editing?") || die "Aborted.\n";
+
+    ${ $args{'template_ref'} }
+        = "=== Your template contained errors ====\n\n"
+        . $args{error} . "\n\n"
+        . $args{bad_template};
+    return 0;
+}
+
+=head1 calling code must implement
+
+run
+process_template
+
+=cut
+
+no Moose::Role;
+1;



More information about the Bps-public-commit mailing list