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.03'; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
73568
|
use base qw(Anansi::ComponentManager); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1570
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 addComponent |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# N/A |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
An overridden inherited method to remove this functionality. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
1
|
|
sub addComponent { |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 finalise |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$OBJECT::SUPER->finalise(@_); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
An overridden virtual method called during object destruction. Not intended to |
77
|
|
|
|
|
|
|
be directly called unless overridden by a descendant. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub finalise { |
83
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
84
|
0
|
|
|
|
|
|
my $components = $self->components(); |
85
|
0
|
0
|
|
|
|
|
if(defined($components)) { |
86
|
0
|
|
|
|
|
|
foreach my $component (@{$components}) { |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $result = $self->SUPER::removeComponent($component); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 initialise |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$OBJECT::SUPER->initialise(@_); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
An overridden virtual method called during object creation. Not intended to be |
98
|
|
|
|
|
|
|
directly called unless overridden by a descendant. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub initialise { |
104
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
105
|
0
|
|
|
|
|
|
my $component = $self->SUPER::addComponent(undef, %parameters); |
106
|
0
|
|
|
|
|
|
$self->channelComponent($component); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 channelComponent |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $return = $OBJECT->channelComponent($component, 'some channel'); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Attempts to create a new subroutine to enable the direct use of a channel of the |
115
|
|
|
|
|
|
|
currently loaded component and define it as a channel of this module. If a |
116
|
|
|
|
|
|
|
channel with the same name as the component channel already is defined for this |
117
|
|
|
|
|
|
|
module then it silently fails. If a subroutine with the same name as the |
118
|
|
|
|
|
|
|
channel does not exist in this module's namespace then that subroutine name is |
119
|
|
|
|
|
|
|
used otherwise it remains anonymous. Returns 0 (FALSE) on failure and 1 (TRUE) |
120
|
|
|
|
|
|
|
on success. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub channelComponent { |
125
|
0
|
|
|
0
|
1
|
|
my ($self, $component) = @_; |
126
|
0
|
|
|
|
|
|
my $componentChannels = $self->component($component); |
127
|
0
|
0
|
|
|
|
|
return 0 if(!defined($componentChannels)); |
128
|
0
|
|
|
|
|
|
my $channels = $self->channel(); |
129
|
0
|
0
|
|
|
|
|
$channels = map { $_ => 1 } (@{$channels}) if(defined($channels)); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
foreach my $channel (@{$componentChannels}) { |
|
0
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
next if('VALIDATE_AS_APPROPRIATE' eq $channel); |
132
|
0
|
0
|
|
|
|
|
if(defined($channels)) { |
133
|
0
|
0
|
|
|
|
|
next if(defined(${$channels}{$componentChannel})); |
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
135
|
0
|
0
|
|
|
|
|
if(exists(&{ref($self).'::'.$channel})) { |
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$self->addChannel( |
137
|
|
|
|
|
|
|
$channel => sub { |
138
|
0
|
|
|
0
|
|
|
my ($self, $channel, @parameters) = @_; |
139
|
0
|
|
|
|
|
|
return $self->component($component, $channel, (@parameters)); |
140
|
|
|
|
|
|
|
} |
141
|
0
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
|
*{ref($self).'::'.$channel} = sub { |
144
|
0
|
|
|
0
|
|
|
my ($self, $channel, @parameters) = @_; |
145
|
0
|
|
|
|
|
|
return $self->component($component, $channel, (@parameters)); |
146
|
0
|
|
|
|
|
|
}; |
147
|
0
|
|
|
|
|
|
$self->addChannel( |
148
|
|
|
|
|
|
|
$channel => ref($self).'::'.$channel |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
return 1; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 removeComponent |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# N/A |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
An overridden inherited method to remove this functionality. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
0
|
1
|
|
sub removeComponent { |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Kevin Treleaven |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |