blib/lib/MOBY/SOAP/Serializer.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 12 SCAR 49.0
CC
12
Cov
0%
envelope
156.0
xmlize
2.0
BEGIN
2.0
CRAP 134.0
1 #$Id: Serializer.pm,v 1.2 2008/08/25 15:21:01 kawas Exp $
2 package MOBY::SOAP::Serializer;
3  
4 use vars qw /$VERSION/;
5 $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /: (\d+)\.(\d+)/;
6  
7 # this module serializes SOAP messages to ensure
8 # compatibility with other soap clients (Java)
9 # All that you have to do to make this your serializer,
10 # is to uncomment, from MOBY-Central.pl, the line:
11 #
12 # $x->serializer(MOBY::SOAP::Serializer->new);
13 #
14 # and all soap messages will pass through this serializer.
15 #
16 # MAKE SURE TO 'use MOBY::SOAP::Serializer;'
17 #
18 # This ensures that mobycentral is compatible with
19 # SOAP-lite version >= .6
20 @MOBY::SOAP::Serializer::ISA = 'SOAP::Serializer';
21  
22 sub xmlize {
23 my $self = shift;
24 my ( $name, $attrs, $values, $id ) = @{ +shift };
25 $attrs ||= {};
26 return $self->SUPER::xmlize( [ $name, $attrs, $values, $id ] );
27 }
28  
29 sub envelope {
30  
31 # delete $_[0]{_namespaces}->{'http://schemas.xmlsoap.org/soap/encoding/'}
32 # if $_[0];
33  
34 # only 'transform' soap responses
35 UNIVERSAL::isa( $_[3] => 'SOAP::Data' )
36 ? do {
37 # when we set to string, we dont have to encode
38 $_[3]->type( 'string' => $_[3]->value() );
39 }
40  
41 : do {
42 do {
43  
44 # for dumps, they are of type string[]: set components accordingly
45 $_[3]->[0] = SOAP::Data->type( 'string' => $_[3]->[0] )
46 if $_[3]->[0];
47 $_[3]->[1] = SOAP::Data->type( 'string' => $_[3]->[1] )
48 if $_[3]->[1];
49 $_[3]->[2] = SOAP::Data->type( 'string' => $_[3]->[2] )
50 if $_[3]->[2];
51 $_[3]->[3] = SOAP::Data->type( 'string' => $_[3]->[3] )
52 if $_[3]->[3];
53 $_[3]->[4] = SOAP::Data->type( 'string' => $_[3]->[4] )
54 if $_[3]->[4];
55 } if ( ref( $_[3] ) eq 'ARRAY' );
56 do {
57  
58 # below encodes data -> set type to string and we dont have to
59 # set to string to avoid encoding
60 $_[3] = SOAP::Data->type( 'string' => $_[3] );
61 } unless ( ref( $_[3] ) eq 'ARRAY' );
62 } if $_[1] =~ /^(?:method|response)$/;
63  
64 $_[2] = (
65 UNIVERSAL::isa( $_[2] => 'SOAP::Data' )
66 ? $_[2]
67 : SOAP::Data->name( $_[2] )->attr( { xmlns => $uri } )
68 )
69 if $_[1] =~ /^(?:method|response)$/;
70  
71 shift->SUPER::envelope(@_);
72 }
73  
74 1;