| 1 | #/*==================================================================== | ||
| 2 | # * Babel Objects, Version 1.0 | ||
| 3 | # * ==================================================================== | ||
| 4 | # * | ||
| 5 | # * Copyright (c) 2000 The Babel Objects Network. All rights reserved. | ||
| 6 | # * | ||
| 7 | # * This source file is subject to version 1.1 of The Babel Objects | ||
| 8 | # * License, that is bundled with this package in the file LICENSE, | ||
| 9 | # * and is available through the world wide web at : | ||
| 10 | # * | ||
| 11 | # * http://www.BabelObjects.Org/law/license/1.1.txt | ||
| 12 | # * | ||
| 13 | # * If you did not receive a copy of the Babel Objects license and are | ||
| 14 | # * unable to obtain it through the world wide web, please send a note | ||
| 15 | # * to license@BabelObjects.Org so we can mail you a copy immediately. | ||
| 16 | # * | ||
| 17 | # * -------------------------------------------------------------------- | ||
| 18 | # * | ||
| 19 | # * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | ||
| 20 | # * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 21 | # * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| 22 | # * DISCLAIMED. IN NO EVENT SHALL THE BABEL OBJECTS NETWORK OR | ||
| 23 | # * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 24 | # * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 25 | # * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
| 26 | # * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| 27 | # * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| 28 | # * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
| 29 | # * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | # * SUCH DAMAGE. | ||
| 31 | # * | ||
| 32 | # * ==================================================================== | ||
| 33 | # * | ||
| 34 | # * This software consists of voluntary contributions made by many | ||
| 35 | # * individuals on behalf of The Babel Objects Network. For more | ||
| 36 | # * information on The Babel Objects Network, please see | ||
| 37 | # * <http://www.BabelObjects.org/>. | ||
| 38 | # * | ||
| 39 | # */ | ||
| 40 | |||
| 41 | package BabelObjects::Runner::RunData; | ||
| 42 | |||
| 43 | use Carp; | ||
| 44 | use strict; | ||
| 45 | |||
| 46 | use BabelObjects::Util::Dvlpt::Log; | ||
| 47 | use BabelObjects::Util::Facility::XMLFacility; | ||
| 48 | |||
| 49 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); | ||
| 50 | |||
| 51 | require Exporter; | ||
| 52 | require AutoLoader; | ||
| 53 | |||
| 54 | @ISA = qw(Exporter AutoLoader); | ||
| 55 | # Items to export into callers namespace by default. Note: do not export | ||
| 56 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 57 | # Do not simply export all your public functions/methods/constants. | ||
| 58 | @EXPORT = qw( | ||
| 59 | ); | ||
| 60 | $VERSION = '1.00'; | ||
| 61 | |||
| 62 | my $aLog; | ||
| 63 | |||
| 64 | my %fields = ( | ||
| 65 | req => undef, | ||
| 66 | confParameters => undef | ||
| 67 | ); | ||
| 68 | |||
| 69 | sub new { | ||
| 70 | my $proto = shift; | ||
| 71 | my $args = shift; | ||
| 72 | |||
| 73 | my $class = ref($proto) || $proto; | ||
| 74 | |||
| 75 | my $self = { | ||
| 76 | _permitted => \%fields, | ||
| 77 | %fields, | ||
| 78 | }; | ||
| 79 | |||
| 80 | bless ($self, $class); | ||
| 81 | |||
| 82 | my %parameters = %$args; | ||
| 83 | |||
| 84 | $aLog = new BabelObjects::Util::Dvlpt::Log(); | ||
| 85 | #$aLog->log("\n-- BabelObjects::Runner::RunData --"); | ||
| 86 | |||
| 87 | foreach (keys %parameters) { | ||
| 88 | # the following lines are useful to verify argument values | ||
| 89 | #$aLog->log("Before : $_ = ".$parameters{$_}); | ||
| 90 | $self->$_($parameters{$_}); | ||
| 91 | #$aLog->log("After : $_ = ".$self->$_); | ||
| 92 | } | ||
| 93 | |||
| 94 | return $self; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub getParameter { | ||
| 98 | my $self = shift; | ||
| 99 | my $parameterName = shift; | ||
| 100 | |||
| 101 | #$aLog->log("Parameter Name = ".$parameterName); | ||
| 102 | |||
| 103 | if ($self->req =~ /CGI/ ) { | ||
| 104 | #$aLog->log("Web request = ".$self->req); | ||
| 105 | return $self->req->param($parameterName); | ||
| 106 | } else { | ||
| 107 | #$aLog->log("No web request = ".$self->req); | ||
| 108 | # we aren't in a web context because $self->req isn't a CGI object | ||
| 109 | my $req = $self->req; | ||
| 110 | return $$req{$parameterName}; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | sub getConfParameter { | ||
| 115 | my $self = shift; | ||
| 116 | my $path = shift; | ||
| 117 | |||
| 118 | #$aLog->log("getConfParameter"); | ||
| 119 | #$aLog->log(" Path = $path"); | ||
| 120 | |||
| 121 | my $doc = $self->confParameters; | ||
| 122 | #$aLog->log(" Doc = $doc"); | ||
| 123 | |||
| 124 | my $xmlHelper = new BabelObjects::Util::Facility::XMLFacility(); | ||
| 125 | my @results = $xmlHelper->getElementsByPath($doc, $path); | ||
| 126 | #my @results = $doc->getElementsByTagName("web"); | ||
| 127 | |||
| 128 | #$aLog->log(@results." results."); | ||
| 129 | #$aLog->log(" $path = ".$results[0]->getFirstChild()->getData()); | ||
| 130 | |||
| 131 | return $results[0]->getFirstChild->getData(); | ||
| 132 | } | ||
| 133 | |||
| 134 | sub getConfParameters { | ||
| 135 | my $self = shift; | ||
| 136 | |||
| 137 | return $self->confParameters; | ||
| 138 | } | ||
| 139 | |||
| 140 | sub AUTOLOAD { | ||
| 141 | my $self = shift; | ||
| 142 | my $type = ref($self) or croak "$self is not an object"; | ||
| 143 | |||
| 144 | my $name = $AUTOLOAD; | ||
| 145 | $name =~ s/.*://; # strip fully-qualified portion | ||
| 146 | |||
| 147 | unless (exists $self->{_permitted}->{$name} ) { | ||
| 148 | if ($name =~ /param/) { | ||
| 149 | # we aren't in a web context because req-param doesn't exist | ||
| 150 | my $parameterName = shift; | ||
| 151 | my %vars = $self->req; | ||
| 152 | return $vars{$parameterName}; | ||
| 153 | } else { | ||
| 154 | croak "Can't access `$name' field in class $type"; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | if (@_) { | ||
| 159 | return $self->{$name} = shift; | ||
| 160 | } else { | ||
| 161 | return $self->{$name}; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | 1; | ||
| 166 | |||
| 167 | __END__ |