line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::ThereDocManager; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::ThereDocManager.pm |
11
|
|
|
|
|
|
|
# Description: Process very simple ThereDocs --- looking for Things! |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 16/08/2005 Auto generated file |
16
|
|
|
|
|
|
|
# 16/08/2005 Needed a way to jump from Here to There |
17
|
|
|
|
|
|
|
# 23/10/2005 Created test file: ThereDocManagerTest.tpm |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
3584
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
14
|
use Goo::Object; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
24
|
1
|
|
|
1
|
|
6
|
use Goo::Loader; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
23
|
|
25
|
1
|
|
|
1
|
|
6
|
use Goo::Prompter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
26
|
1
|
|
|
1
|
|
5
|
use Goo::ThingFinder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
27
|
1
|
|
|
1
|
|
5
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
4
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
462
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# what is a there doc? |
32
|
|
|
|
|
|
|
my $default_mode = "E"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
############################################################################### |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# find_there_doc - find the line where the there_doc is found |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
############################################################################### |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub find_there_doc { |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
1
|
|
my ($this, $filename) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $line_count = 0; |
46
|
0
|
|
|
|
|
|
my $target_line = 0; # which line has a ThereDoc |
47
|
0
|
|
|
|
|
|
my $target = ""; # the string to target |
48
|
0
|
|
|
|
|
|
my $mode = ""; # the action mode |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my @new_lines; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# go through each line looking for ThereDocs |
53
|
0
|
|
|
|
|
|
foreach my $line (Goo::FileUtilities::get_file_as_lines($filename)) { |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$line_count++; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# match the ThereDoc a <<a |
58
|
0
|
0
|
|
|
|
|
if ($line =~ /([a-zA-Z\>])\>\>(.*)$/) { |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# what is the ThereDoc \>\>\> pointing to? |
61
|
0
|
|
|
|
|
|
$mode = uc($1); |
62
|
0
|
|
|
|
|
|
$target = $2; |
63
|
0
|
|
|
|
|
|
$target_line = $line_count; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# default to edit mode |
66
|
0
|
0
|
|
|
|
|
if ($mode eq ">") { $mode = "E"; } |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# remove the theredoc from the line |
69
|
0
|
|
|
|
|
|
$line =~ s/[a-zA-Z\>]\>\>//; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# keep all the lines |
74
|
0
|
|
|
|
|
|
push(@new_lines, $line); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# the lines should no longer contain ThereDocs |
79
|
0
|
|
|
|
|
|
Goo::FileUtilities::write_lines_as_file($filename, @new_lines); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# return the line_count and target of the last ThereDoc |
82
|
0
|
|
|
|
|
|
return ($mode, $target, $target_line); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
############################################################################### |
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
# process - given a string, look for there_docs and then do things if you |
90
|
|
|
|
|
|
|
# find one! |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
############################################################################### |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub process { |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
1
|
|
my ($this, $full_path) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# find the ThereDoc in the document |
99
|
0
|
|
|
|
|
|
my ($mode, $target_string, $theredoc_line_number) = $this->find_there_doc($full_path); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# look for any Things in the target |
102
|
0
|
|
|
|
|
|
my @things = Goo::ThingFinder::get_things($target_string); |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if (scalar(@things) > 1) { |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# we found some Things - pick one |
107
|
0
|
|
|
|
|
|
@things = Goo::Prompter::pick_one("Which Thing?", @things); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# if we found something |
111
|
0
|
0
|
|
|
|
|
if (scalar(@things) == 1) { |
112
|
0
|
|
|
|
|
|
return ($theredoc_line_number, Goo::Loader::load(pop(@things)), $mode); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#else { |
116
|
|
|
|
|
|
|
# # assume we're talking about the current Thing |
117
|
|
|
|
|
|
|
# return ($theredoc_line_number, Goo::Loader::load($full_path), $mode); |
118
|
|
|
|
|
|
|
#} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 NAME |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Goo::ThereDocManager - Process very simple ThereDocs --- looking for Things! |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SYNOPSIS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
use Goo::ThereDocManager; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
ThereDocs enable you to jump quickly from one Thing to another Thing while editing. |
138
|
|
|
|
|
|
|
Use a ThereDoc when you want to jump to "There". |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 METHODS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item find_there_doc |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
find the line where the ThereDoc is found |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item process |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
given a string, look for ThereDocs and then do the appropriate action |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 AUTHOR |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|