line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::TextEditor; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::TextEditor.pm |
11
|
|
|
|
|
|
|
# Description: Run Nano, or your favourite editor |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 26/06/2005 Auto generated file |
16
|
|
|
|
|
|
|
# 26/06/2005 Needed to abstract this into one place |
17
|
|
|
|
|
|
|
# 15/10/2005 Create a hard symlink to: ln /home/search/dev/nanorc ~/.nanorc |
18
|
|
|
|
|
|
|
# for consist syntax highlighting on different machines |
19
|
|
|
|
|
|
|
# 08/11/2005 Added method: editString |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
############################################################################### |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
3995
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5
|
use Goo::Environment; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
26
|
1
|
|
|
1
|
|
6
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
329
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $editor_preference = { nigel => "/usr/bin/nano", |
29
|
|
|
|
|
|
|
sven => "/bin/vi" |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $viewer_preference = { nigel => "/usr/bin/nano -v" }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $default_editor = "/usr/bin/nano"; |
36
|
|
|
|
|
|
|
my $default_viewer = "/usr/bin/nano -v"; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
############################################################################### |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# edit - edit a file and save the results |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
############################################################################### |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub edit { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
my ($filename, $line_number) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
0
|
|
|
|
$line_number = $line_number || 1; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $programmer = Goo::Environment::get_user(); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# look up the editor for this programmer |
54
|
0
|
|
0
|
|
|
|
my $EDITOR = $editor_preference->{$programmer} || $default_editor; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# edit it with your favourite editor - nano / emacs / vi |
57
|
0
|
|
|
|
|
|
system("$EDITOR +$line_number $filename"); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
############################################################################### |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
# view - just view a file |
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
############################################################################### |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub view { |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
1
|
|
my ($filename, $line_number) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$line_number = $line_number || 1; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $programmer = Goo::Environment::get_user(); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# look up the editor for this programmer |
77
|
0
|
|
0
|
|
|
|
my $VIEWER = $viewer_preference->{$programmer} || $default_viewer; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# edit it with your favourite editor - nano / emacs / vi |
80
|
0
|
|
|
|
|
|
system("$VIEWER +$line_number $filename"); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
############################################################################### |
86
|
|
|
|
|
|
|
# |
87
|
|
|
|
|
|
|
# edit_string - edit a string in a text_editor |
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
############################################################################### |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub edit_string { |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
1
|
|
my ($string) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $rand = rand(1000); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# create a filename |
98
|
0
|
|
|
|
|
|
my $temp_filename = "/tmp/" . $rand . "-" . $$ . ".tmp"; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# write database value to a file |
101
|
0
|
|
|
|
|
|
Goo::FileUtilities::write_file($temp_filename, $string); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# edit the value |
104
|
0
|
|
|
|
|
|
edit($temp_filename); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# slurp the file back into RAM |
107
|
0
|
|
|
|
|
|
my $edited_string = Goo::FileUtilities::slurp($temp_filename); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
unlink($temp_filename); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $edited_string; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 NAME |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Goo::TextEditor - Run Nano, or your favourite editor |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SYNOPSIS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
use Goo::TextEditor; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 DESCRIPTION |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Edit a file with your favourite external text editor (e.g., vi, vim, nano etc.). |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 METHODS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item edit |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
edit a file and save the results |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item view |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
just view a file |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item edit_string |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
edit a string inside a text_editor |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHOR |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
155
|
|
|
|
|
|
|
|