|
@@ -18,14 +18,38 @@ sub run {
|
|
|
# Process the args
|
|
# Process the args
|
|
|
my $args = Troglodyne::CGI::get_args();
|
|
my $args = Troglodyne::CGI::get_args();
|
|
|
|
|
|
|
|
|
|
+ # XXX Validation plz
|
|
|
|
|
+
|
|
|
|
|
+ # Load route code
|
|
|
|
|
+ my $namespace = "Troglodyne::API::$args->{'module'}";
|
|
|
|
|
+ my ( $loaded, $err, $coderef );
|
|
|
|
|
+ {
|
|
|
|
|
+ local $@;
|
|
|
|
|
+ $loaded = eval {
|
|
|
|
|
+ Cpanel::LoadModule::Custom::load_perl_module($namespace);
|
|
|
|
|
+ };
|
|
|
|
|
+ $err = $@;
|
|
|
|
|
+ $coderef = $namespace->can($args->{'function'});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
# Get back the datastruct from the called module.
|
|
# Get back the datastruct from the called module.
|
|
|
|
|
+ # Yeah, yeah, I know. String eval. XXX
|
|
|
my $ret = {
|
|
my $ret = {
|
|
|
'metadata' => {
|
|
'metadata' => {
|
|
|
'input_args' => $args,
|
|
'input_args' => $args,
|
|
|
},
|
|
},
|
|
|
- 'data' => {},
|
|
|
|
|
- 'result' => 1,
|
|
|
|
|
};
|
|
};
|
|
|
|
|
+ if( $loaded && $coderef ) {
|
|
|
|
|
+ my $data = $coderef->();
|
|
|
|
|
+ $ret->{'data'} = $data;
|
|
|
|
|
+ $ret->{'result'} = 1;
|
|
|
|
|
+ } elsif( !$coderef ) {
|
|
|
|
|
+ $ret->{'error'} = "No such function '$args->{'function'}' in $namespace";
|
|
|
|
|
+ $ret->{'result'} = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $ret->{'error'} = $err;
|
|
|
|
|
+ $ret->{'result'} = 0;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
# Emit the JSON
|
|
# Emit the JSON
|
|
|
print "Content-type: application/json\r\n\r\n";
|
|
print "Content-type: application/json\r\n\r\n";
|