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. See L for inherited methods. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
24974
|
use base qw(Anansi::Component); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1650
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 content |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $contents = $OBJECT->content(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# OR |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if(1 == $OBJECT->content(undef, undef)); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# OR |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if(1 == $OBJECT->channel('CONTENT', undef)); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# OR |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if(1 == $OBJECT->content(undef, 'some content')); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# OR |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if(1 == $OBJECT->channel('CONTENT', 'some content')); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Either returns the existing content or redefines the content. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub content { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
59
|
0
|
|
|
|
|
|
my $channel; |
60
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 != scalar(@_)); |
61
|
0
|
0
|
|
|
|
|
$self->{CONTENTS} = '' if(!defined($self->{CONTENTS})); |
62
|
0
|
0
|
|
|
|
|
return $self->{CONTENTS} if(0 == scalar(@_)); |
63
|
0
|
|
|
|
|
|
my $content = shift(@_); |
64
|
0
|
0
|
|
|
|
|
return 0 if(0 < scalar(@_)); |
65
|
0
|
0
|
|
|
|
|
$content = '' if(!defined($content)); |
66
|
0
|
0
|
|
|
|
|
return 0 if(ref($content) !~ /^$/); |
67
|
0
|
|
|
|
|
|
$self->{CONTENTS} = $content; |
68
|
0
|
|
|
|
|
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Script::Shell', 'CONTENT' => 'content'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 finalise |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$OBJECT::SUPER->finalise(@_); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
An overridden virtual method called during object destruction. Not intended to |
79
|
|
|
|
|
|
|
be directly called unless overridden by a descendant. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub finalise { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
86
|
0
|
|
|
|
|
|
print $self->content(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 initialise |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$OBJECT::SUPER->initialise(@_); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
An overridden virtual method called during object creation. Not intended to be |
95
|
|
|
|
|
|
|
directly called unless overridden by a descendant. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub initialise { |
101
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
102
|
0
|
|
|
|
|
|
$self->loadParameters(%parameters); |
103
|
0
|
|
|
|
|
|
$self->content(); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 loadParameters |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$OBJECT->loadParameters(); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Loads all of the argument values from the command line, assigning any names that |
112
|
|
|
|
|
|
|
are supplied to the values. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub loadParameters { |
118
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
119
|
0
|
0
|
|
|
|
|
$self->{PARAMETERS} = {} if(!defined($self->{PARAMETERS})); |
120
|
0
|
|
|
|
|
|
for(my $index = 0; $index < scalar(@ARGV); $index++) { |
121
|
0
|
0
|
|
|
|
|
if($ARGV[$index] =~ /^[a-zA-Z]+[a-zA-Z0-9_-]*=.*$/) { |
|
|
0
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my ($name, $value) = ($ARGV[$index] =~ /^([a-zA-Z]+[a-zA-Z0-9_-]*)=(.*)$/); |
123
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$name} = $value; |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} elsif($ARGV[$index] =~ /^-[a-zA-Z]+[a-zA-Z0-9_-]*=.*$/) { |
125
|
0
|
|
|
|
|
|
my ($name, $value) = ($ARGV[$index] =~ /^-([a-zA-Z]+[a-zA-Z0-9_-]*)=(.*)$/); |
126
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$name} = $value; |
|
0
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} else { |
128
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$index} = $ARGV[$index]; |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 medium |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $medium = Anansi::Script::Shell->medium(); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# OR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $medium = $OBJECT->medium(); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# OR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $medium = $OBJECT->channel('MEDIUM'); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns the STRING description of the medium this module is designed to handle. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub medium { |
152
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
153
|
0
|
|
|
|
|
|
my $channel; |
154
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 < scalar(@_)); |
155
|
0
|
|
|
|
|
|
return 'SHELL'; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Script::Shell', 'MEDIUM' => 'medium'); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 parameter |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
my $parameters = $OBJECT->parameter(); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# OR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my $parameters = $OBJECT->channel('PARAMETER'); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# OR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $parameterValue = $OBJECT->parameter(undef, 'parameter name'); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# OR |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my $parameterValue = $OBJECT->channel('PARAMETER', 'parameter name'); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# OR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
if($OBJECT->parameter(undef, 'parameter name' => 'parameter value', 'another parameter' => undef)); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# OR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
if($OBJECT->channel('PARAMETER', 'parameter name' => 'parameter value', 'another parameter' => undef)); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Either returns an ARRAY of all the existing parameter names or returns the value |
186
|
|
|
|
|
|
|
of a specific parameter or sets the value of one or more parameters. Assigning |
187
|
|
|
|
|
|
|
an "undef" value has the effect of deleting the parameter. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub parameter { |
193
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
194
|
0
|
|
|
|
|
|
my $channel; |
195
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 < scalar(@_)); |
196
|
0
|
0
|
|
|
|
|
if(0 == scalar(@_)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
return [] if(!defined($self->{PARAMETERS})); |
198
|
0
|
|
|
|
|
|
return [( keys(%{$self->{PARAMETERS}}) )]; |
|
0
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
} elsif(1 == scalar(@_)) { |
200
|
0
|
|
|
|
|
|
my $name = shift(@_); |
201
|
0
|
0
|
|
|
|
|
return if(!defined($self->{PARAMETERS})); |
202
|
0
|
0
|
|
|
|
|
return if(!defined(${$self->{PARAMETERS}}{$name})); |
|
0
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
return ${$self->{PARAMETERS}}{$name}; |
|
0
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
} elsif(1 == scalar(@_) % 2) { |
205
|
0
|
|
|
|
|
|
return 0; |
206
|
|
|
|
|
|
|
} |
207
|
0
|
|
|
|
|
|
my ($name, %parameters) = @_; |
208
|
0
|
|
|
|
|
|
foreach my $name (keys(%parameters)) { |
209
|
0
|
0
|
|
|
|
|
if(defined(${$self->{PARAMETERS}}{$name})) { |
|
0
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
${$self->{PARAMETERS}}{$name} = $parameters{$name}; |
|
0
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} else { |
212
|
0
|
|
|
|
|
|
delete(${$self->{PARAMETERS}}{$name}); |
|
0
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
0
|
|
|
|
|
|
return 1; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Script::Shell', 'PARAMETER' => 'parameter'); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 validate |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
my $valid = $OBJECT->validate(); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# OR |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my $valid = $OBJECT->channel('VALIDATE_AS_APPROPRIATE'); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Determines whether this module is the correct one to use for handling Perl |
230
|
|
|
|
|
|
|
script execution. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub validate { |
236
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
237
|
0
|
|
|
|
|
|
my $channel; |
238
|
0
|
0
|
|
|
|
|
$channel = shift(@_) if(0 < scalar(@_)); |
239
|
0
|
0
|
|
|
|
|
return 0 if(defined($ENV{'HTTP_HOST'})); |
240
|
0
|
|
|
|
|
|
return 1; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Script::Shell', 'VALIDATE_AS_APPROPRIATE' => 'validate'); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 AUTHOR |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Kevin Treleaven |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
1; |