File Coverage

blib/lib/UDDI.pm
Criterion Covered Total %
statement 6 187 3.2
branch 0 72 0.0
condition 0 6 0.0
subroutine 2 21 9.5
pod 9 9 100.0
total 17 295 5.7


line stmt bran cond sub pod time code
1             package UDDI;
2              
3             # Copyright 2000 ActiveState Tool Corp.
4              
5 1     1   53971 use strict;
  1         2  
  1         3588  
6              
7             our $VERSION = "0.03";
8              
9             our $registry ||= "http://test.uddi.microsoft.com/inquire";
10             #our $registry = "http://uddi.microsoft.com/inquire";
11             our $TRACE;
12             our %err;
13              
14             require Exporter;
15             our @EXPORT_OK = qw(find_binding find_business find_service find_tModel
16             get_bindingDetail get_businessDetail get_businessDetailExt
17             get_serviceDetail get_tModelDetail
18             );
19              
20             my %findQualifier = map {$_ => 1}
21             qw(exactNameMatch caseSensitiveMatch
22             sortByNameAsc sortByNameDesc
23             sortByDateAsc sortByDateDesc
24             );
25              
26             sub _esc_q {
27 0     0     for (@_) {
28 0           s/&/&/g;
29 0           s/\"/"/g;
30 0           s/
31             }
32             }
33              
34             sub _esc {
35 0     0     for (@_) {
36 0           s/&/&/g;
37 0           s/
38             }
39             }
40              
41             sub _rows_and_fq
42             {
43 0     0     my $arg = shift;
44 0           my $msg = "";
45 0 0         if (defined(my $maxRows = delete $arg->{maxRows})) {
46 0           $msg .= qq( maxRows="$maxRows");
47             }
48 0           $msg .= qq( xmlns="urn:uddi-org:api">);
49 0 0         if (my $findQ = delete $arg->{findQualifiers}) {
50 0 0         unless (ref($findQ)) {
51 0           $findQ = [split(' ', $findQ)];
52             }
53 0 0         if ($^W) {
54 0           for (@$findQ) {
55 0 0         warn "Unknown findQualifier '$_'\n" unless $findQualifier{$_};
56             }
57             }
58 0           $msg .= "" .
59             join("", map "$_", @$findQ) .
60             "";
61             }
62 0           return $msg;
63             }
64              
65             sub _tbag
66             {
67 0     0     my $arg = shift;
68 0           my $msg = "";
69 0 0         if (my $tBag = delete $arg->{tModelBag}) {
70 0 0         unless (ref($tBag)) {
71 0           $tBag = [split(' ', $tBag)];
72             }
73 0           $msg .= "" .
74             join("", map "$_", @$tBag) .
75             "";
76             }
77 0           return $msg;
78             }
79              
80             sub _key_ref
81             {
82 0     0     my($arg, $bag) = @_;
83 0           my $msg = "";
84 0 0         if (my $refs = delete $arg->{$bag}) {
85             # XXX using a hash to implement a keyedReference bag is problematic
86             # because there is no obvous place to put tModelKey if wanted...
87 0 0         if (ref($refs) eq "HASH") {
88 0           my @kref;
89 0           for my $k (sort keys %$refs) {
90 0           my $v = $refs->{$k};
91 0           for ($k, $v) {
92 0           _esc_q($_);
93             }
94 0           push(@kref, qq());
95             }
96 0           $msg = "<$bag>" . join("", @kref) . "";
97             }
98             else {
99 0           die "Unknown $bag argument type(must be hash)";
100             }
101             }
102 0           $msg;
103             }
104              
105             sub find_binding
106             {
107 0     0 1   my %arg = @_;
108 0           my $serviceKey = delete $arg{serviceKey};
109 0 0         die "Missing serviceKey" unless $serviceKey;
110 0           my $msg = qq(
111 0           $msg .= _rows_and_fq(\%arg);
112 0           $msg .= _tbag(\%arg);
113 0           $msg .= qq();
114 0 0         if (%arg) {
115 0           my $a = join(", ", keys %arg);
116 0           warn "Unrecongized parameters: $a";
117             }
118              
119 0           return _request($msg);
120             }
121              
122             sub find_business
123             {
124 0     0 1   my %arg = @_;
125 0           my $msg = qq(
126 0           $msg .= _rows_and_fq(\%arg);
127              
128 0 0         if (my $n = delete $arg{name}) {
129 0           _esc($n);
130 0           $msg .= qq($n);
131             }
132 0           $msg .= _key_ref(\%arg, "identifierBag");
133 0           $msg .= _key_ref(\%arg, "categoryBag");
134 0           $msg .= _tbag(\%arg);
135              
136 0 0         if (my $discU = delete $arg{discoveryURLs}) {
137 0 0         unless (ref($discU)) {
138 0           $discU = [split(' ', $discU)];
139             }
140 0           $msg .= "" .
141             join("", map "$_", @$discU) .
142             "";
143             }
144              
145 0           $msg .= qq();
146 0 0         if (%arg) {
147 0           my $a = join(", ", keys %arg);
148 0           warn "Unrecongized parameters: $a";
149             }
150              
151 0           return _request($msg);
152             }
153              
154             sub find_service
155             {
156 0     0 1   my %arg = @_;
157 0           my $businessKey = delete $arg{businessKey};
158 0 0         die "Missing businessKey" unless $businessKey;
159 0           my $msg = qq(
160 0           $msg .= _rows_and_fq(\%arg);
161 0 0         if (my $n = delete $arg{name}) {
162 0           _esc($n);
163 0           $msg .= qq($n);
164             }
165 0           $msg .= _key_ref(\%arg, "categoryBag");
166 0           $msg .= _tbag(\%arg);
167 0           $msg .= qq();
168 0 0         if (%arg) {
169 0           my $a = join(", ", keys %arg);
170 0           warn "Unrecongized parameters: $a";
171             }
172              
173 0           return _request($msg);
174             }
175              
176             sub find_tModel
177             {
178 0     0 1   my %arg = @_;
179 0           my $msg = qq(
180 0           $msg .= _rows_and_fq(\%arg);
181 0 0         if (my $n = delete $arg{name}) {
182 0           _esc($n);
183 0           $msg .= qq($n);
184             }
185 0           $msg .= _key_ref(\%arg, "identifierBag");
186 0           $msg .= _key_ref(\%arg, "categoryBag");
187 0           $msg .= _tbag(\%arg);
188 0           $msg .= qq();
189 0 0         if (%arg) {
190 0           my $a = join(", ", keys %arg);
191 0           warn "Unrecongized parameters: $a";
192             }
193              
194 0           return _request($msg);
195             }
196              
197             sub get_bindingDetail
198             {
199 0     0 1   my $msg = qq();
200 0           for (@_) {
201 0           $msg .= "$_";
202             }
203 0           $msg .= "";
204              
205 0           return _request($msg);
206             }
207              
208             sub _get_businessDetail
209             {
210 0 0   0     my $ext = (shift) ? "Ext" : "";
211 0           my $msg = qq();
212 0           for (@_) {
213 0           $msg .= "$_";
214             }
215 0           $msg .= "";
216              
217 0           return _request($msg);
218             }
219              
220             sub get_businessDetail
221             {
222 0     0 1   unshift(@_, 0);
223 0           goto &_get_businessDetail;
224             }
225              
226             sub get_businessDetailExt
227             {
228 0     0 1   unshift(@_, 1);
229 0           goto &_get_businessDetail;
230             }
231              
232             sub get_serviceDetail
233             {
234 0     0 1   my $msg = qq();
235 0           for (@_) {
236 0           $msg .= "$_";
237             }
238 0           $msg .= "";
239              
240 0           return _request($msg);
241             }
242              
243             sub get_tModelDetail
244             {
245 0     0 1   my $msg = qq();
246 0           for (@_) {
247 0           $msg .= "$_";
248             }
249 0           $msg .= "";
250              
251 0           return _request($msg);
252             }
253              
254              
255              
256             # ----------------------------------
257              
258             my $ua;
259              
260             sub _request {
261 0     0     my $msg = shift;
262              
263 0 0         if (!$ua) {
264 0           require LWP::UserAgent;
265 0           $ua = LWP::UserAgent->new;
266 0           $ua->agent("UDDI.pm/$VERSION " . $ua->agent);
267 0           $ua->env_proxy;
268             }
269              
270 0           undef(%UDDI::err);
271              
272 0           my $req = HTTP::Request->new(POST => $registry);
273 0 0         $req->date(time) if $TRACE;
274 0           $req->header("SOAPAction", '""');
275 0           $req->content_type("text/xml");
276 0           $req->content(qq($msg\n));
277              
278 0 0         print $TRACE "\n\n", ("=" x 50), "\n", $req->as_string if $TRACE;
279              
280 0           my $res = $ua->request($req);
281              
282 0 0         print $TRACE $res->as_string if $TRACE;
283              
284 0 0 0       if ($res->content_type eq "text/xml" && $res->header("SOAPAction")) {
285             #warn $res->content;
286              
287 0           require UDDI::SOAP;
288 0           my $envelope = UDDI::SOAP::parse($res->content);
289 0 0         if ($envelope->must_understand_headers) {
290 0           %UDDI::err = ( type => "SOAP",
291             code => "MustUnderstand",
292             message => "UDDI response contained SOAP headers that ".
293             "the client libarary did not understand",
294             detail => $envelope,
295             );
296 0           return undef;
297             }
298              
299 0           my $obj = $envelope->body_content;
300              
301 0 0         if (ref($obj) eq "UDDI::SOAP::Fault") {
302 0           %UDDI::err = ( type => "SOAP",
303             code => $obj->code,
304             message => $obj->message,
305             detail => $obj,
306             );
307 0           return undef;
308             }
309              
310 0           return $obj;
311             }
312              
313             %UDDI::err = (
314 0           type => "HTTP",
315             code => $res->code,
316             message => $res->status_line,
317             detail => $res,
318             );
319 0           return undef;
320             }
321              
322             # The following table is auto-generated from:
323             # "UDDI API schema. Version 1.0, revision 0. Last change 2000-09-06"
324              
325             # urn:uddi-org:api elements
326              
327             sub TEXT_CONTENT () { 0x01 }
328             sub ELEM_CONTENT () { 0x02 }
329              
330             our %elementContent = (
331             'UDDI::addressLine' => 0x01,
332             'UDDI::bindingKey' => 0x01,
333             'UDDI::businessKey' => 0x01,
334             'UDDI::description' => 0x01,
335             'UDDI::keyValue' => 0x01,
336             'UDDI::name' => 0x01,
337             'UDDI::overviewURL' => 0x01,
338             'UDDI::personName' => 0x01,
339             'UDDI::serviceKey' => 0x01,
340             'UDDI::tModelKey' => 0x01,
341             'UDDI::uploadRegister' => 0x01,
342             'UDDI::address' => 0x02,
343             'UDDI::contacts' => 0x02,
344             'UDDI::contact' => 0x02,
345             'UDDI::discoveryURL' => 0x01,
346             'UDDI::discoveryURLs' => 0x02,
347             'UDDI::phone' => 0x01,
348             'UDDI::email' => 0x01,
349             'UDDI::businessEntity' => 0x02,
350             'UDDI::businessServices' => 0x02,
351             'UDDI::businessService' => 0x02,
352             'UDDI::bindingTemplates' => 0x02,
353             'UDDI::identifierBag' => 0x02,
354             'UDDI::keyedReference' => 0000,
355             'UDDI::categoryBag' => 0x02,
356             'UDDI::bindingTemplate' => 0x02,
357             'UDDI::accessPoint' => 0x01,
358             'UDDI::hostingRedirector' => 0000,
359             'UDDI::tModelInstanceDetails' => 0x02,
360             'UDDI::tModelInstanceInfo' => 0x02,
361             'UDDI::instanceDetails' => 0x02,
362             'UDDI::instanceParms' => 0x01,
363             'UDDI::tModel' => 0x02,
364             'UDDI::tModelBag' => 0x02,
365             'UDDI::overviewDoc' => 0x02,
366             'UDDI::authInfo' => 0x01,
367             'UDDI::get_authToken' => 0000,
368             'UDDI::authToken' => 0x02,
369             'UDDI::discard_authToken' => 0x02,
370             'UDDI::save_tModel' => 0x02,
371             'UDDI::delete_tModel' => 0x02,
372             'UDDI::save_business' => 0x02,
373             'UDDI::delete_business' => 0x02,
374             'UDDI::save_service' => 0x02,
375             'UDDI::delete_service' => 0x02,
376             'UDDI::save_binding' => 0x02,
377             'UDDI::delete_binding' => 0x02,
378             'UDDI::dispositionReport' => 0x02,
379             'UDDI::result' => 0x02,
380             'UDDI::errInfo' => 0x01,
381             'UDDI::findQualifiers' => 0x02,
382             'UDDI::findQualifier' => 0x01,
383             'UDDI::find_tModel' => 0x02,
384             'UDDI::find_business' => 0x02,
385             'UDDI::find_binding' => 0x02,
386             'UDDI::find_service' => 0x02,
387             'UDDI::serviceList' => 0x02,
388             'UDDI::businessList' => 0x02,
389             'UDDI::tModelList' => 0x02,
390             'UDDI::businessInfo' => 0x02,
391             'UDDI::businessInfos' => 0x02,
392             'UDDI::serviceInfo' => 0x02,
393             'UDDI::serviceInfos' => 0x02,
394             'UDDI::get_businessDetail' => 0x02,
395             'UDDI::businessDetail' => 0x02,
396             'UDDI::get_serviceDetail' => 0x02,
397             'UDDI::serviceDetail' => 0x02,
398             'UDDI::get_registeredInfo' => 0x02,
399             'UDDI::registeredInfo' => 0x02,
400             'UDDI::tModelInfo' => 0x02,
401             'UDDI::tModelInfos' => 0x02,
402             'UDDI::get_tModelDetail' => 0x02,
403             'UDDI::tModelDetail' => 0x02,
404             'UDDI::businessEntityExt' => 0x02,
405             'UDDI::get_businessDetailExt' => 0x02,
406             'UDDI::businessDetailExt' => 0x02,
407             'UDDI::get_bindingDetail' => 0x02,
408             'UDDI::bindingDetail' => 0x02,
409             'UDDI::validate_categorization' => 0x02,
410             );
411              
412              
413             package UDDI::Object;
414              
415 1     1   13 use overload '""' => \&as_string;
  1         1  
  1         14  
416              
417             our $AUTOLOAD;
418              
419             sub AUTOLOAD
420             {
421 0     0     my $self = shift;
422 0           my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2);
423 0 0         return if $method eq "DESTROY";
424              
425 0           my $k = "urn:uddi-org:api\0$method";
426 0 0         if (exists $self->[0]{$k}) {
427 0           return $self->[0]{$k};
428             }
429              
430 0           my @res = grep ref($_) eq "UDDI::$method", @$self;
431 0 0         return wantarray ? @res : $res[0];
432             }
433              
434             sub xml_lang
435             {
436 0     0     my $self = shift;
437 0           return $self->[0]{"xml\0lang"};
438             }
439              
440             sub as_string
441             {
442 0     0     my($self, $elem) = @_;
443 0           my $class = ref($self);
444              
445 0 0         unless ($class) {
446             # plain string
447 0 0         UDDI::_esc($self) if $elem;
448 0           return $self;
449             }
450              
451 0 0 0       return $self->[1]
452             if $UDDI::elementContent{$class} == UDDI::TEXT_CONTENT && !$elem;
453              
454 0           (my $tag = $class) =~ s/^UDDI:://;
455              
456 0           my @e = @$self;
457 0           my $attr = shift @e;
458 0 0         if (%$attr) {
459 0           my @attr;
460 0           for my $k (sort keys %$attr) {
461 0           my $v = $attr->{$k};
462 0           $k =~ s/^[^\0]*\0//; # kill namespace qualifier
463 0           UDDI::_esc_q($v);
464 0           @attr = qq($k="$v");
465             }
466 0           $attr = join(" ", "", @attr);
467             }
468             else {
469 0           $attr = "";
470             }
471              
472 0 0         return "<$tag$attr/>" unless @e;
473              
474 0           return join("", "<$tag$attr>", (map as_string($_, 1), @e), "");
475             }
476              
477             1;
478              
479             __END__