line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
2
|
|
4207
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
19
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
20
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
209
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Base class for encoders |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
791
|
use XML::RPC::Fast (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1145
|
|
25
|
|
|
|
|
|
|
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 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
|
|
|
|
|
|
|
sub new { |
52
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub request { |
64
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub response { |
76
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub fault { |
88
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub registerClass { |
129
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub decode { |
150
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub registerType { |
178
|
0
|
|
|
0
|
1
|
|
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<< >> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |