GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Term::CallEditor(3) User Contributed Perl Documentation Term::CallEditor(3)

Term::CallEditor - solicit data from an external editor

  use Term::CallEditor qw/solicit/;

  my $fh = solicit('FOO: please replace this text');
  die "$Term::CallEditor::errstr\n" unless $fh;

  print while readline $fh;

This module calls an external editor via the "solicit()" function, then returns any data from this editor as a file handle. The environment variables "VISUAL" and then "EDITOR" are consulted for a program name to run, otherwise falling back to vi(1). The Text::ParseWords "shellwords()" function is used to expand the environment variables.

"solicit()" returns a temporary file handle pointing to what was written in the editor (and also the filename in list context).

solicit
"solicit()" as a second argument accepts a number of optional parameters as a hash reference.

  solicit(
      "\x{8ACB}",
      {   skip_interactive => 1,
          binmode_layer    => ':utf8'
      }
  );
    
BINMODE => BOOLEAN
If true, enables "binmode" on the filehandle prior to writing the message to it.
DEFAULT_EDITOR => string
What to use as the default editor instead of vi(1).
NOSYNC => BOOLEAN
If true, "sync()" from IO::Handle will not be called. "sync()" is not called when on Win32, but otherwise is called by default.
binmode_layer => binmode layer
If set, enables "binmode" on the filehandle prior to writing the message to it.
safe_level => NUMBER
Set a custom "safe_level" value for the File::Temp method of that name.
skip_interactive => BOOLEAN
If true, "solicit" skips making a test to see whether the terminal is interactive.

On error, "solicit()" returns "undef". Consult $Term::CallEditor::errstr for details. Note that File::Temp may throw a fatal error if the "safe_level" checks fail, so paranoid coders should wrap the "solicit" call in an "eval" block (or instead use something like Syntax::Keyword::Try).

See also the "eg/solicit" script under the module distribution.
Pass in a block of text to the editor
Use a here doc:

  my $fh = solicit(<< "END_BLARB");

  FOO: This is an example designed to span multiple lines for
  FOO: the sake of an example that span multiple lines.
  END_BLARB
    
Shell Exec Wrapper
A shell exec wrapper may be necessary as a target for EDITOR (or VISUAL) as not all programs that support EDITOR (or VISUAL) perform shell word splitting on the input, and the "shellword" splitting (now) done by this module may not suffice for complicated shell commands:

  #!/bin/sh
  exec youreditor --some-arg "$@"
    

No known bugs.

Newer versions of this module may be available from CPAN.

If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome.

<https://github.com/thrig/Term-CallEditor>

This module relies heavily on the Unix terminal, permissions on the temporary directory (for the File::Temp module "safe_level" call), whether "system()" can actually run the "EDITOR" environment variable, and so forth.

vipe(1) of moreutils to use vi(1) in pipes.

https://unix.stackexchange.com/questions/4859/visual-vs-editor-what-s-the-difference

  "Most applications treat $VISUAL as a shell snippet that they append
  the (shell-quoted) file name to, but some treat it as the name of an
  executable which they may or may not search in $PATH. So it's best to
  set VISUAL (and EDITOR) to the full path to an executable (which could
  be a wrapper script if you want e.g. options)." -- Gilles

thrig - Jeremy Mates (cpan:JMATES) "<jmates at cpan.org>"

Copyright 2004 Jeremy Mates

This program is distributed under the (Revised) BSD License: <https://opensource.org/licenses/BSD-3-Clause>

Inspired from the CVS prompt-user-for-commit-message functionality.
2022-04-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.