File Coverage

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


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2             package SOAP::WSDL::Serializer::XSD;
3 3     3   1220 use strict;
  3         4  
  3         119  
4 3     3   16 use warnings;
  3         3  
  3         85  
5 3     3   1984 use Class::Std::Fast::Storable;
  3         1937515  
  3         25  
6 3     3   479 use Scalar::Util qw(blessed);
  3         6  
  3         236  
7              
8 3     3   15 use version; our $VERSION = qv('3.001');
  3         6  
  3         17  
9              
10 3     3   1012 use SOAP::WSDL::Factory::Serializer;
  3         7  
  3         1977  
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 1244 my ($self, $args_of_ref) = @_;
17              
18 10         17 my $opt = $args_of_ref->{ options };
19              
20 10 100       44 if (not $opt->{ namespace }->{ $SOAP_NS })
21             {
22 9         26 $opt->{ namespace }->{ $SOAP_NS } = 'SOAP-ENV';
23             }
24              
25 10 100       28 if (not $opt->{ namespace }->{ $XML_INSTANCE_NS })
26             {
27 9         22 $opt->{ namespace }->{ $XML_INSTANCE_NS } = 'xsi';
28             }
29              
30 10         18 my $soap_prefix = $opt->{ namespace }->{ $SOAP_NS };
31              
32             # envelope start with namespaces
33 10         25 my $xml = qq|<$soap_prefix\:Envelope |;
34              
35 10         13 for my $uri ( sort { $a cmp $b } keys %{ $opt->{ namespace } } )
  10         32  
  10         45  
36             {
37 20         35 my $prefix = $opt->{ namespace }->{ $uri };
38 20         69 $xml .= "xmlns:$prefix=\"$uri\" ";
39             }
40             #
41             # add namespace for user-supplied prefix if needed
42 10 100       41 $xml .= "xmlns:$opt->{prefix}=\"" . $args_of_ref->{ body }->get_xmlns() . "\" "
43             if $opt->{prefix};
44              
45             # TODO insert encoding
46 10         16 $xml.='>';
47 10         39 $xml .= $self->serialize_header($args_of_ref->{ method }, $args_of_ref->{ header }, $opt);
48 10         52 $xml .= $self->serialize_body($args_of_ref->{ method }, $args_of_ref->{ body }, $opt);
49 10         41 $xml .= '';
50 10         79 return $xml;
51             }
52              
53             sub serialize_header {
54 10     10 1 26 my ($self, $method, $data, $opt) = @_;
55              
56             # header is optional. Leave out if there's no header data
57 10 100       28 return q{} if not $data;
58 6 100       42 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 18 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       31 $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       17 return join ( q{},
75             "<$opt->{ namespace }->{ $SOAP_NS }\:Body>",
76             defined $data
77             ? ref $data eq 'ARRAY'
78 10 100       76 ? join q{}, map { blessed $_ ? $_->serialize_qualified() : () } @{ $data }
  5 100       17  
    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__