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

sartak at bestpractical.com sartak at bestpractical.com
Sat May 10 20:36:41 EDT 2008


Author: sartak
Date: Sat May 10 20:36:37 2008
New Revision: 12217

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/Makefile.PL
   Prophet/trunk/lib/Prophet/CLI.pm

Log:
 r55520 at onn:  sartak | 2008-05-10 20:36:26 -0400
 Provide edit_text and edit_hash methods in Prophet::CLI::Command


Modified: Prophet/trunk/Makefile.PL
==============================================================================
--- Prophet/trunk/Makefile.PL	(original)
+++ Prophet/trunk/Makefile.PL	Sat May 10 20:36:37 2008
@@ -22,6 +22,7 @@
 requires('JSON');
 requires('Module::Pluggable');
 requires('File::Find::Rule');
+requires('Proc::InvokeEditor');
 
 features(
     'REST Server' => [

Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI.pm	Sat May 10 20:36:37 2008
@@ -158,6 +158,44 @@
     }
 }
 
+=head2 edit_text [text] -> text
+
+Filters the given text through the user's C<$EDITOR> using
+L<Proc::InvokeEditor>.
+
+=cut
+
+sub edit_text {
+    my $self = shift;
+    my $text = shift;
+
+    require Proc::InvokeEditor;
+    return scalar Proc::InvokeEditor->edit($text);
+}
+
+=head2 edit_hash hashref -> hashref
+
+Filters the hash through the user's C<$EDITOR> using L<Proc::InvokeEditor>.
+
+No validation is done on the input or output.
+
+=cut
+
+sub edit_hash {
+    my $self = shift;
+    my $hash = shift;
+
+    my $input = join "\n", map { "$_: $hash->{$_}\n" } keys %$hash;
+    my $output = $self->edit_text($input);
+
+    my $filtered;
+    while ($output =~ m{^(\S+?):(.*)$}g) {
+        $filtered->{$1} = $2;
+    }
+
+    return $filtered;
+}
+
 package Prophet::CLI::Command;
 
 use base qw/Class::Accessor/;



More information about the Bps-public-commit mailing list