Runner/Initializer.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 87 CC 3 SCAR 14.6
CC
3
Cov
0%
AUTOLOAD
12.0
new
2.0
loadParameters
2.0
CRAP 4.3
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::Initializer;
42  
43 use Carp;
44 use strict;
45  
46 use BabelObjects::Util::Dvlpt::Log;
47  
48 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
49 use XML::DOM;
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 $VERSION = '1.00';
60  
61 my $doc;
62 my $aLog;
63  
64 my %fields = (
65 cfg => undef
66 );
67
68 sub new {
69 my $proto = shift;
70 my $args = shift;
71  
72 my $class = ref($proto) || $proto;
73  
74 my $self = {
75 _permitted => \%fields,
76 %fields,
77 };
78
79 bless ($self, $class);
80  
81 my %parameters = %$args;
82  
83 $aLog = new BabelObjects::Util::Dvlpt::Log();
84 $aLog->log("\n-- BabelObjects::Runner::Initializer --");
85  
86 foreach (keys %parameters) {
87 # the following lines are useful to verify argument values
88 $aLog->log("Before : $_ = ".$parameters{$_});
89 $self->$_($parameters{$_});
90 $aLog->log("After : $_ = ".$self->$_);
91 }
92  
93 $self->loadParameters();
94  
95 return $self;
96 }
97
98 sub loadParameters {
99 my $self = shift;
100  
101 $aLog->log("Start - loadParameters()");
102  
103 $aLog->log("new Parser()");
104 my $parser = new XML::DOM::Parser(NoLWP => 1);
105  
106 $aLog->log("parsefile()");
107 $doc = $parser->parsefile($self->cfg);
108  
109 $aLog->log("End - loadParameters()");
110 }
111  
112 sub getParameters {
113 my $self = shift;
114  
115 return $doc;
116 }
117  
118 sub AUTOLOAD {
119 my $self = shift;
120 my $type = ref($self) or croak "$self is not an object";
121
122 my $name = $AUTOLOAD;
123 $name =~ s/.*://; # strip fully-qualified portion
124
125 unless (exists $self->{_permitted}->{$name} ) {
126 croak "Can't access `$name' field in class $type";
127 }
128
129 # Gérer le cas des attributs multivalués
130 if (@_) {
131 return $self->{$name} = shift;
132 } else {
133 return $self->{$name};
134 }
135 }
136
137 1;
138  
139 __END__