line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::Thing::pm::Perl5ThereDocManager; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::Thing::pm::Perl5ThereDocManager.pm |
11
|
|
|
|
|
|
|
# Description: Process ThereDocs embedded in 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
|
|
8681
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
10
|
use Goo::Loader; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
27
|
|
24
|
1
|
|
|
1
|
|
9
|
use Goo::Prompter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
25
|
1
|
|
|
1
|
|
7
|
use Goo::ThereDocManager; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
26
|
1
|
|
|
1
|
|
639
|
use Goo::Thing::pm::ScopeMatcher; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
29
|
|
27
|
1
|
|
|
1
|
|
532
|
use Goo::Thing::pm::MethodMatcher; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
6
|
use base qw(Goo::ThereDocManager); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
535
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
############################################################################### |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# find_package_and_method - return the method and package the there_doc is targetting |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
############################################################################### |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub find_package_and_method { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
1
|
|
my ($this, $target, $filename, $full_path, $target_line_number) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# a simple method call in this package |
43
|
0
|
0
|
|
|
|
|
if ($target =~ /\s+(\w+)\(/) { |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# package, method |
46
|
0
|
|
|
|
|
|
return ($filename, $1); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# a sub call in another package (e.g., Database::get_row()) |
50
|
0
|
0
|
|
|
|
|
if ($target =~ /(\w+)::(\w+)\(/) { |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# package, method |
53
|
0
|
|
|
|
|
|
return ($1 . ".pm", $2); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# a constructor call |
57
|
0
|
0
|
|
|
|
|
if ($target =~ /(\w+)\->(new)\(/) { |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# package, method |
60
|
0
|
|
|
|
|
|
return ($1 . ".pm", $2); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# a method call |
64
|
0
|
0
|
|
|
|
|
if ($target =~ /(\w+)\->(\w+)\(/) { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $referent = $1; |
67
|
0
|
|
|
|
|
|
my $method = $2; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# package, method |
70
|
0
|
0
|
|
|
|
|
return ($filename, $method) if ($referent =~ /\$(this|self)/); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# where is the referent from? |
73
|
|
|
|
|
|
|
# look for it in the current scope |
74
|
0
|
|
|
|
|
|
my $current_scope = |
75
|
|
|
|
|
|
|
Goo::Thing::pm::ScopeMatcher::get_scope_of_line($target_line_number, $full_path); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# For example, what is the package for $car? |
78
|
|
|
|
|
|
|
# my $car = Car->new() |
79
|
0
|
0
|
|
|
|
|
if ($current_scope =~ /my\s+\$$referent\s+=\s+(\w+)\->new\(/) { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# the referent is constructed in this scope |
82
|
|
|
|
|
|
|
# jump to this package |
83
|
0
|
|
|
|
|
|
return ($1 . ".pm", $method); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# check if the referent is a package method |
88
|
|
|
|
|
|
|
# my $car = CarFactory::get_car(); |
89
|
0
|
0
|
|
|
|
|
if ($current_scope =~ /my\s+\$$referent\s+=\s+(\w+)::(\w+)/) { |
90
|
|
|
|
|
|
|
### look up the referent in the current scope? |
91
|
|
|
|
|
|
|
# e.g. my $car = CarFactory::getCar |
92
|
0
|
|
|
|
|
|
return ($1 . ".pm", $2); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
############################################################################### |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# process - given a string, look for there_docs and then do things if you |
103
|
|
|
|
|
|
|
# find one! |
104
|
|
|
|
|
|
|
# |
105
|
|
|
|
|
|
|
############################################################################### |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub process { |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
0
|
1
|
|
my ($this, $thing) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# match the string the ThereDoc is targetting <<< this bit |
112
|
0
|
|
|
|
|
|
my ($mode, $target_string, $theredoc_line_number) = |
113
|
|
|
|
|
|
|
$this->find_there_doc($thing->get_full_path()); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Prompter::notify("found there_doc with mode $mode at $target_string + $theredoc_line_number"); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# which package and method is the ThereDoc targetting? |
118
|
0
|
|
|
|
|
|
my ($package, $method) = |
119
|
|
|
|
|
|
|
$this->find_package_and_method($target_string, $thing->get_filename(), |
120
|
|
|
|
|
|
|
$thing->get_full_path(), $theredoc_line_number); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
0
|
|
|
|
if ($package && $method) { |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Prompter::notify("ThereDoc targets: $package, $method"); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $target_thing = Goo::Loader::load($package); |
128
|
0
|
|
|
|
|
|
my $target_line_number = |
129
|
|
|
|
|
|
|
Goo::Thing::pm::MethodMatcher::get_line_number($method, $target_thing->get_file()); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# jump back to where we were before we did the jump? |
132
|
0
|
|
|
|
|
|
return ($theredoc_line_number, $target_thing, $mode, $target_line_number); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# does the user want to jump to another Thing? |
138
|
0
|
|
|
|
|
|
return $this->SUPER::process($thing->get_full_path()); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 NAME |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Goo::Thing::pm::Perl5ThereDocManager - Process ThereDocs embedded in Perl5 programs |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SYNOPSIS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
use Goo::Thing::pm::Perl5ThereDocManager; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 DESCRIPTION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 METHODS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=over |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item find_package_and_method |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
return the method and package the ThereDoc is targetting |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item process |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
given a string, look for ThereDocs and then carry out the first ThereDoc action. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHOR |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
179
|
|
|
|
|
|
|
|