line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Anansi::Script::Shell; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Anansi::Script::Shell - Defines the mechanisms specific to handling command line execution. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $OBJECT = Anansi::Script::Shell->new(); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
This module is designed to be an optional component module for use by the |
15
|
|
|
|
|
|
|
L component management module. It defines the processes |
16
|
|
|
|
|
|
|
specific to handling both input and output from Perl scripts that are executed |
17
|
|
|
|
|
|
|
from a command line. Uses L I<(indirectly)>, |
18
|
|
|
|
|
|
|
L and L. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
68796
|
use base qw(Anansi::ScriptComponent); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
602
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 addChannel |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Declared in L. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 channel |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Declared in L. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 componentManagers |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Declared in L. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 finalise |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$OBJECT->SUPER::finalise(); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$OBJECT->Anansi::Script::Shell::finalise(); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Declared in L. Overridden by this module. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub finalise { |
66
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
67
|
0
|
|
|
|
|
|
print $self->content(); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 implicate |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Declared in L. Intended to be overridden by an extending module. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 import |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Declared in L. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 initialise |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$OBJECT->SUPER::initialise(); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$OBJECT->Anansi::Script::Shell::initialise(); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Declared in L. Overridden by this module. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub initialise { |
97
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
98
|
0
|
|
|
|
|
|
$self->loadParameters(%parameters); |
99
|
0
|
|
|
|
|
|
$self->content(); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 old |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Declared in L. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 removeChannel |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Declared in L. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 used |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Declared in L. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 uses |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Declared in L. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 content |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $contents = $OBJECT->content(); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
if(1 == $OBJECT->content(undef, undef)); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
if(1 == $OBJECT->channel('CONTENT', undef)); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
if(1 == $OBJECT->content(undef, 'some content')); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
if(1 == $OBJECT->channel('CONTENT', 'some content')); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Either returns the existing content or redefines the content. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub content { |
154
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
155
|
0
|
|
|
|
|
|
my $channel; |
156
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 != scalar(@_)); |
157
|
0
|
0
|
|
|
|
|
$self->{CONTENTS} = '' if(!defined($self->{CONTENTS})); |
158
|
0
|
0
|
|
|
|
|
return $self->{CONTENTS} if(0 == scalar(@_)); |
159
|
0
|
|
|
|
|
|
my $content = shift(@_); |
160
|
0
|
0
|
|
|
|
|
return 0 if(0 < scalar(@_)); |
161
|
0
|
0
|
|
|
|
|
$content = '' if(!defined($content)); |
162
|
0
|
0
|
|
|
|
|
return 0 if(ref($content) !~ /^$/); |
163
|
0
|
|
|
|
|
|
$self->{CONTENTS} = $content; |
164
|
0
|
|
|
|
|
|
return 1; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Anansi::ScriptComponent::addChannel('Anansi::Script::Shell', 'CONTENT' => 'content'); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 loadParameters |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$OBJECT->loadParameters(); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Loads all of the argument values from the command line, assigning any names that |
175
|
|
|
|
|
|
|
are supplied to the values. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub loadParameters { |
181
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
182
|
0
|
0
|
|
|
|
|
$self->{PARAMETERS} = {} if(!defined($self->{PARAMETERS})); |
183
|
0
|
|
|
|
|
|
for(my $index = 0; $index < scalar(@ARGV); $index++) { |
184
|
0
|
0
|
|
|
|
|
if($ARGV[$index] =~ /^[a-zA-Z]+[a-zA-Z0-9_-]*=.*$/) { |
|
|
0
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my ($name, $value) = ($ARGV[$index] =~ /^([a-zA-Z]+[a-zA-Z0-9_-]*)=(.*)$/); |
186
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$name} = $value; |
|
0
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} elsif($ARGV[$index] =~ /^-[a-zA-Z]+[a-zA-Z0-9_-]*=.*$/) { |
188
|
0
|
|
|
|
|
|
my ($name, $value) = ($ARGV[$index] =~ /^-([a-zA-Z]+[a-zA-Z0-9_-]*)=(.*)$/); |
189
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$name} = $value; |
|
0
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
} else { |
191
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$index} = $ARGV[$index]; |
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 medium |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
my $medium = Anansi::Script::Shell->medium(); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $medium = $OBJECT->medium(); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $medium = $OBJECT->channel('MEDIUM'); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Returns the STRING description of the medium this module is designed to handle. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub medium { |
211
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
212
|
0
|
|
|
|
|
|
my $channel; |
213
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 < scalar(@_)); |
214
|
0
|
|
|
|
|
|
return 'SHELL'; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Anansi::ScriptComponent::addChannel('Anansi::Script::Shell', 'MEDIUM' => 'medium'); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 parameter |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $parameters = $OBJECT->parameter(); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
my $parameters = $OBJECT->channel('PARAMETER'); |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
my $parameterValue = $OBJECT->parameter(undef, 'parameter name'); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $parameterValue = $OBJECT->channel('PARAMETER', 'parameter name'); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
if($OBJECT->parameter(undef, 'parameter name' => 'parameter value', 'another parameter' => undef)); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
if($OBJECT->channel('PARAMETER', 'parameter name' => 'parameter value', 'another parameter' => undef)); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Either returns an ARRAY of all the existing parameter names or returns the value |
235
|
|
|
|
|
|
|
of a specific parameter or sets the value of one or more parameters. Assigning |
236
|
|
|
|
|
|
|
an "undef" value has the effect of deleting the parameter. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub parameter { |
242
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
243
|
0
|
|
|
|
|
|
my $channel; |
244
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 < scalar(@_)); |
245
|
0
|
0
|
|
|
|
|
if(0 == scalar(@_)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
246
|
0
|
0
|
|
|
|
|
return [] if(!defined($self->{PARAMETERS})); |
247
|
0
|
|
|
|
|
|
return [( keys(%{$self->{PARAMETERS}}) )]; |
|
0
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} elsif(1 == scalar(@_)) { |
249
|
0
|
|
|
|
|
|
my $name = shift(@_); |
250
|
0
|
0
|
|
|
|
|
return if(!defined($self->{PARAMETERS})); |
251
|
0
|
0
|
|
|
|
|
return if(!defined(${$self->{PARAMETERS}}{$name})); |
|
0
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
|
return ${$self->{PARAMETERS}}{$name}; |
|
0
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
} elsif(1 == scalar(@_) % 2) { |
254
|
0
|
|
|
|
|
|
return 0; |
255
|
|
|
|
|
|
|
} |
256
|
0
|
|
|
|
|
|
my ($name, %parameters) = @_; |
257
|
0
|
|
|
|
|
|
foreach my $name (keys(%parameters)) { |
258
|
0
|
0
|
|
|
|
|
if(defined(${$self->{PARAMETERS}}{$name})) { |
|
0
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$name} = $parameters{$name}; |
|
0
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
} else { |
261
|
0
|
|
|
|
|
|
delete(${$self->{PARAMETERS}}{$name}); |
|
0
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} |
264
|
0
|
|
|
|
|
|
return 1; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Anansi::ScriptComponent::addChannel('Anansi::Script::Shell', 'PARAMETER' => 'parameter'); |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head2 validate |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
my $valid = $OBJECT->validate(); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
my $valid = $OBJECT->channel('VALIDATE_AS_APPROPRIATE'); |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Determines whether this module is the correct one to use for handling Perl |
277
|
|
|
|
|
|
|
script execution. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
sub validate { |
283
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
284
|
0
|
|
|
|
|
|
my $channel; |
285
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 < scalar(@_)); |
286
|
0
|
|
|
|
|
|
return 1; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Anansi::ScriptComponent::addChannel('Anansi::Script::Shell', 'VALIDATE_AS_APPROPRIATE' => 'validate'); |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 NOTES |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
This module is designed to make it simple, easy and quite fast to code your |
295
|
|
|
|
|
|
|
design in perl. If for any reason you feel that it doesn't achieve these goals |
296
|
|
|
|
|
|
|
then please let me know. I am here to help. All constructive criticisms are |
297
|
|
|
|
|
|
|
also welcomed. |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=cut |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 AUTHOR |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
Kevin Treleaven treleaven I net> |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
1; |
310
|
|
|
|
|
|
|
|