line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::Thing::pm::ScopeMatcher; |
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::ScopeMatcher.pm |
11
|
|
|
|
|
|
|
# Description: Extract the matching scope out of a program |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 17/08/2005 Auto generated file |
16
|
|
|
|
|
|
|
# 17/08/2005 Started to do this in multiple places |
17
|
|
|
|
|
|
|
# 26/10/2005 Added method: getScope |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
6
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
323
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# get_scope_of_string - return the scope of the string |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_scope_of_string { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
1
|
|
my ($string, $code) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $current_scope = ""; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
foreach my $line (split(/\n/, $code)) { |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
next if ($line =~ /^\#/); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ($line =~ /^sub/) { |
43
|
|
|
|
|
|
|
# restart the scope |
44
|
0
|
|
|
|
|
|
$current_scope = ""; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$current_scope .= $line . "\n"; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($line =~ /$string/) { |
50
|
0
|
|
|
|
|
|
return $current_scope; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# not found in scope |
56
|
0
|
|
|
|
|
|
return ""; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
############################################################################### |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# get_scope_of_line - return the scope of a given line number |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
############################################################################### |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_scope_of_line { |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
1
|
|
my ($line_number, $filename) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $current_scope = ""; |
72
|
0
|
|
|
|
|
|
my $line_count = 0; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
foreach my $line (Goo::FileUtilities::get_file_as_lines($filename)) { |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$line_count++; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# ignore comments |
79
|
0
|
0
|
|
|
|
|
next if ($line =~ /^\#/); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($line =~ /^sub/) { |
82
|
|
|
|
|
|
|
# restart the scope |
83
|
0
|
|
|
|
|
|
$current_scope = ""; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$current_scope .= $line; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ($line_count == $line_number) { |
89
|
0
|
|
|
|
|
|
return $current_scope; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# not found in scope |
95
|
0
|
|
|
|
|
|
return ""; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Goo::Thing::pm::ScopeMatcher - Extract the matching scope out of a program |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SYNOPSIS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
use Goo::Thing::pm::ScopeMatcher; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 METHODS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item get_scope_of_string |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return the scope of the current string |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item get_scope_of_line |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return the scope of a given line number |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SEE ALSO |
134
|
|
|
|
|
|
|
|