Subject: | feature suggestion |
Date: | Fri, 09 Nov 2007 17:59:28 +0000 |
To: | bug-Proc-InvokeEditor [...] rt.cpan.org |
From: | Tim Booth <tbooth [...] ceh.ac.uk> |
Hi,
The module has been around for years and does exectly what it says on
the tin. However, one thing I found handy to add was a feature enabling
specifying the extension on the temporary file - (eg .xml)
The motivation for this is that the editor (Vim in my case) can use this
as a hint for syntax hilighting and the like when editing the buffer.
Patch is pretty trivial as the Tempfile module does all the work
already:
tbooth@barsukas[new]sudo diff -u /usr/share/perl5/Proc/InvokeEditor.pm /usr/share/perl5/Proc/InvokeEditor.pm.new
--- /usr/share/perl5/Proc/InvokeEditor.pm 2001-09-17 21:26:18.000000000 +0100
+++ /usr/share/perl5/Proc/InvokeEditor.pm.new 2007-11-09 17:55:50.000000000 +0000
@@ -101,6 +101,7 @@
sub edit {
my $self = shift;
my $arg = shift;
+ my $suff = shift;
# if the argument supplied is a reference to an array of lines,
# join it together based on the input record separator
if (ref($arg) eq 'ARRAY') {
@@ -108,9 +109,9 @@
}
my $result;
if (ref($self)) {
- $result = _edit($arg, $self->{'editors'}, $self->{'cleanup'});
+ $result = _edit($arg, $self->{'editors'}, $self->{'cleanup'}, $suff);
} else {
- $result = _edit($arg, \@DEFAULT_EDITORS, 1);
+ $result = _edit($arg, \@DEFAULT_EDITORS, 1, $suff);
}
if (wantarray) {
my @result = split m|$/|, $result;
@@ -164,6 +165,8 @@
my $string = shift;
my $er = shift;
my $unlink = shift;
+ my $suff = shift;
+
assert(ref($er) eq 'ARRAY');
assert(defined $unlink);
my @editors = @$er;
@@ -171,8 +174,11 @@
my $chosen_editor = first_usable(undef, $er);
+ my @suff;
+ @suff = (SUFFIX => $suff) if $suff;
+
# get a temp file, and write the text to it
- my ($fh, $filename) = tempfile(UNLINK => $unlink);
+ my ($fh, $filename) = tempfile(UNLINK => $unlink, @suff);
print $fh $string;
close $fh or die "Couldn't close tempfile [$filename]; $!";
# start the editor
Any takers?
TIM
--
This message (and any attachments) is for the recipient only. NERC
is subject to the Freedom of Information Act 2000 and the contents
of this email and any reply you make may be disclosed by NERC unless
it is exempt from release under the Act. Any material supplied to
NERC may be stored in an electronic records management system.