line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Document::Transport; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# L O A D M O D U L E S -------------------------------------------------- |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
68269
|
use strict; |
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
232
|
|
6
|
3
|
|
|
3
|
|
25
|
use vars qw/ $VERSION $SELF /; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
306
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#use XML::Parser; |
9
|
3
|
|
|
3
|
|
1615
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use XML::Writer; |
11
|
|
|
|
|
|
|
use XML::Writer::String; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Net::Domain qw(hostname hostdomain); |
14
|
|
|
|
|
|
|
use File::Spec; |
15
|
|
|
|
|
|
|
use Carp; |
16
|
|
|
|
|
|
|
use Data::Dumper; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
'$Revision: 1.1 $ ' =~ /.*:\s(.*)\s\$/ && ($VERSION = $1); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# C O N S T R U C T O R ---------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
my $proto = shift; |
24
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# bless the query hash into the class |
27
|
|
|
|
|
|
|
my $block = bless { DOCUMENT => undef, |
28
|
|
|
|
|
|
|
WRITER => undef, |
29
|
|
|
|
|
|
|
BUFFER => undef }, $class; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Configure the object |
32
|
|
|
|
|
|
|
$block->configure( @_ ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $block; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# A C C E S S O R M E T H O D S ------------------------------------------- |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# $xml = $object->build( Role => $string, |
41
|
|
|
|
|
|
|
# Origin => $strng, |
42
|
|
|
|
|
|
|
# Response => $sting, |
43
|
|
|
|
|
|
|
# TimeStamp => $string, |
44
|
|
|
|
|
|
|
# Meta => [ { Group => [ { Name => $string, |
45
|
|
|
|
|
|
|
# UCD => $string, |
46
|
|
|
|
|
|
|
# Value => $string, |
47
|
|
|
|
|
|
|
# Units => $string }, |
48
|
|
|
|
|
|
|
# . |
49
|
|
|
|
|
|
|
# . |
50
|
|
|
|
|
|
|
# . |
51
|
|
|
|
|
|
|
# { Name => $string, |
52
|
|
|
|
|
|
|
# UCD => $string, |
53
|
|
|
|
|
|
|
# Value => $string, |
54
|
|
|
|
|
|
|
# Units => $string } ], }, |
55
|
|
|
|
|
|
|
# { Group => [ { Name => $string, |
56
|
|
|
|
|
|
|
# UCD => $string, |
57
|
|
|
|
|
|
|
# Value => $string, |
58
|
|
|
|
|
|
|
# Units => $string }, |
59
|
|
|
|
|
|
|
# . |
60
|
|
|
|
|
|
|
# . |
61
|
|
|
|
|
|
|
# . |
62
|
|
|
|
|
|
|
# { Name => $string, |
63
|
|
|
|
|
|
|
# UCD => $string, |
64
|
|
|
|
|
|
|
# Value => $string, |
65
|
|
|
|
|
|
|
# Units => $string } ], }, |
66
|
|
|
|
|
|
|
# { Name => $string, |
67
|
|
|
|
|
|
|
# UCD => $string, |
68
|
|
|
|
|
|
|
# Value => $string, |
69
|
|
|
|
|
|
|
# Units => $string }, |
70
|
|
|
|
|
|
|
# . |
71
|
|
|
|
|
|
|
# . |
72
|
|
|
|
|
|
|
# . |
73
|
|
|
|
|
|
|
# { Name => $string, |
74
|
|
|
|
|
|
|
# UCD => $string, |
75
|
|
|
|
|
|
|
# Value => $string, |
76
|
|
|
|
|
|
|
# Units => $string } ] ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub build { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
my %args = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# mandatory tags |
84
|
|
|
|
|
|
|
unless ( exists $args{Role} ) { |
85
|
|
|
|
|
|
|
return undef; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# open the document |
89
|
|
|
|
|
|
|
$self->{WRITER}->xmlDecl( 'UTF-8' ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# BEGIN DOCUMENT ------------------------------------------------------- |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->{WRITER}->startTag( 'trn:Transport', |
94
|
|
|
|
|
|
|
'role' => $args{Role}, |
95
|
|
|
|
|
|
|
'version' => '0.1', |
96
|
|
|
|
|
|
|
'xmlns:trn' => 'http://www.telescope-networks.org/xml/Transport/v0.1', |
97
|
|
|
|
|
|
|
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
98
|
|
|
|
|
|
|
'xsi:schemaLocation' => |
99
|
|
|
|
|
|
|
'http://www.telescope-networks.org/xml/Transport/v0.1 ' . |
100
|
|
|
|
|
|
|
'http://www.telescope-networks.org/schema/Transport-v0.1.xsd' |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# SKELETON DOCUMENT ---------------------------------------------------- |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Origin |
106
|
|
|
|
|
|
|
if ( exists $args{Origin} ) { |
107
|
|
|
|
|
|
|
$self->{WRITER}->startTag( 'Origin' ); |
108
|
|
|
|
|
|
|
$self->{WRITER}->characters( $args{Origin} ); |
109
|
|
|
|
|
|
|
$self->{WRITER}->endTag( 'Origin' ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Response |
113
|
|
|
|
|
|
|
if ( exists $args{Response} ) { |
114
|
|
|
|
|
|
|
$self->{WRITER}->startTag( 'Response' ); |
115
|
|
|
|
|
|
|
$self->{WRITER}->characters( $args{Response} ); |
116
|
|
|
|
|
|
|
$self->{WRITER}->endTag( 'Response' ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# TimeStamp |
120
|
|
|
|
|
|
|
if ( exists $args{TimeStamp} ) { |
121
|
|
|
|
|
|
|
$self->{WRITER}->startTag( 'TimeStamp' ); |
122
|
|
|
|
|
|
|
$self->{WRITER}->characters( $args{TimeStamp} ); |
123
|
|
|
|
|
|
|
$self->{WRITER}->endTag( 'TimeStamp' ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Meta |
127
|
|
|
|
|
|
|
if ( exists $args{Meta} ) { |
128
|
|
|
|
|
|
|
$self->{WRITER}->startTag( 'Meta' ); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my @array = @{$args{Meta}}; |
131
|
|
|
|
|
|
|
foreach my $i ( 0 ... $#array ) { |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my %hash = %{${$args{Meta}}[$i]}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
if ( exists $hash{Group} ) { |
136
|
|
|
|
|
|
|
$self->{WRITER}->startTag( 'Group' ); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my @subarray = @{$hash{Group}}; |
139
|
|
|
|
|
|
|
foreach my $i ( 0 ... $#subarray ) { |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Only UNITS is optional for Param tags |
142
|
|
|
|
|
|
|
if ( exists ${$subarray[$i]}{Units} ) { |
143
|
|
|
|
|
|
|
$self->{WRITER}->emptyTag('Param', |
144
|
|
|
|
|
|
|
'name' => ${$subarray[$i]}{Name}, |
145
|
|
|
|
|
|
|
'ucd' => ${$subarray[$i]}{UCD}, |
146
|
|
|
|
|
|
|
'value' => ${$subarray[$i]}{Value}, |
147
|
|
|
|
|
|
|
'units' => ${$subarray[$i]}{Units} ); |
148
|
|
|
|
|
|
|
} else { |
149
|
|
|
|
|
|
|
$self->{WRITER}->emptyTag('Param', |
150
|
|
|
|
|
|
|
'name' => ${$subarray[$i]}{Name}, |
151
|
|
|
|
|
|
|
'ucd' => ${$subarray[$i]}{UCD}, |
152
|
|
|
|
|
|
|
'value' => ${$subarray[$i]}{Value}); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
$self->{WRITER}->endTag( 'Group' ); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} else { |
159
|
|
|
|
|
|
|
# Only UNITS is optional for Param tags |
160
|
|
|
|
|
|
|
if ( exists $hash{Units} ) { |
161
|
|
|
|
|
|
|
$self->{WRITER}->emptyTag('Param', |
162
|
|
|
|
|
|
|
'name' => $hash{Name}, |
163
|
|
|
|
|
|
|
'ucd' => $hash{UCD}, |
164
|
|
|
|
|
|
|
'value' => $hash{Value}, |
165
|
|
|
|
|
|
|
'units' => $hash{Units} ); |
166
|
|
|
|
|
|
|
} else { |
167
|
|
|
|
|
|
|
$self->{WRITER}->emptyTag('Param', |
168
|
|
|
|
|
|
|
'name' => $hash{Name}, |
169
|
|
|
|
|
|
|
'ucd' => $hash{UCD}, |
170
|
|
|
|
|
|
|
'value' => $hash{Value} ); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
$self->{WRITER}->endTag( 'Meta' ); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# END DOCUMENT --------------------------------------------------------- |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$self->{WRITER}->endTag( 'trn:Transport' ); |
181
|
|
|
|
|
|
|
$self->{WRITER}->end(); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $xml = $self->{BUFFER}->value(); |
184
|
|
|
|
|
|
|
$self->_parse( XML => $xml ); |
185
|
|
|
|
|
|
|
return $xml; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub role { |
191
|
|
|
|
|
|
|
my $self = shift; |
192
|
|
|
|
|
|
|
return $self->{DOCUMENT}->{role}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub version { |
196
|
|
|
|
|
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
return $self->{DOCUMENT}->{version}; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub origin { |
201
|
|
|
|
|
|
|
my $self = shift; |
202
|
|
|
|
|
|
|
return $self->{DOCUMENT}->{Origin}; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub response { |
206
|
|
|
|
|
|
|
my $self = shift; |
207
|
|
|
|
|
|
|
return $self->{DOCUMENT}->{Response}; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub time { |
211
|
|
|
|
|
|
|
my $self = shift; |
212
|
|
|
|
|
|
|
return $self->{DOCUMENT}->{TimeStamp}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub meta { |
216
|
|
|
|
|
|
|
my $self = shift; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
return %{$self->{DOCUMENT}->{Meta}}; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# C O N F I G U R E --------------------------------------------------------- |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub configure { |
224
|
|
|
|
|
|
|
my $self = shift; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# BLESS XML WRITER |
227
|
|
|
|
|
|
|
# ---------------- |
228
|
|
|
|
|
|
|
$self->{BUFFER} = new XML::Writer::String(); |
229
|
|
|
|
|
|
|
$self->{WRITER} = new XML::Writer( OUTPUT => $self->{BUFFER}, |
230
|
|
|
|
|
|
|
DATA_MODE => 1, |
231
|
|
|
|
|
|
|
DATA_INDENT => 4 ); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# CONFIGURE FROM ARGUEMENTS |
234
|
|
|
|
|
|
|
# ------------------------- |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
# return unless we have arguments |
237
|
|
|
|
|
|
|
return undef unless @_; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# grab the argument list |
240
|
|
|
|
|
|
|
my %args = @_; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
# Loop over the allowed keys |
243
|
|
|
|
|
|
|
for my $key (qw / File XML / ) { |
244
|
|
|
|
|
|
|
if ( lc($key) eq "file" && exists $args{$key} ) { |
245
|
|
|
|
|
|
|
$self->_parse( File => $args{$key} ); |
246
|
|
|
|
|
|
|
last; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} elsif ( lc($key) eq "xml" && exists $args{$key} ) { |
249
|
|
|
|
|
|
|
$self->_parse( XML => $args{$key} ); |
250
|
|
|
|
|
|
|
last; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# Nothing to configure... |
256
|
|
|
|
|
|
|
return undef; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
# P R I V A T E M E T H O D S ------------------------------------------ |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub _parse { |
264
|
|
|
|
|
|
|
my $self = shift; |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
# return unless we have arguments |
267
|
|
|
|
|
|
|
return undef unless @_; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# grab the argument list |
270
|
|
|
|
|
|
|
my %args = @_; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
my $xs = new XML::Simple( ); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# Loop over the allowed keys |
275
|
|
|
|
|
|
|
for my $key (qw / File XML / ) { |
276
|
|
|
|
|
|
|
if ( lc($key) eq "file" && exists $args{$key} ) { |
277
|
|
|
|
|
|
|
$self->{DOCUMENT} = $xs->XMLin( $args{$key} ); |
278
|
|
|
|
|
|
|
last; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
} elsif ( lc($key) eq "xml" && exists $args{$key} ) { |
281
|
|
|
|
|
|
|
$self->{DOCUMENT} = $xs->XMLin( $args{$key} ); |
282
|
|
|
|
|
|
|
last; |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
#print Dumper( $self->{DOCUMENT} ); |
288
|
|
|
|
|
|
|
return; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# L A S T O R D E R S ------------------------------------------------------ |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
1; |