File Coverage

blib/lib/SOAP/WSDL/Factory/Serializer.pm
Criterion Covered Total %
statement 13 13 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 2 2 100.0
total 25 25 100.0


line stmt bran cond sub pod time code
1             package SOAP::WSDL::Factory::Serializer;
2 26     26   13016 use strict;
  26         30  
  26         683  
3 26     26   82 use warnings;
  26         31  
  26         3781  
4              
5             our $VERSION = 3.003;
6              
7             my %SERIALIZER = (
8             '1.1' => 'SOAP::WSDL::Serializer::XSD',
9             );
10              
11             # class method
12             sub register {
13 1     1 1 219 my ($class, $ref_type, $package) = @_;
14 1         2 $SERIALIZER{ $ref_type } = $package;
15             }
16              
17             sub get_serializer {
18 5     5 1 836 my ($self, $args_of_ref) = @_;
19 5   100     17 $args_of_ref->{ soap_version } ||= '1.1';
20             # sanity check
21             die "no serializer registered for SOAP version $args_of_ref->{ soap_version }"
22 5 100       19 if not exists ($SERIALIZER{ $args_of_ref->{ soap_version } });
23              
24             # load module
25 4 100       216 eval "require $SERIALIZER{ $args_of_ref->{ soap_version } }"
26             or die "Cannot load serializer $SERIALIZER{ $args_of_ref->{ soap_version } }", $@;
27              
28 3         22 return $SERIALIZER{ $args_of_ref->{ soap_version } }->new();
29             }
30              
31             1;
32              
33             =pod
34              
35             =head1 NAME
36              
37             SOAP::WSDL::Factory::Serializer - Factory for retrieving serializer objects
38              
39             =head1 SYNOPSIS
40              
41             # from SOAP::WSDL::Client:
42             $serializer = SOAP::WSDL::Factory::Serializer->get_serializer({
43             soap_version => $soap_version,
44             });
45              
46             # in serializer class:
47             package MyWickedSerializer;
48             use SOAP::WSDL::Factory::Serializer;
49              
50             # register as serializer for SOAP1.2 messages
51             SOAP::WSDL::Factory::Serializer->register( '1.2' , __PACKAGE__ );
52              
53             =head1 DESCRIPTION
54              
55             SOAP::WSDL::Factory::Serializer serves as factory for retrieving
56             serializer objects for SOAP::WSDL.
57              
58             The actual work is done by specific serializer classes.
59              
60             SOAP::WSDL::Serializer tries to load one of the following classes:
61              
62             =over
63              
64             =item * the class registered for the scheme via register()
65              
66             =back
67              
68             =head1 METHODS
69              
70             =head2 register
71              
72             SOAP::WSDL::Serializer->register('1.1', 'MyWickedSerializer');
73              
74             Globally registers a class for use as serializer class.
75              
76             =head2 get_serializer
77              
78             Returns an object of the serializer class for this endpoint.
79              
80             =head1 WRITING YOUR OWN SERIALIZER CLASS
81              
82             =head2 Registering a deserializer
83              
84             Serializer classes may register with SOAP::WSDL::Factory::Serializer.
85              
86             Serializer objects may also be passed directly to SOAP::WSDL::Client by
87             using the set_serializer method. Note that serializers objects set via
88             SOAP::WSDL::Client's set_serializer method are discarded when the SOAP
89             version is changed via set_soap_version.
90              
91             Registering a serializer class with SOAP::WSDL::Factory::Serializer is done
92             by executing the following code where $version is the SOAP version the
93             class should be used for, and $class is the class name.
94              
95             SOAP::WSDL::Factory::Serializer->register( $version, $class);
96              
97             To auto-register your transport class on loading, execute register() in
98             your tranport class (see L above).
99              
100             =head2 Serializer package layout
101              
102             Serializer modules must be named equal to the serializer class they contain.
103             There can only be one serializer class per serializer module.
104              
105             =head2 Methods to implement
106              
107             Serializer classes must implement the following methods:
108              
109             =over
110              
111             =item * new
112              
113             Constructor.
114              
115             =item * serialize
116              
117             Serializes data to XML. The following named parameters are passed to the
118             serialize method in a anonymous hash ref:
119              
120             {
121             method => $operation_name,
122             header => $header_data,
123             body => $body_data,
124             }
125              
126             =back
127              
128             =head1 LICENSE AND COPYRIGHT
129              
130             Copyright 2004-2007 Martin Kutter. All rights reserved.
131              
132             This file is part of SOAP-WSDL. You may distribute/modify it under
133             the same terms as perl itself.
134              
135             =head1 AUTHOR
136              
137             Martin Kutter Emartin.kutter fen-net.deE
138              
139             =head1 REPOSITORY INFORMATION
140              
141             $Rev: 851 $
142             $LastChangedBy: kutterma $
143             $Id: Serializer.pm 851 2009-05-15 22:45:18Z kutterma $
144             $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Factory/Serializer.pm $
145              
146             =cut