NAME

IO::EditPrompt - Support a prompt that uses the configured editor to take long text

VERSION

This document describes IO::EditPrompt version 0.01

SYNOPSIS

use IO::EditPrompt;

my $p = IO::EditPrompt->new();
my $answer = $p->prompt( 'Explain in your own words:' );

my $p1 = IO::EditPrompt->new({ tmpdir=>'./tmp', editor=>'emacs' });
my $abstract = $p1->prompt( "Enter your abstract:\n(no HTML tags allowed)\n", 'Boilerplate abstract' );
my $write_up = $p1->prompt( <<EOH );
Enter a write-up of meeting:
  blank lines for paragraphs.
  <em/>, <strong/>, <a/> are all supported
EOH

DESCRIPTION

This module provides extended functionality for entering or changing text for command line programs.

The IO::Prompter module does a wonderful job of encapsulating a lot of user entry tasks in a really nice interface. One thing it does not do well is allow input for long-form text. Many version control systems use the approach of opening a window in your editor to deal with long-form text. This seems like a great solution and avoids a large number of nasty bits (like editing functions surrounding Unicode characters).

This module wraps up the functionality needed to use an editor in this fashion in a realtively straight-forward interface.

INTERFACE

new

Create new IO::EditPrompt object. This object can be used with multiple prompt calls. The optional paramters must be passed as a hashref.

dir

Specify a directory for the temporary file to edit.

default_editor

The name of a default editor if none is provided by the EDITOR environment variable.

editor

Force calling this program as the editor, independent of the environment. If this parameter is missing, the program will default to using the EDITOR environment variable. If there is no value for EDITOR, we try the supplied default_editor parameter. If none of these have values, we default to vim.

prompt( $prompt, $deftext )

Open the editor with the supplied $prompt and $deftext already filled in. Every line of the prompt text will be prefixed by the string # , the default text will be supplied as is. After the user saves any changes, the content of the file is read and any text that begins with # is removed. The result is returned to the caller.

If the cleaned up text is empty, the user is given an attempt to retry.

CONFIGURATION AND ENVIRONMENT

IO::EditPrompt relies on the EDITOR environment variable to supply a default editor to use.

DEPENDENCIES

  • File::Temp

  • IO::Prompter

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-io-editprompt@rt.cpan.org, or through the web interface at http://rt.cpan.org.

SEE ALSO

Other modules with related functionality include:

  • IO::Prompt

  • IO::Prompter

  • IO::Prompt::Tiny

  • IO::Prompt::Simple

  • Prompt::Timeout

  • Term::Prompt

AUTHOR

G. Wade Johnson <gwadej@cpan.org>

LICENCE AND COPYRIGHT

Copyright (c) 2015, G. Wade Johnson <gwadej@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.