[Bps-public-commit] r13326 - in App-Todo: bin lib/App

trs at bestpractical.com trs at bestpractical.com
Mon Jun 16 12:13:32 EDT 2008


Author: trs
Date: Mon Jun 16 12:13:31 2008
New Revision: 13326

Modified:
   App-Todo/   (props changed)
   App-Todo/bin/todo.pl
   App-Todo/lib/App/Todo.pm

Log:
 r36126 at zot:  tom | 2008-06-16 12:13:22 -0400
 Make the comment command use $EDITOR rather than STDIN


Modified: App-Todo/bin/todo.pl
==============================================================================
--- App-Todo/bin/todo.pl	(original)
+++ App-Todo/bin/todo.pl	Mon Jun 16 12:13:31 2008
@@ -408,21 +408,37 @@
 }
 
 sub comment_task {
-    my $task = get_task_id('comment on');
-    if(-t STDIN) {
-        print "Type your comment now. End with end-of-file or a dot on a line by itself.\n";
-    }
-    my $comment;
-    while(<STDIN>) {
-        chomp;
-        last if $_ eq ".";
-        $comment .= "\n$_";
+    my $task   = get_task_id('comment on');
+    my $editor = $ENV{EDITOR} || $ENV{VISUAL};
+    pod2usage(-message => "You need to specify a texteditor as \$EDITOR or \$VISUAL.",
+              -exitval => 1
+    ) unless $editor;
+
+    my $fh = File::Temp->new( UNLINK => 0 );
+    my $fn = $fh->filename;
+    $fh->close;
+
+    # Call the editor with the file as the first arg
+    system( "$editor $fn" );
+
+    # Slurp in the content
+    open (my $file, "<:utf8", $fn) || die("Can't open file '$fn': $!");
+    my $content;
+    {
+        local $/ = undef;
+        $content = <$file>;
     }
+    close($file);
 
     my $result = call(UpdateTask =>
                       id         => $task,
-                      comment    => $comment);
-    result_ok($result, "Commented on task");
+                      comment    => $content);
+
+    result_ok($result,
+              "Commented on task",
+              "Your comment is saved in the temporary file $fn.");
+    
+    unlink $fn;
 }
 
 sub get_task_id {

Modified: App-Todo/lib/App/Todo.pm
==============================================================================
--- App-Todo/lib/App/Todo.pm	(original)
+++ App-Todo/lib/App/Todo.pm	Mon Jun 16 12:13:31 2008
@@ -1,6 +1,6 @@
 package App::Todo;
 
-our $VERSION = 0.95;
+our $VERSION = 0.96;
 
 =head1 NAME
 



More information about the Bps-public-commit mailing list