lib/XML/RPC/Enc.pm

filter: Statementstmt 51.8% 14 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 100% 7 / 7 totaltotal 55.5% 25 / 45 CC 1 SCAR 4.9
CC
1
Cov
52%
new
2.0
request
2.0
response
2.0
CRAP 1.6
« lib/XML/RPC/UA.pm ↑ Summary
1 package XML::RPC::Enc;
2  
3 =head1 NAME
4  
5 XML::RPC::Enc - Base class for XML::RPC encoders
6  
7 =head1 SYNOPSIS
8  
9 Generic usage
10  
11 use XML::RPC::Fast;
12
13 my $server = XML::RPC::Fast->new( undef, encoder => XML::RPC::Enc::LibXML->new );
14 my $client = XML::RPC::Fast->new( $uri, encoder => XML::RPC::Enc::LibXML->new );
15  
16 =cut
17  
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # Base class for encoders
23  
24 2 ▶use XML::RPC::Fast ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 our $VERSION = $XML::RPC::Fast::VERSION;
26  
27 =head1 METHODS
28  
29 The following methods should be implemented
30  
31 =cut
32  
33 =head2 new (%args)
34  
35 Should support arguments:
36  
37 =over 4
38  
39 =item internal_encoding [ = undef ]
40  
41 Internal encoding. C<undef> means wide perl characters (perl-5.8.1+)
42  
43 =item external_encoding [ = utf-8 ]
44  
45 External encoding. Which encoding to use in composed XML
46  
47 =back
48  
49 =cut
50  
51 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
52 0 my ( $pkg, %args ) = @_;
53 }
54  
55 # Encoder part
56  
57 =head2 request ($method, @args) : xml byte-stream, [ new call url ]
58  
59 Encode request into XML
60  
61 =cut
62  
63 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
64 0 my ( $self, $method, @args ) = @_;
65 0 croak "request not implemented by $self";
66 #return $xml;
67 }
68  
69 =head2 response (@args) : xml byte-stream
70  
71 Encode response into XML
72  
73 =cut
74  
75 0 ▶sub response {
Subroutine response: not called CC=1 SCAR=6.9
Pod documented
76 0 my ( $self, $method, @args ) = @_;
77 0 croak "response not implemented by $self";
78 #return $xml;
79 }
80  
81 =head2 fault ($faultcode, $faultstring) : xml byte-stream
82  
83 Encode fault into XML
84  
85 =cut
86  
87 0 ▶sub fault {
Subroutine fault: not called CC=1 SCAR=6.9
Pod documented
88 0 my ( $self, $faultcode, $faultstring ) = @_;
89 0 croak "fault not implemented by $self";
90 #return $xml;
91 }
92  
93 =head2 registerClass ($class_name,$encoder_cb)
94  
95 Register encoders for custom Perl types
96  
97 Encoders description:
98  
99 # Generic:
100 $simple_encoder_cb = sub {
101 my $object = shift;
102 # ...
103 return type => $string;
104 };
105  
106 # Encoder-dependent (XML::RPC::Enc::LibXML)
107 $complex_encoder_cb = sub {
108 my $object = shift;
109 # ...
110 return XML::LibXML::Node;
111 };
112  
113 Samples:
114  
115 $enc->registerClass( DateTime => sub {
116 return ( 'dateTime.iso8601' => $_[0]->strftime('%Y%m%dT%H%M%S.%3N%z') );
117 });
118  
119 # Encoder-dependent (XML::RPC::Enc::LibXML)
120 $enc->registerClass( DateTime => sub {
121 my $node = XML::LibXML::Element->new('dateTime.iso8601');
122 $node->appendText($_[0]->strftime('%Y%m%dT%H%M%S.%3N%z'));
123 return $node;
124 });
125  
126 =cut
127  
128 0 ▶sub registerClass {
Subroutine registerClass: not called CC=1 SCAR=6.9
Pod documented
129 0 my ( $self,$class,$encoder ) = @_;
130 0 croak "registerClass not implemented by $self";
131 }
132  
133 # Decoder part
134  
135 =head2 decode ($xml) : $methodname, @args
136  
137 Decode request xml
138  
139 =head2 decode ($xml) : @args
140  
141 Decode response xml
142  
143 =head2 decode ($xml) : { fault => { faultCode => ..., faultString => ... } }
144  
145 Decode fault xml
146  
147 =cut
148  
149 0 ▶sub decode {
Subroutine decode: not called CC=1 SCAR=6.9
Pod documented
150 0 my ( $self, $xml ) = @_;
151 0 croak "decode not implemented by $self";
152 # return $methodname, @args if request
153 # return @args if response
154 # return { fault => { faultCode => ..., faultString => ... } } if fault
155 }
156  
157 =head2 registerType ($xmlrpc_type,$decoder_cb)
158  
159 Register decoders for XML-RPC types
160  
161 $decoder_cb is depends on encoder implementation.
162  
163 Samples for XML::RPC::Enc::LibXML
164  
165 $enc->registerType( base64 => sub {
166 my $node = shift;
167 return MIME::Base64::decode($node->textContent);
168 });
169  
170 $enc->registerType( 'dateTime.iso8601' => sub {
171 my $node = shift;
172 return DateTime::Format::ISO8601->parse_datetime($node->textContent);
173 });
174  
175 =cut
176  
177 0 ▶sub registerType {
Subroutine registerType: not called CC=1 SCAR=6.9
Pod documented
178 0 my ( $self,$type,$decoder ) = @_;
179 0 croak "registerType not implemented by $self";
180 }
181  
182 =head1 COPYRIGHT & LICENSE
183  
184 Copyright (c) 2008-2009 Mons Anderson.
185  
186 This program is free software; you can redistribute it and/or modify it
187 under the same terms as Perl itself.
188  
189 =head1 AUTHOR
190  
191 Mons Anderson, C<< <mons@cpan.org> >>
192  
193 =cut
194  
195 2 1;
« lib/XML/RPC/UA.pm ↑ Summary