blib/lib/Catalyst/Plugin/Server/XMLRPC/DispatchType/XMLRPCPath.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 124 CC 15 SCAR 35.3
CC
15
Cov
0%
register
72.0
methods
30.0
list
12.0
CRAP 34.1
1 package Catalyst::Plugin::Server::XMLRPC::DispatchType::XMLRPCPath;
2  
3 use strict;
4 use base qw/Catalyst::DispatchType::Path/;
5 use Text::SimpleTable;
6 use Data::Dumper;
7 use Scalar::Util 'reftype';
8  
9 __PACKAGE__->mk_accessors(qw/config/);
10  
11 =head1 NAME
12  
13 Catalyst::Plugin::Server::XMLRPC::DispatchType::XMLRPCPath - XMLRPCPath DispatchType
14  
15 =head1 SYNOPSIS
16  
17 See L<Catalyst>.
18  
19 =head1 DESCRIPTION
20  
21 =head1 METHODS
22  
23 =head2 $self->list($c)
24  
25 Generates a nice debug-table containing the XMLRPCPath methods.
26  
27 =cut
28  
29 sub list {
30 my ( $self, $c ) = @_;
31 my $prefixwarning = 1;
32  
33 ### Because this is the only place where we need the config
34 $self->config( $c->server->xmlrpc->config );
35  
36 my $paths = Text::SimpleTable->new(
37 [ 36, 'XMLRPCPath Method' ],
38 [ 37, 'Private' ]
39 );
40  
41 for my $method ( sort keys %{ $self->methods($c) } ) {
42 my $action = $self->methods($c)->{$method};
43 $paths->row( $method, "/$action" );
44 }
45  
46 $c->log->debug( "Loaded XMLRPC entrypoint:\n host.tld" .
47 $self->config->path);
48 $c->log->debug( "Loaded XMLRPCPath Method actions:\n" . $paths->draw )
49 if ( keys %{ $self->methods($c) } );
50 $c->log->debug( 'WARNING: XMLRPC prefix set, but _not_ used!' ) if
51 ($prefixwarning && $self->config->prefix);
52  
53 }
54  
55 =head2 $self->methods()
56  
57 Returns a hashref containing 'methods' => action_object mappings. Methods
58 are in the form of "example.bla.get"
59  
60 =cut
61  
62 sub methods {
63 my ( $self, $c ) = @_;
64 my $prefixwarning = 1;
65  
66 ### Cached list of method => path mapping
67 return $self->{methods} if $self->{methods};
68 $self->{methods} = {};
69  
70 ### Because this is the only place where we need the config
71 $self->config( $c->server->xmlrpc->config)
72 unless $self->config;
73  
74 for my $path ( sort keys %{ $self->{_paths} } ) {
75 my $action = (reftype($self->{_paths}->{$path}) eq 'ARRAY') ?
76 $self->{_paths}->{$path}->[0] : $self->{_paths}->{$path};
77 $path = "/$path" unless $path eq '/';
78 my ($method) = $path =~ m|^/?(.*)$|;
79 my $separator= $self->config->separator;
80 my $prefix = $self->config->prefix;
81 $method =~ s|/|$separator|g;
82 $method =~ s|^$prefix\.||g;
83 $self->{methods}->{$method} = $action;
84 }
85  
86 return $self->{methods};
87 }
88  
89 =head2 $self->register( $c, $action )
90  
91 Registers the XMLRPCPath actions into the dispatcher
92  
93 =cut
94  
95 sub register {
96 my ( $self, $c, $action ) = @_;
97  
98 my $attrs = $action->attributes;
99 my @register;
100  
101 foreach my $r ( @{ $attrs->{XMLRPCPath} || [] } ) {
102 unless ($r) {
103 $r = $action->namespace;
104 $r = '/' unless $r;
105 }
106 elsif ( $r !~ m!^/! ) { # It's a relative path
107 $r = $action->namespace . "/$r";
108 }
109 push( @register, $r );
110 }
111  
112 if ( $attrs->{XMLRPCGlobal} ) {
113 push( @register, $action->name ); # Register sub name against root
114 }
115  
116 if ( $attrs->{XMLRPCLocal} || $attrs->{XMLRPC} ) {
117 push( @register, join( '/', $action->namespace, $action->name ) );
118  
119 # Register sub name as a relative path
120 }
121  
122 $self->register_path( $c, $_, $action ) for @register;
123  
124 $c->server->xmlrpc->dispatcher->{Path} = $self
125 unless (scalar %{$c->server->xmlrpc->dispatcher});
126  
127 return 1 if @register;
128 return 0;
129 }
130  
131 sub match {
132 my $self = shift;
133 my ($c, $name) = @_;
134  
135 ### This subtile line is available to prevent backing up to
136 ### a default action
137 return unless $c->req->path eq $name;
138  
139 $self->next::method( @_ );
140 }
141  
142  
143 =head1 AUTHOR
144  
145 Michiel Ootjers C<michiel@cpan.org>
146 Jos Boumans, C<kane@cpan.org>
147  
148 =head1 COPYRIGHT
149  
150 This program is free software, you can redistribute it and/or modify it under
151 the same terms as Perl itself.
152  
153 =cut
154  
155 1;