File: gateway.psgi

package info (click to toggle)
libdata-amf-perl 0.09%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 544 kB
  • ctags: 527
  • sloc: perl: 5,955; makefile: 14
file content (34 lines) | stat: -rwxr-xr-x 687 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use Data::AMF::Remoting;
use Plack::Request;
use UNIVERSAL::require;

sub
{
	my $env = shift;
	my $req = Plack::Request->new($env);
	my $res = $req->new_response(200);
	
	if ($req->path =~ /\/amf\/gateway$/)
	{
		my $remoting = Data::AMF::Remoting->new(
			source => $req->raw_body,
			message_did_process => sub
			{
				my $message = shift;

				my ($controller_name, $method) = split '\.', $message->target_uri;
				
				$controller_name->require;
				my $controller = $controller_name->new;
				
				return $controller->$method($message->value);
			}
		);
		$remoting->run;
		
		$res->content_type('application/x-amf');
		$res->body($remoting->data);
	}
	
	return $res->finalize;
};