annotate Lib/IMPL/Test/Plan.pm @ 94:79bf75223afe

Fixed security related bugs
author wizard
date Thu, 29 Apr 2010 01:31:27 +0400
parents 74bae30eb25e
children 4267a2ac3d46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
1 package IMPL::Test::Plan;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
5 use base qw(IMPL::Object);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
8 use IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
9 use IMPL::Test::Result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
10 use IMPL::Test::BadUnit;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
11 use Error qw(:try);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
13 use IMPL::Serialization;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
14 use IMPL::Serialization::XmlFormatter;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
16 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
17 public property Units => prop_all | prop_list;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
18 public property Results => prop_all | prop_list;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
19 public property Listeners => prop_all | prop_list;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
20 private property _Cache => prop_all | prop_list;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
21 private property _Count => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
22 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
23
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
24 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
25 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
26 $this->Units(\@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
27 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
28
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
29 sub restore {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
30 my ($class,$data,$instance) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
31
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
32 $instance ||= $class->surrogate;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
34 $instance->callCTOR();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
36 my %args = @$data;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
37
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
38 $instance->Units($args{Units});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
39 $instance->Results($args{Results}) if $args{Results};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
40 $instance->Listeners($args{Listeners}) if $args{Listeners};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
41 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
42
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
43 sub save {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
44 my ($this,$ctx) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
45
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
46 $ctx->AddVar(Units => [$this->Units]);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
47 $ctx->AddVar(Results => [$this->Results]) if $this->Results;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
48 $ctx->AddVar(Listeners => [$this->Listeners]) if $this->Listeners;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
49 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
50
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
51 sub AddListener {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
52 my ($this,$listener) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
53
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
54 $this->Listeners($this->Listeners,$listener);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
55 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
56
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
57 sub Prepare {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
58 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
60 my $count = 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
61 my @cache;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
62
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
63 foreach my $Unit ($this->Units){
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
64 my %info;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
65
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
66 # preload module
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
67 undef $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
68
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
69 eval "require $Unit" unless (ref $Unit);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
71 # handle loading errors
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
72 $Unit = new IMPL::Test::BadUnit($Unit,"Failed to load unit",$@) if $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
73
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
74 $info{Unit} = $Unit;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
75 try {
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
76 $info{Tests} = [$Unit->List];
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
77 } otherwise {
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
78 my $err = $@;
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
79 $Unit = $info{Unit} = new IMPL::Test::BadUnit(
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
80 $Unit->can('UnitName') ?
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
81 $Unit->UnitName :
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
82 $Unit,
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
83 "Failed to extract tests",
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
84 $err
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
85 );
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
86 $info{Tests} = [$Unit->List];
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
87 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
88 $count += @{$info{Tests}};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
89 push @cache, \%info if @{$info{Tests}};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
90 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
91
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
92 $this->_Count($count);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
93 $this->_Cache(\@cache);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
94 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
95
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
96 sub Count {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
97 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
98 return $this->_Count;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
99 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
100
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
101 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
102 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
103
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
104 die new IMPL::InvalidOperationException("You must call the prepare method before running the plan") unless $this->_Cache;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
105
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
106 $this->_Tell(RunPlan => $this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
107
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
108 my @resultsTotal;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
109
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
110 foreach my $info ($this->_Cache) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
111 $this->_Tell(RunUnit => $info->{Unit});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
112
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
113 my $data;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
114 undef $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
115 eval {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
116 $data = $info->{Unit}->StartUnit;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
117 };
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
118
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
119 my @results;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
120
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
121 if (not $@) {
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
122
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
123 foreach my $test (@{$info->{Tests}}) {
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
124 my $name = $test->Name;
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
125
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
126 #protected creation of the test
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
127 $test = eval { $info->{Unit}->new($test); } || new IMPL::Test::BadUnit(
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
128 $info->{Unit}->can('UnitName') ?
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
129 $info->{Unit}->UnitName :
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
130 $info->{Unit},
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
131 "Failed to construct the test $name",
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
132 $@
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
133 );
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
134
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
135 # invoke the test
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
136 $this->_Tell(RunTest => $test);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
137 my $result = $test->Run($data);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
138 $this->_Tell(EndTest => $test,$result);
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
139
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
140 push @results,$result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
141 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
142 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
143 my $e = $@;
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
144 my $badTest = new IMPL::Test::BadUnit(
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
145 $info->{Unit}->can('UnitName') ?
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
146 $info->{Unit}->UnitName :
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
147 $info->{Unit},
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
148 "Failed to initialize the unit",
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
149 $@
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
150 );
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
151 foreach my $test (@{$info->{Tests}}) {
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
152
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
153 $this->_Tell(RunTest => $badTest);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
154 my $result = new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
155 Name => $test->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
156 State => IMPL::Test::Result::FAIL,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
157 Exception => $e
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
158 );
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
159 $this->_Tell(EndTest => $badTest,$result);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
160 push @results,$result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
161 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
162 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
163
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
164 eval {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
165 $info->{Unit}->FinishUnit($data);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
166 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
167
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
168 undef $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
169
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
170 push @resultsTotal, { Unit => $info->{Unit}, Results => \@results};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
171
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
172 $this->_Tell(EndUnit => $info->{Unit},\@results);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
173 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
174
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
175 $this->Results(\@resultsTotal);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
176 $this->_Tell(EndPlan => $this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
177 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
178
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
179 sub _Tell {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
180 my ($this,$what,@args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
181
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
182 $_->$what(@args) foreach $this->Listeners;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
183 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
184
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
185 sub SaveXML {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
186 my ($this,$out) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
187
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
188 my $h;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
189
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
190 if (ref $out eq 'GLOB') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
191 $h = $out;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
192 } elsif ($out and not ref $out) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
193 open $h, ">", $out or die new IMPL::Exception("Failed to open file",$out);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
194 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
195 die new IMPL::InvalidOperationException("Invalid output specified");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
196 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
197
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
198 my $s = new IMPL::Serializer(Formatter => new IMPL::Serialization::XmlFormatter( IdentOutput => 1, SkipWhitespace => 1) );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
199 $s->Serialize($h,$this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
200 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
201
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
202 sub LoadXML {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
203 my ($self,$in) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
204
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
205 my $h;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
206
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
207 if (ref $in eq 'GLOB') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
208 $h = $in;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
209 } elsif ($in and not ref $in) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
210 open $h, ">", $in or die new IMPL::Exception("Failed to open file",$in);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
211 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
212 die new IMPL::InvalidOperationException("Invalid input specified");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
213 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
214
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
215 my $s = new IMPL::Serializer(Formatter => new IMPL::Serialization::XmlFormatter( IdentOutput => 1, SkipWhitespace => 1) );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
216 return $s->Deserialize($h);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
217 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
218
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
219 sub xml {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
220 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
221 my $str = '';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
222
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
223 open my $h,'>',\$str or die new IMPL::Exception("Failed to create stream");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
224 $this->SaveXML($h);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
225 undef $h;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
226 return $str;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
227 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
228
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
229 sub LoadXMLString {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
230 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
231 my $str = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
232
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
233 open my $h,'<',\$str or die new IMPL::Exception("Failed to create stream");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
234 return $self->LoadXML($h);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
235 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
236
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
237
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
238 1;