File Coverage

blib/lib/SOAP/WSDL/Serializer/XSD.pm
Criterion Covered Total %
statement 42 42 100.0
branch 22 22 100.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 75 75 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2             package SOAP::WSDL::Serializer::XSD;
3 3     3   487 use strict;
  3         3  
  3         85  
4 3     3   11 use warnings;
  3         2  
  3         88  
5 3     3   893 use Class::Std::Fast::Storable;
  3         18753  
  3         14  
6 3     3   338 use Scalar::Util qw(blessed);
  3         5  
  3         179  
7              
8             our $VERSION = 3.003;
9              
10 3     3   340 use SOAP::WSDL::Factory::Serializer;
  3         4  
  3         1043  
11              
12             my $SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/';
13             my $XML_INSTANCE_NS = 'http://www.w3.org/2001/XMLSchema-instance';
14              
15             sub serialize {
16 10     10 1 841 my ($self, $args_of_ref) = @_;
17              
18 10         12 my $opt = $args_of_ref->{ options };
19              
20 10 100       24 if (not $opt->{ namespace }->{ $SOAP_NS })
21             {
22 9         15 $opt->{ namespace }->{ $SOAP_NS } = 'SOAP-ENV';
23             }
24              
25 10 100       18 if (not $opt->{ namespace }->{ $XML_INSTANCE_NS })
26             {
27 9         13 $opt->{ namespace }->{ $XML_INSTANCE_NS } = 'xsi';
28             }
29              
30 10         11 my $soap_prefix = $opt->{ namespace }->{ $SOAP_NS };
31              
32             # envelope start with namespaces
33 10         12 my $xml = qq|<$soap_prefix\:Envelope |;
34              
35 10         9 for my $uri ( sort { $a cmp $b } keys %{ $opt->{ namespace } } )
  10         20  
  10         31  
36             {
37 20         16 my $prefix = $opt->{ namespace }->{ $uri };
38 20         38 $xml .= "xmlns:$prefix=\"$uri\" ";
39             }
40             #
41             # add namespace for user-supplied prefix if needed
42 10 100       24 $xml .= "xmlns:$opt->{prefix}=\"" . $args_of_ref->{ body }->get_xmlns() . "\" "
43             if $opt->{prefix};
44              
45             # TODO insert encoding
46 10         9 $xml.='>';
47 10         21 $xml .= $self->serialize_header($args_of_ref->{ method }, $args_of_ref->{ header }, $opt);
48 10         28 $xml .= $self->serialize_body($args_of_ref->{ method }, $args_of_ref->{ body }, $opt);
49 10         25 $xml .= '';
50 10         50 return $xml;
51             }
52              
53             sub serialize_header {
54 10     10 1 18 my ($self, $method, $data, $opt) = @_;
55              
56             # header is optional. Leave out if there's no header data
57 10 100       13 return q{} if not $data;
58 6 100       29 return join ( q{},
59             "<$opt->{ namespace }->{ $SOAP_NS }\:Header>",
60             blessed $data ? $data->serialize_qualified : (),
61             "{ namespace }->{ $SOAP_NS }\:Header>",
62             );
63             }
64              
65             sub serialize_body {
66 10     10 1 11 my ($self, $method, $data, $opt) = @_;
67              
68             # TODO This one wipes out the old class' XML name globally
69             # Fix in some more appropriate place...
70 10 100       20 $data->__set_name("$opt->{prefix}:" . $data->__get_name() ) if $opt->{prefix};
71              
72             # Body is NOT optional. Serialize to empty body
73             # if we have no data.
74 3 100       20 return join ( q{},
75             "<$opt->{ namespace }->{ $SOAP_NS }\:Body>",
76             defined $data
77             ? ref $data eq 'ARRAY'
78 10 100       47 ? join q{}, map { blessed $_ ? $_->serialize_qualified() : () } @{ $data }
  5 100       9  
    100          
    100          
79             : blessed $data
80             ? $opt->{prefix}
81             ? $data->serialize()
82             : $data->serialize_qualified()
83             : ()
84             : (),
85             "{ namespace }->{ $SOAP_NS }\:Body>",
86             );
87             }
88              
89             __END__