freeside/FS/FS XMLRPC.pm,1.1,1.2
Kristian Hoffmann
khoff at pouncequick.420.am
Tue Mar 8 10:15:12 PST 2005
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv22024
Modified Files:
XMLRPC.pm
Log Message:
Minor re-work to allow for pseudo methods, like 'version', and eventually config look-ups (next commit).
Index: XMLRPC.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/XMLRPC.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- XMLRPC.pm 2 Mar 2005 21:00:59 -0000 1.1
+++ XMLRPC.pm 8 Mar 2005 18:15:09 -0000 1.2
@@ -3,8 +3,12 @@
use strict;
use vars qw( @ISA $DEBUG );
use Frontier::RPC2;
-use FS::Record qw( qsearch qsearchs );
-use FS::cust_main qw( smart_search );
+
+# Instead of 'use'ing freeside modules on the fly below, just preload them now.
+use FS;
+use FS::CGI;
+use FS::Record;
+use FS::cust_main;
@ISA = qw( );
@@ -84,39 +88,48 @@
#die 'Called _serve without parameters' unless ref($params) eq 'ARRAY';
$params = [] unless (ref($params) eq 'ARRAY');
- my ($class, $sub) = split(/\./, $method_name);
- my $fssub = "FS::${class}::${sub}";
- warn "fssub: ${fssub}" if $DEBUG;
- warn "params: " . Dumper($params) if $DEBUG;
-
- unless (UNIVERSAL::can("FS::${class}", $sub)) {
- warn "FS::XMLRPC: Can't call undefined subroutine '${fssub}'";
- # Should we encode an error in the response,
- # or just break silently to the remote caller and complain locally?
- return [];
- }
+ if ($method_name =~ /^(\w+)\.(\w+)/) {
- my @result;
- eval {
- no strict 'refs';
+ #my ($class, $sub) = split(/\./, $method_name);
+ my ($class, $sub) = ($1, $2);
my $fssub = "FS::${class}::${sub}";
- @result = (&$fssub(@$params));
- };
+ warn "fssub: ${fssub}" if $DEBUG;
+ warn "params: " . Dumper($params) if $DEBUG;
- if ($@) {
- warn "FS::XMLRPC: Error while calling '${fssub}': $@";
- return [];
- }
+ unless (UNIVERSAL::can("FS::${class}", $sub)) {
+ warn "FS::XMLRPC: Can't call undefined subroutine '${fssub}'";
+ # Should we encode an error in the response,
+ # or just break silently to the remote caller and complain locally?
+ return [];
+ }
- warn Dumper(@result);
+ my @result;
+ eval {
+ no strict 'refs';
+ my $fssub = "FS::${class}::${sub}";
+ @result = (&$fssub(@$params));
+ };
- if (grep { UNIVERSAL::can($_, 'hashref') ? 0 : 1 } @result) {
- warn "FS::XMLRPC: One or more objects returned from '${fssub}' doesn't " .
- "support the 'hashref' method.";
- return [];
- } else {
- return [ map { $_->hashref } @result ];
- }
+ if ($@) {
+ warn "FS::XMLRPC: Error while calling '${fssub}': $@";
+ return [];
+ }
+
+ warn Dumper(@result);
+
+ if (grep { UNIVERSAL::can($_, 'hashref') ? 0 : 1 } @result) {
+ warn "FS::XMLRPC: One or more objects returned from '${fssub}' doesn't " .
+ "support the 'hashref' method.";
+ return [];
+ } else {
+ return [ map { $_->hashref } @result ];
+ }
+ } elsif ($method_name eq 'version') {
+ return [ $FS::VERSION ];
+ } # else...
+
+ warn "Unhandle XMLRPC request '${method_name}'";
+ return [];
}
More information about the freeside-commits
mailing list