Perl SDK

From Multi Theft Auto: Wiki

Currently there is not a Perl SDK as such, but you can use the following code to call a function on an MTA server, assuming you have access:

using JSON;

sub callFunction {
	my ($server, $resourcename, $functionname) = @_;
	my $content = objToJson([@_[3..$#_]]);
	$ua = LWP::UserAgent->new;
	my $url = "http://" . $server . "/" . $resourcename . "/call/" . $functionname;
	$req = HTTP::Request->new(POST => $url);
	$req->header('Accept' => 'text/html');
	$res = $ua->request($req);
	my $ret = "";
	eval {
		$ret = jsonToObj($res->content);
	return $ret;

This requires that you install the JSON package. You can do this easily by navigating to your perl 'bin' directory and executing "cpan", then typing "install JSON".


my $ret = callFunction("hostname:httpPort", "resourceName", "functionName" [, args ...]);

The function returns an array of the values returned by the function.