The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

0.1.5_4 (2015-08-04)

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.

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-2015 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.