line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::EditorEdit; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
177084
|
$Term::EditorEdit::VERSION = '0.0016'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Edit a document via $EDITOR |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# prompt_Yn, prompt_yN |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
18
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
55
|
|
11
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
1717
|
use Any::Moose; |
|
2
|
|
|
|
|
74077
|
|
|
2
|
|
|
|
|
16
|
|
14
|
2
|
|
|
2
|
|
1284
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
152
|
|
15
|
2
|
|
|
2
|
|
2837
|
use File::Temp; |
|
2
|
|
|
|
|
53201
|
|
|
2
|
|
|
|
|
165
|
|
16
|
2
|
|
|
2
|
|
1262
|
use Term::EditorEdit::Edit; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
900
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub EDITOR { |
19
|
0
|
|
0
|
0
|
0
|
0
|
return $ENV{VISUAL} || $ENV{EDITOR}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $__singleton__; |
23
|
|
|
|
|
|
|
sub __singleton__ { |
24
|
1
|
|
33
|
1
|
|
33
|
return $__singleton__ ||=__PACKAGE__->new; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub edit_file { |
28
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
29
|
0
|
|
|
|
|
0
|
my $file = shift; |
30
|
0
|
0
|
|
|
|
0
|
die "*** Missing editor (No \$VISUAL or \$EDITOR)\n" unless my $editor = $self->EDITOR; |
31
|
0
|
|
|
|
|
0
|
my $rc = system $editor, $file; |
32
|
0
|
0
|
|
|
|
0
|
unless ( $rc == 0 ) { |
33
|
0
|
|
|
|
|
0
|
my ($exit_value, $signal, $core_dump); |
34
|
0
|
|
|
|
|
0
|
$exit_value = $? >> 8; |
35
|
0
|
|
|
|
|
0
|
$signal = $? & 127; |
36
|
0
|
|
|
|
|
0
|
$core_dump = $? & 128; |
37
|
0
|
|
|
|
|
0
|
die "Error during edit ($editor): exit value($exit_value), signal($signal), core_dump($core_dump): $!"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub edit { |
42
|
1
|
|
|
1
|
1
|
21
|
my $self = shift; |
43
|
1
|
50
|
|
|
|
12
|
$self = $self->__singleton__ unless blessed $self; |
44
|
1
|
|
|
|
|
71
|
my %given = @_; |
45
|
|
|
|
|
|
|
# carp "Ignoring remaining arguments: @_" if @_; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
5
|
my $document = delete $given{document}; |
48
|
1
|
50
|
|
|
|
6
|
$document = '' unless defined $document; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
3
|
my $file = delete $given{file}; |
51
|
1
|
50
|
|
|
|
28
|
$file = $self->tmp unless defined $file; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
858
|
my $edit = Term::EditorEdit::Edit->new( |
54
|
|
|
|
|
|
|
editor => $self, |
55
|
|
|
|
|
|
|
file => $file, |
56
|
|
|
|
|
|
|
document => $document, |
57
|
|
|
|
|
|
|
%given, # process, split, ... |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
7
|
return $edit->edit; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
0
|
11
|
sub tmp { return File::Temp->new( unlink => 1 ) } |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |