Name

App::bif::Editor - run a system (text) editor

Version

0.1.5_8 (yyyy-mm-dd)

Synopsis

use App::bif::Editor;

my $editor = App::bif::Editor->new(txt => $some_text);

print "You edited the following:\n". $editor->result;

Description

App::bif::Editor starts a system editor, optionally with text that you provide, or on a filename you provide, and allows you to retrieve the result.

This does basically the same thing as Proc::InvokeEditor, however it has much simpler and less code, has less dependencies, should work on Win32, defaults to unicode, and more importantly doesn't use system() so we can still do stuff while the editor is running. For example, timesheet tracking that is accurate even when the user suspends their laptop.

As an aide for testing, if STDOUT is not connected to a terminal then no editor will be started and the result method will return the txt attribute.

Constructor

The new() constuctor takes the following arguments.

auto
By default the editor is started when the object is created. Set auto to a false value to inhibit this behaviour.
encoding
The Perl IO layer encoding to write and read the file with. Defaults to ':utf8'. Set it to ':raw' to get binary mode.
editor
The editor executable to run. If this is not given then the EDITOR environment variable will be used, and if that is empty then the following programs will be searched for using File::Which: sensible-editor, vim, vi, emacs, nano notepad. You can override the search list by setting @App::bif::Editor::EDITORS.
txt
The contents to write to the file before the editor starts. Note that this will OVERWRITE the contents of the filename attribute!
filename
A Path::Tiny filename to edit. Defaults to a temporary file.

Attributes

pid
The process ID of the editor program.

Methods

edit
Open the editor if it is not running. Can be called safely when the editor is already running.
result
Returns the contents of the filename.
wait_child
Wait for the editor process to finish.

See Also

Proc::FastSpawn, Proc::InvokeEditor

Author

Mark Lawrence <nomad@null.net>

Copyright And License

Copyright 2014-2017 Mark Lawrence <nomad@null.net>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.