line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# This program is not guaranteed to work at all, and by using this # |
3
|
|
|
|
|
|
|
# program you release the author of any and all liability. # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# You may use this code as long as you are in compliance with the # |
6
|
|
|
|
|
|
|
# license (see the LICENSE file) and this notice, disclaimer and # |
7
|
|
|
|
|
|
|
# comment box remain intact and unchanged. # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# Package: Term::RouterCLI # |
10
|
|
|
|
|
|
|
# Class: Debugger # |
11
|
|
|
|
|
|
|
# Description: Methods for building a Router (Stanford) style CLI # |
12
|
|
|
|
|
|
|
# # |
13
|
|
|
|
|
|
|
# Written by: Bret Jordan (jordan at open1x littledot org) # |
14
|
|
|
|
|
|
|
# Created: 2011-08-24 # |
15
|
|
|
|
|
|
|
##################################################################### |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
package Term::RouterCLI::Debugger; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
5
|
|
48
|
use 5.8.8; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
196
|
|
23
|
5
|
|
|
5
|
|
40
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
153
|
|
24
|
5
|
|
|
5
|
|
36
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
127
|
|
25
|
5
|
|
|
5
|
|
8158
|
use Config::General; |
|
5
|
|
|
|
|
262324
|
|
|
5
|
|
|
|
|
468
|
|
26
|
5
|
|
|
5
|
|
8028
|
use Log::Log4perl; |
|
5
|
|
|
|
|
444681
|
|
|
5
|
|
|
|
|
45
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
29
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $hDebugConfig; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new |
35
|
|
|
|
|
|
|
{ |
36
|
29
|
|
|
29
|
0
|
82
|
my $pkg = shift; |
37
|
29
|
|
33
|
|
|
389
|
my $class = ref($pkg) || $pkg; |
38
|
|
|
|
|
|
|
|
39
|
29
|
|
|
|
|
65
|
my $self = {}; |
40
|
29
|
|
|
|
|
86
|
$self->{'_sName'} = $pkg; # Lets set the object name so we can use it in debugging |
41
|
29
|
|
|
|
|
107
|
bless ($self, $class); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Lets send any passed in arguments to the _init method |
44
|
29
|
|
|
|
|
134
|
$self->_init(@_); |
45
|
29
|
|
|
|
|
82
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _init |
49
|
|
|
|
|
|
|
{ |
50
|
29
|
|
|
29
|
|
58
|
my $self = shift; |
51
|
29
|
|
|
|
|
79
|
my %hParameters = @_; |
52
|
|
|
|
|
|
|
|
53
|
29
|
|
|
|
|
99
|
$self->{'_iDebug'} = 0; # This is for internal debugger debugging |
54
|
29
|
|
|
|
|
71
|
$self->{'_sFilename'} = undef; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Lets overwrite any defaults with values that are passed in |
57
|
29
|
50
|
|
|
|
111
|
if (%hParameters) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
0
|
foreach (keys (%hParameters)) { $self->{$_} = $hParameters{$_}; } |
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub DESTROY |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
66
|
0
|
|
|
|
|
0
|
$self = {}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# ---------------------------------------- |
72
|
|
|
|
|
|
|
# Public Methods |
73
|
|
|
|
|
|
|
# ---------------------------------------- |
74
|
|
|
|
|
|
|
sub SetFilename |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
# This method is for setting the filename for the configuration file |
77
|
|
|
|
|
|
|
# Required: |
78
|
|
|
|
|
|
|
# string(file name) |
79
|
3
|
|
|
3
|
0
|
9
|
my $self = shift; |
80
|
3
|
|
|
|
|
6
|
my $parameter = shift; |
81
|
3
|
50
|
|
|
|
22
|
if (defined $parameter) { $self->{'_sFilename'} = $parameter; } |
|
3
|
|
|
|
|
26
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub StartDebugger |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
# This method will load the log4perl configuration file |
87
|
3
|
|
|
3
|
0
|
8
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
3
|
|
|
|
|
61
|
my $oConfig = new Config::General |
90
|
|
|
|
|
|
|
( |
91
|
|
|
|
|
|
|
-ConfigFile => "$self->{'_sFilename'}", |
92
|
|
|
|
|
|
|
-LowerCaseNames => 0, |
93
|
|
|
|
|
|
|
-MergeDuplicateOptions => 1, |
94
|
|
|
|
|
|
|
-AutoTrue => 0, |
95
|
|
|
|
|
|
|
-ExtendedAccess => 1, |
96
|
|
|
|
|
|
|
-SaveSorted => 1 |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Lets get all of the configuration in one pass to save disk IO then lets save the data in to the object |
100
|
3
|
|
|
|
|
17653
|
my %hConfiguration = $oConfig->getall(); |
101
|
3
|
|
|
|
|
94
|
$hDebugConfig = \%hConfiguration; |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
23
|
Log::Log4perl::init($hDebugConfig); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub ReloadDebuggerConfiguration |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
# This method will reload the current debugger configuration that is in memory allowing us to turn |
109
|
|
|
|
|
|
|
# debugging on and off on the fly. |
110
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
111
|
0
|
|
|
|
|
0
|
Log::Log4perl::init($hDebugConfig); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub GetDebugConfig |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
# This method will return the global object for the Debug Configuration so that it can be edited on the fly |
117
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
118
|
0
|
|
|
|
|
0
|
return $hDebugConfig; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub GetLogger |
122
|
|
|
|
|
|
|
{ |
123
|
|
|
|
|
|
|
# This method is a helper method to get the Log4perl logger object |
124
|
3
|
|
|
3
|
0
|
3
|
my $self = shift; |
125
|
3
|
|
|
|
|
4
|
my $object = shift; |
126
|
3
|
|
|
|
|
5
|
my $package = ref($object); |
127
|
3
|
|
|
|
|
14
|
my @data = caller(1); |
128
|
3
|
|
|
|
|
13
|
my $caller = (split "::", $data[3])[-1]; |
129
|
3
|
|
|
|
|
9
|
my $sLoggerName = $package . "::" . $caller; |
130
|
|
|
|
|
|
|
|
131
|
3
|
50
|
|
|
|
11
|
print "+++ DEBUGGER +++ $sLoggerName\n" if ($self->{'_iDebug'} == 1); |
132
|
|
|
|
|
|
|
|
133
|
3
|
|
|
|
|
19
|
return Log::Log4perl->get_logger("$sLoggerName"); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub DumpArray |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
# This method is for dumping the contents of an array |
139
|
|
|
|
|
|
|
# Required: |
140
|
|
|
|
|
|
|
# array_ref (array of values) |
141
|
|
|
|
|
|
|
# Return: |
142
|
|
|
|
|
|
|
# string_ref (data from array) |
143
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
my $parameter = shift; |
145
|
0
|
|
|
|
|
|
my $sStringData = ""; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$sStringData .= "\t"; |
148
|
0
|
|
|
|
|
|
foreach (@$parameter) |
149
|
|
|
|
|
|
|
{ |
150
|
0
|
|
|
|
|
|
$sStringData .= "$_, "; |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
$sStringData .= "\n"; |
153
|
0
|
|
|
|
|
|
return \$sStringData; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub DumpHashKeys |
157
|
|
|
|
|
|
|
{ |
158
|
|
|
|
|
|
|
# This method is for dumping the contents of an array |
159
|
|
|
|
|
|
|
# Required: |
160
|
|
|
|
|
|
|
# hash_ref (array of values) |
161
|
|
|
|
|
|
|
# Return: |
162
|
|
|
|
|
|
|
# string_ref (data from array) |
163
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
164
|
0
|
|
|
|
|
|
my $parameter = shift; |
165
|
0
|
|
|
|
|
|
my $sStringData = ""; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$sStringData .= "\t"; |
168
|
0
|
|
|
|
|
|
foreach (keys(%$parameter)) |
169
|
|
|
|
|
|
|
{ |
170
|
0
|
|
|
|
|
|
$sStringData .= "$_, "; |
171
|
|
|
|
|
|
|
} |
172
|
0
|
|
|
|
|
|
$sStringData .= "\n"; |
173
|
0
|
|
|
|
|
|
return \$sStringData; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
return 1; |