~ubuntu-branches/ubuntu/trusty/libproc-invokeeditor-perl/trusty

« back to all changes in this revision

Viewing changes to lib/Proc/InvokeEditor.pm

  • Committer: Bazaar Package Importer
  • Author(s): Gunnar Wolf, gregor herrmann, Gunnar Wolf
  • Date: 2008-01-07 11:26:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080107112617-tmkj3rv9s9mn12we
Tags: 1.02-1
[ gregor herrmann ]
* debian/control: Added: Vcs-Svn field (source stanza); Vcs-Browser
  field (source stanza); Homepage field (source stanza).
* Set Maintainer to Debian Perl Group.
* Use dist-based URL in debian/watch.

[ Gunnar Wolf ]
* New upstream release
* Added myself as an uploader
* Bumped up standards-version to 3.7.3 (no changes needed)
* Upgraded dh_compat level to 5
* Listed the examples to be installed inside debian/rules, instead of
  an external file
* No longer ignores failure on make clean
* Debhelper is b-d, not b-d-i

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
29
29
 
30
 
 @EXPORT = qw(
 
30
@EXPORT = qw(
31
31
        
32
32
);
33
 
$VERSION = '0.02';
 
33
$VERSION = '1.02';
34
34
 
35
35
@DEFAULT_EDITORS = ( $ENV{'VISUAL'}, $ENV{'EDITOR'}, '/usr/bin/vi',
36
36
                     '/bin/vi', '/bin/ed'
101
101
sub edit {
102
102
  my $self = shift;
103
103
  my $arg = shift;
 
104
  my $suff = shift;
104
105
  # if the argument supplied is a reference to an array of lines,
105
106
  # join it together based on the input record separator
106
107
  if (ref($arg) eq 'ARRAY') {
108
109
  }
109
110
  my $result;
110
111
  if (ref($self)) {
111
 
    $result = _edit($arg, $self->{'editors'}, $self->{'cleanup'});
 
112
    $result = _edit($arg, $self->{'editors'}, $self->{'cleanup'}, $suff);
112
113
  } else {
113
 
    $result = _edit($arg, \@DEFAULT_EDITORS, 1);
 
114
    $result = _edit($arg, \@DEFAULT_EDITORS, 1, $suff);
114
115
  }
115
116
  if (wantarray) {
116
117
    my @result = split m|$/|, $result;
164
165
  my $string = shift;
165
166
  my $er = shift;
166
167
  my $unlink = shift;
 
168
  my $suff = shift;
 
169
 
167
170
  assert(ref($er) eq 'ARRAY');
168
171
  assert(defined $unlink);
169
172
  my @editors = @$er; 
171
174
 
172
175
  my $chosen_editor = first_usable(undef, $er); 
173
176
 
 
177
  my @suff;
 
178
  @suff = (SUFFIX => $suff) if $suff;
 
179
 
174
180
  # get a temp file, and write the text to it
175
 
  my ($fh, $filename) = tempfile(UNLINK => $unlink);
 
181
  my ($fh, $filename) = tempfile(UNLINK => $unlink, @suff);
176
182
  print $fh $string;
177
183
  close $fh or die "Couldn't close tempfile [$filename]; $!";
178
184
  # start the editor
313
319
  $editor->cleanup(0);
314
320
  my $result = $editor->edit($string);
315
321
 
 
322
A optional second argument is available $suff - example usage:
 
323
 
 
324
        my $reuslt = Proc::InvokeEditor->edit($string, '.xml');
 
325
 
 
326
This specifies a filename suffix to be used when the editor is launched - this
 
327
can be useful if the data in the file is of a particular type and you want to
 
328
trigger an editor's syntax highlighting mode.
 
329
 
316
330
=head1 TODO
317
331
 
318
332
=over 4
328
342
Michael Stevens E<lt>mstevens@etla.orgE<gt>. Also incorporating
329
343
suggestions and feedback from Leon Brocard and Phil Pennock.
330
344
 
 
345
Patches supplied by Tim Booth.
 
346
 
331
347
=head1 SEE ALSO
332
348
 
333
349
L<perl>.