annotate Lib/IMPL/Test/Plan.pm @ 76:b1652a158b2b

Web::DOM
author wizard
date Wed, 31 Mar 2010 16:17:13 +0400
parents 16ada169ca75
children 74bae30eb25e
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 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
76 $info{Tests} = [map $Unit->new($_), $Unit->List];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
77 } otherwise {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
78 $info{Tests} = [$info{Unit} = new IMPL::Test::BadUnit($Unit->can('UnitName') ? $Unit->UnitName : $Unit,"Failed to extract tests",$@)];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
79 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
80 $count += @{$info{Tests}};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
81 push @cache, \%info if @{$info{Tests}};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
82 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
84 $this->_Count($count);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
85 $this->_Cache(\@cache);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
86 }
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 sub Count {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
89 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
90 return $this->_Count;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
93 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
94 my $this = shift;
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 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
97
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
98 $this->_Tell(RunPlan => $this);
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 my @resultsTotal;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
101
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
102 foreach my $info ($this->_Cache) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
103 $this->_Tell(RunUnit => $info->{Unit});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
104
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
105 my $data;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
106 undef $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
107 eval {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
108 $data = $info->{Unit}->StartUnit;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
111 my @results;
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 if (not $@) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
114 foreach my $test (@{$info->{Tests}}) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
115 $this->_Tell(RunTest => $test);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
116 my $result = $test->Run($data);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
117 $this->_Tell(EndTest => $test,$result);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
118 push @results,$result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
119 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
120 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
121 my $e = $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
122 foreach my $test (@{$info->{Tests}}) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
123 $this->_Tell(RunTest => $test);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
124 my $result = new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
125 Name => $test->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
126 State => IMPL::Test::Result::FAIL,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
127 Exception => $e
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
128 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
129 $this->_Tell(EndTest => $test,$result);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
130 push @results,$result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
131 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
132 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
133
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
134 eval {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
135 $info->{Unit}->FinishUnit($data);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
136 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
137
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
138 undef $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
139
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
140 push @resultsTotal, { Unit => $info->{Unit}, Results => \@results};
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 $this->_Tell(EndUnit => $info->{Unit},\@results);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
143 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
144
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
145 $this->Results(\@resultsTotal);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
146 $this->_Tell(EndPlan => $this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
147 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
148
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
149 sub _Tell {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
150 my ($this,$what,@args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
151
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
152 $_->$what(@args) foreach $this->Listeners;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
153 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
154
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
155 sub SaveXML {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
156 my ($this,$out) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
157
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
158 my $h;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
159
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
160 if (ref $out eq 'GLOB') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
161 $h = $out;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
162 } elsif ($out and not ref $out) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
163 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
164 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
165 die new IMPL::InvalidOperationException("Invalid output specified");
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 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
169 $s->Serialize($h,$this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
170 }
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 sub LoadXML {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
173 my ($self,$in) = @_;
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 my $h;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
176
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
177 if (ref $in eq 'GLOB') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
178 $h = $in;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
179 } elsif ($in and not ref $in) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
180 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
181 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
182 die new IMPL::InvalidOperationException("Invalid input specified");
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 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
186 return $s->Deserialize($h);
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
189 sub xml {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
190 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
191 my $str = '';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
192
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
193 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
194 $this->SaveXML($h);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
195 undef $h;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
196 return $str;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
199 sub LoadXMLString {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
200 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
201 my $str = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
202
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
203 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
204 return $self->LoadXML($h);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
205 }
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 31
diff changeset
208 1;