LS/SOAP/Serializer.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 69 CC 5 SCAR 15.9
CC
5
Cov
0%
new
6.0
method_prefix
6.0
encode_array
6.0
CRAP 4.9
1 # ====================================================================
2 # Copyright (c) 2002,2003 IBM Corporation
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Common Public License v1.0
5 # which accompanies this distribution, and is available at
6 # http://www.opensource.org/licenses/cpl.php
7 #
8 # =====================================================================
9  
10 package LS::SOAP::Serializer;
11  
12 use strict;
13 use vars qw(@ISA);
14  
15 use SOAP::Lite;
16  
17  
18 @ISA = qw(SOAP::Serializer);
19  
20  
21 #
22 # new - The only change from SOAP::Serializer::new is to change some
23 # default attributes:
24 #
25 # - remove extraneous attributes from the envelope,
26 # - turn autotyping off,
27 # - remove extraneous namespace declarations from the envelope,
28 # - set the namespace prefix that will be used on the method element.
29 #
30 sub new {
31  
32 my $self = shift;
33 my $initialized = ref $self;
34  
35 $self = $self->SUPER::new(@_);
36  
37 if (!$initialized) {
38  
39  
40 my $ns = {
41 $SOAP::Constants::NS_ENV=> $SOAP::Constants::PREFIX_ENV,
42 $SOAP::Constants::DEFAULT_XML_SCHEMA=> 'xsd',
43 };
44 $self
45 -> attr({})
46 -> autotype(0)
47 -> namespaces($ns)
48 -> method_prefix('')
49 }
50  
51 return $self;
52 }
53  
54  
55 #
56 # method_prefix - This is a method not found in SOAP::Serializer. It allows
57 # setting and retrieval of the namespace prefix used on the
58 # method element in the envelope.
59 #
60 sub method_prefix {
61  
62 my $self = shift->new;
63 @_ ? ($self->{_method_prefix} = shift, return $self) : return $self->{_method_prefix};
64 }
65  
66  
67 #
68 # encode_array - This does the same thing as SOAP::Serializer::encode_array,
69 # except that it doesn't calculate the 'arrayType' attribute.
70 #
71 sub encode_array {
72  
73 my($self, $array, $name, $type, $attr) = @_;
74 my $items = 'item';
75  
76 my @items = map {$self->encode_object($_, $items)} @$array;
77  
78 $type = qualify($self->encprefix => 'Array') if $self->autotype && !defined $type;
79  
80 return [
81 $name || qualify($self->encprefix => 'Array'),
82 {'xsi:type' => $self->maptypetouri($type), %$attr},
83 [@items],
84 $self->gen_id($array)
85 ];
86 }
87  
88  
89 #
90 # envelope - The same as SOAP::Serializer::envelope, except we set the
91 # prefix of the method element to the one that was explicitly
92 # chosen, rather than allowing it to be internally generated.
93 #
94 sub envelope {
95  
96 my $self = shift->new;
97  
98 if ($_[0] eq 'method' || $_[0] eq 'response') {
99 $_[1] = SOAP::Data
100 -> name($_[1])
101 -> prefix($self->method_prefix)
102 -> uri($self->uri);
103 }
104  
105 $self->SUPER::envelope(@_);
106 }
107  
108 1;
109  
110 __END__