blib/lib/SOAP/WSDL/Deserializer/Hash.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/SOAP/WSDL/Expat/Base.pm ↑ Summary blib/lib/SOAP/WSDL/Deserializer/XSD.pm »
1 package SOAP::WSDL::Deserializer::Hash;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Class::Std::Fast::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use SOAP::WSDL::SOAP::Typelib::Fault11;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use SOAP::WSDL::Expat::Message2Hash;
Subroutine BEGIN: called CC=1 SCAR=2.6
7  
8 use SOAP::WSDL::Factory::Deserializer;
9 SOAP::WSDL::Factory::Deserializer->register( '1.1', __PACKAGE__ );
10  
11 our $VERSION = 3.004;
12  
13 sub BUILD {
14 my ($self, $ident, $args_of_ref) = @_;
15  
16 # ignore all options
17 for (keys %{ $args_of_ref }) {
18 delete $args_of_ref->{ $_ }
19 }
20 }
21  
22 sub deserialize {
23 my ($self, $content) = @_;
24  
25 my $parser = SOAP::WSDL::Expat::Message2Hash->new();
26 eval { $parser->parse_string( $content ) };
27 if ($@) {
28 die $self->generate_fault({
29 code => 'soap:Server',
30 role => 'urn:localhost',
31 message => "Error deserializing message: $@. \n"
32 . "Message was: \n$content"
33 });
34 }
35 return $parser->get_data();
36 }
37  
38 sub generate_fault {
39 my ($self, $args_from_ref) = @_;
40 return SOAP::WSDL::SOAP::Typelib::Fault11->new({
41 faultcode => $args_from_ref->{ code } || 'SOAP-ENV:Client',
42 faultactor => $args_from_ref->{ role } || 'urn:localhost',
43 faultstring => $args_from_ref->{ message } || "Unknown error"
44 });
45 }
46  
47 1;
48  
49 =head1 NAME
50  
51 SOAP::WSDL::Deserializer::Hash - Deserializer SOAP messages into perl hash refs
52  
53 =head1 SYNOPSIS
54  
55 use SOAP::WSDL;
56 use SOAP::WSDL::Deserializer::Hash;
57  
58 =head1 DESCRIPTION
59  
60 Deserializer for creating perl hash refs as result of a SOAP call.
61  
62 =head2 Output structure
63  
64 The XML structure is converted into a perl data structure consisting of
65 hash and or list references. List references are used for holding array data.
66  
67 SOAP::WSDL::Deserializer::Hash creates list references always at the maximum
68 depth possible.
69  
70 Examples:
71  
72 XML:
73 <MyDataArray>
74 <MyData>1</MyData>
75 <MyData>1</MyData>
76 </MyDataArray>
77  
78 Perl:
79 {
80 MyDataArray => {
81 MyData => [ 1, 1 ]
82 }
83 }
84  
85 XML:
86 <DeepArray>
87 <MyData><int>1<int>/MyData>
88 <MyData><int>1<int>/MyData>
89 </DeepArray>
90  
91 Perl:
92 {
93 MyDataArray => {
94 MyData => [
95 { int => 1 },
96 { int => 1 }
97 ]
98 }
99 }
100  
101 List reference creation is triggered by the second occurrence of an element.
102 XML Array types with one element only will not be represented as list
103 references.
104  
105 =head1 USAGE
106  
107 All you need to do is to use SOAP::WSDL::Deserializer::Hash.
108  
109 SOAP::WSDL::Deserializer::Hash autoregisters itself for SOAP1.1 messages
110  
111 You may register SOAP::WSDLDeserializer::Hash for other SOAP Versions by
112 calling
113  
114 SOAP::Factory::Deserializer->register('1.2',
115 SOAP::WSDL::Deserializer::Hash)
116  
117 =head1 Limitations
118  
119 =over
120  
121 =item * Namespaces
122  
123 All namespaces are ignored.
124  
125 =item * XML attributes
126  
127 All XML attributes are ignored.
128  
129 =back
130  
131 =head2 Differences from other SOAP::WSDL::Deserializer classes
132  
133 =over
134  
135 =item * generate_fault
136  
137 SOAP::WSDL::Deserializer::Hash will die with a SOAP::WSDL::Fault11 object when
138 a parse error appears
139  
140 =back
141  
142 =head1 METHODS
143  
144 =head2 deserialize
145  
146 Deserializes the message.
147  
148 =head2 generate_fault
149  
150 Generates a L<SOAP::WSDL::SOAP::Typelib::Fault11|SOAP::WSDL::SOAP::Typelib::Fault11>
151 object and returns it.
152  
153 =head1 LICENSE AND COPYRIGHT
154  
155 Copyright 2004-2008 Martin Kutter.
156  
157 This file is part of SOAP-WSDL. You may distribute/modify it under
158 the same terms as perl itself.
159  
160 =head1 AUTHOR
161  
162 Martin Kutter E<lt>martin.kutter fen-net.deE<gt>
163  
164 =head1 REPOSITORY INFORMATION
165  
166 $Rev: 851 $
167 $LastChangedBy: kutterma $
168 $Id: Hash.pm 851 2009-05-15 22:45:18Z kutterma $
169 $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Deserializer/Hash.pm $
170  
171 =cut
« blib/lib/SOAP/WSDL/Expat/Base.pm ↑ Summary blib/lib/SOAP/WSDL/Deserializer/XSD.pm »