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