line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Anansi::Script; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Anansi::Script - Manages how Perl script user input and process output should be handled. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#!/usr/bin/perl |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Anansi::Script; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $OBJECT = Anansi::Script->new(); |
15
|
|
|
|
|
|
|
if(defined($OBJECT)) { |
16
|
|
|
|
|
|
|
my $channels = $OBJECT->channel(); |
17
|
|
|
|
|
|
|
if(defined($channels)) { |
18
|
|
|
|
|
|
|
my %channelHash = map { $_ => 1 } (@{$channels}); |
19
|
|
|
|
|
|
|
if(defined($channelHash{MEDIUM})) { |
20
|
|
|
|
|
|
|
my $medium = $OBJECT->channel('MEDIUM'); |
21
|
|
|
|
|
|
|
if('CGI' eq $medium) { |
22
|
|
|
|
|
|
|
$OBJECT->channel('CONTENT', << "HEREDOC" |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This Perl script was run using the Common Gateway Interface. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
HEREDOC |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} elsif('SHELL' eq $medium) { |
31
|
|
|
|
|
|
|
$OBJECT->channel('CONTENT', 'This Perl script was run using the Shell.'."\n"); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Determines the medium used to run the Perl Script and implements the resources |
42
|
|
|
|
|
|
|
to handle the user input and process output. Simplifies the interaction |
43
|
|
|
|
|
|
|
mechanism and enables the Perl Script to be used in different mediums. See |
44
|
|
|
|
|
|
|
L for inherited methods. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
67788
|
use base qw(Anansi::ComponentManager); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
700
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 addChannel |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Declared in L. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 addComponent |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$OBJECT->SUPER::addComponent(undef); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$OBJECT->Anansi::ComponentManager::addComponent(undef); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Declared in L. Overridden by this module. Redeclared |
73
|
|
|
|
|
|
|
in order to preclude inheritance. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
0
|
1
|
|
sub addComponent { |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 channel |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Declared in L. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 component |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Declared in L. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 componentIdentification |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Declared in L. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 components |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Declared in L. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 DESTROY |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Declared in L. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 finalise |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$OBJECT->SUPER::finalise(undef); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$OBJECT->Anansi::Script::finalise(undef); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Declared as a virtual method in L. Overridden by this module. |
124
|
|
|
|
|
|
|
Indirectly called during object destruction. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub finalise { |
130
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
131
|
0
|
|
|
|
|
|
my $components = $self->components(); |
132
|
0
|
0
|
|
|
|
|
if(defined($components)) { |
133
|
0
|
|
|
|
|
|
foreach my $component (@{$components}) { |
|
0
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $result = $self->SUPER::removeComponent($component); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 fixate |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Declared as a virtual method in L. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 implicate |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Declared as a virtual method in L. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 import |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Declared in L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 initialise |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$OBJECT::SUPER->initialise(@_); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$OBJECT->Anansi::Script::initialise(@_); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Declared as a virtual method in L. Overridden by this module. |
168
|
|
|
|
|
|
|
Indirectly called during object construction. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub initialise { |
174
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
175
|
0
|
|
|
|
|
|
my $component = $self->SUPER::addComponent(undef, %parameters); |
176
|
0
|
|
|
|
|
|
$self->channelComponent($component); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 new |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Declared in L. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 old |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Declared in L. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 priorities |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Declared in L. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 reinitialise |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Declared as a virtual method in L. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 removeChannel |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Declared in L. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 removeComponent |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$OBJECT->SUPER::removeComponent(undef); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
$OBJECT->Anansi::ComponentManager::removeComponent(undef); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Declared in L. Overridden by this module. Redeclared |
222
|
|
|
|
|
|
|
in order to preclude inheritance. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
0
|
1
|
|
sub removeComponent { |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 used |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Declared in L. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 uses |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Declared in L. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=cut |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 METHODS |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 channelComponent |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
my $return = $OBJECT->channelComponent($component, 'some channel'); |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Attempts to create a new subroutine to enable the direct use of a channel of the |
255
|
|
|
|
|
|
|
currently loaded component and define it as a channel of this module. If a |
256
|
|
|
|
|
|
|
channel with the same name as the component channel already is defined for this |
257
|
|
|
|
|
|
|
module then it silently fails. If a subroutine with the same name as the |
258
|
|
|
|
|
|
|
channel does not exist in this module's namespace then that subroutine name is |
259
|
|
|
|
|
|
|
used otherwise it remains anonymous. Returns B<0> I<(zero)> on failure and B<1> |
260
|
|
|
|
|
|
|
I<(one)> on success. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub channelComponent { |
266
|
0
|
|
|
0
|
1
|
|
my ($self, $component) = @_; |
267
|
0
|
|
|
|
|
|
my $componentChannels = $self->component($component); |
268
|
0
|
0
|
|
|
|
|
return 0 if(!defined($componentChannels)); |
269
|
0
|
|
|
|
|
|
my $channels = $self->channel(); |
270
|
0
|
0
|
|
|
|
|
$channels = map { $_ => 1 } (@{$channels}) if(defined($channels)); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
271
|
0
|
|
|
|
|
|
foreach my $channel (@{$componentChannels}) { |
|
0
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
next if('VALIDATE_AS_APPROPRIATE' eq $channel); |
273
|
0
|
0
|
|
|
|
|
if(defined($channels)) { |
274
|
0
|
0
|
|
|
|
|
next if(defined(${$channels}{$componentChannel})); |
|
0
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
} |
276
|
0
|
0
|
|
|
|
|
if(exists(&{ref($self).'::'.$channel})) { |
|
0
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
$self->addChannel( |
278
|
|
|
|
|
|
|
$channel => sub { |
279
|
0
|
|
|
0
|
|
|
my ($self, $channel, @parameters) = @_; |
280
|
0
|
|
|
|
|
|
return $self->component($component, $channel, (@parameters)); |
281
|
|
|
|
|
|
|
} |
282
|
0
|
|
|
|
|
|
); |
283
|
|
|
|
|
|
|
} else { |
284
|
0
|
|
|
|
|
|
*{ref($self).'::'.$channel} = sub { |
285
|
0
|
|
|
0
|
|
|
my ($self, $channel, @parameters) = @_; |
286
|
0
|
|
|
|
|
|
return $self->component($component, $channel, (@parameters)); |
287
|
0
|
|
|
|
|
|
}; |
288
|
0
|
|
|
|
|
|
$self->addChannel( |
289
|
|
|
|
|
|
|
$channel => ref($self).'::'.$channel |
290
|
|
|
|
|
|
|
); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
} |
293
|
0
|
|
|
|
|
|
return 1; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head1 NOTES |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
This module is designed to make it simple, easy and quite fast to code your |
300
|
|
|
|
|
|
|
design in perl. If for any reason you feel that it doesn't achieve these goals |
301
|
|
|
|
|
|
|
then please let me know. I am here to help. All constructive criticisms are |
302
|
|
|
|
|
|
|
also welcomed. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=cut |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 AUTHOR |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Kevin Treleaven treleaven I net> |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=cut |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
1; |
315
|
|
|
|
|
|
|
|