Plugin/XMLRPC.pm

filter: Statementstmt 35.0% 28 / 80 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 8 / 12 Podpod 100% 2 / 2 totaltotal 32.2% 38 / 118 CC 11 SCAR 42.0
CC
11
Cov
28%
xmlrpc
132.0
setup_dispatcher
2.0
_deserialize_xmlrpc
2.0
CRAP 66.6
↑ Summary Plugin/XMLRPC/DispatchType/XMLRPC.pm »
1 package Catalyst::Plugin::XMLRPC;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base 'Class::Data::Inheritable';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use attributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use RPC::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use RPC::XML::ParserFactory 'XML::Parser';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catalyst::Action;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catalyst::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use NEXT;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '2.01';
13  
14 1 __PACKAGE__->mk_classdata('_xmlrpc_parser');
15 1 __PACKAGE__->_xmlrpc_parser( RPC::XML::ParserFactory->new );
16  
17 =head1 NAME
18  
19 Catalyst::Plugin::XMLRPC - DEPRECATED Dispatch XMLRPC methods with Catalyst
20  
21 =head1 SYNOPSIS
22  
23 # Include it in plugin list
24 use Catalyst qw/XMLRPC/;
25  
26 # Public action to redispatch somewhere in a controller
27 sub entrypoint : Global : Action('XMLRPC') {}
28  
29 # Methods with XMLRPC attribute in any controller
30 sub echo : XMLRPC('myAPI.echo') {
31 my ( $self, $c, @args ) = @_;
32 return RPC::XML::fault->new( 400, "No input!" ) unless @args;
33 return join ' ', @args;
34 }
35  
36 sub add : XMLRPC {
37 my ( $self, $c, $a, $b ) = @_;
38 return $a + $b;
39 }
40  
41 =head1 DESCRIPTION
42  
43 This plugin is DEPRECATED. Please do not use in new code.
44  
45 This plugin allows your controller class to dispatch XMLRPC methods
46 from its own class.
47  
48 =head1 METHODS
49  
50 =head2 $c->xmlrpc
51  
52 Call this method from a controller action to set it up as a endpoint.
53  
54 =cut
55  
56 0 ▶sub xmlrpc {
Subroutine xmlrpc: not called CC=11 SCAR=48.8
Pod documented
57 0 my $c = shift;
58  
59 # Deserialize
60 0 my $req;
61 0 eval { $req = $c->_deserialize_xmlrpc };
62 0 ▶ if ( $@ || !$req ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $req) 0 0 0
Condition0%0/3
$@ or not $req
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $req
$@ not $req
Truth table0%0/3
A or not(B)
A= $@B= not $req
ABresult
1X1
011
000
63 0 ▶ $c->log->debug(qq/Invalid XMLRPC request "$@"/) if $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 0 0
64 0 $c->_serialize_xmlrpc( RPC::XML::fault->new( -1, 'Invalid request' ) );
65 0 return 0;
66 }
67  
68 0 my $res = RPC::XML::fault->new( -2, "No response for request" );
69  
70 # We have a method
71 0 my $method = $req->{method};
72 0 ▶ $c->log->debug(qq/XMLRPC request for "$method"/) if $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 0 0
73  
74 0 ▶ if ($method) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method) 0 0 0
75  
76 0 my $container;
77 0 for my $type ( @{ $c->dispatcher->dispatch_types } ) {
78 0 ▶ $container = $type
Branch: 1 branch
BranchTrueFalseTotal
if $type->isa("Catalyst::Plugin::XMLRPC::DispatchType::XMLRPC") 0 0 0
79 if $type->isa('Catalyst::Plugin::XMLRPC::DispatchType::XMLRPC');
80 }
81  
82 0 ▶ if ($container) {
Branch: 1 branch
BranchTrueFalseTotal
if ($container) { } 0 0 0
83 0 ▶ if ( my $action = $container->{methods}{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $container->{'methods'}{$method}) { } 0 0 0
84 0 my $class = $action->class;
85 0 ▶ $class = $c->components->{$class} || $class;
Condition0%0/3
$c->components->{$class} || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->components->{$class} || $class
$c->components->{$class} $class
Truth table0%0/3
A || B
A= $c->components->{$class}B= $class
ABresult
1X1
011
000
86 0 my @args = @{ $c->req->args };
87 0 $c->req->args( $req->{args} );
88 0 $c->state( $c->execute( $class, $action ) );
89 0 $res = $c->state;
90 0 $c->req->args( \@args );
91 }
92 0 else { $res = RPC::XML::fault->new( -4, "Unknown method" ) }
93 }
94 0 else { $res = RPC::XML::fault->new( -3, "Please come back later" ) }
95  
96 }
97  
98 # Serialize response
99 0 $c->_serialize_xmlrpc($res);
100 0 return $res;
101 }
102  
103 =head2 setup_dispatcher
104  
105 =cut
106  
107 # Register our DispatchType
108 0 ▶sub setup_dispatcher {
Subroutine setup_dispatcher: not called CC=1 SCAR=6.9
Pod documented
109 0 my $c = shift;
110 0 $c->NEXT::setup_dispatcher(@_);
111 0 push @{ $c->dispatcher->preload_dispatch_types },
112 '+Catalyst::Plugin::XMLRPC::DispatchType::XMLRPC';
113 0 return $c;
114 }
115  
116 # Deserializes the xml in $c->req->body
117 0 ▶sub _deserialize_xmlrpc {
Subroutine _deserialize_xmlrpc: not called CC=1 SCAR=6.9
118 0 my $c = shift;
119  
120 0 my $p = $c->_xmlrpc_parser->parse;
121 0 my $body = $c->req->body;
122 0 my $content = do { local $/; <$body> };
123 0 $p->parse_more($content);
124 0 my $req = $p->parse_done;
125  
126 0 my $name = $req->name;
127 0 my @args = map { $_->value } @{ $req->args };
128  
129 0 return { method => $name, args => \@args };
130 }
131  
132 # Serializes the response to $c->res->body
133 0 ▶sub _serialize_xmlrpc {
Subroutine _serialize_xmlrpc: not called CC=1 SCAR=6.9
134 0 my ( $c, $status ) = @_;
135 0 my $res = RPC::XML::response->new($status);
136 0 $c->res->content_type('text/xml');
137 0 $c->res->body( $res->as_string );
138 }
139  
140 =head1 SEE ALSO
141  
142 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
143 L<Catalyst::Response>, L<Catalyst::Helper>, L<RPC::XML>
144  
145 =head1 AUTHORS
146  
147 Sebastian Riedel, C<sri@oook.de>
148 Marcus Ramberg, C<mramberg@cpan.org>
149 Christian Hansen
150 Yoshinori Sano
151 Michiel Ootjers
152 Jos Boumans
153  
154 =head1 COPYRIGHT
155  
156 Copyright (c) 2005
157 the Catalyst::Plugin::XMLRPC L</AUTHORS>
158 as listed above.
159  
160 =head1 LICENSE
161  
162 This library is free software, you can redistribute it and/or modify
163 it under the same terms as Perl itself.
164  
165 =cut
166  
167 1 1;
↑ Summary Plugin/XMLRPC/DispatchType/XMLRPC.pm »