line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::AMF; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24729
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1047
|
use parent "Plack::Middleware"; |
|
1
|
|
|
|
|
320
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
25746
|
use Data::AMF::Remoting; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Plack::Request; |
12
|
|
|
|
|
|
|
use Plack::Util; |
13
|
|
|
|
|
|
|
use Plack::Util::Accessor qw/path headers_handler message_handler/; |
14
|
|
|
|
|
|
|
use UNIVERSAL::require; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub prepare_app { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
unless (defined $self->headers_handler) { |
20
|
|
|
|
|
|
|
$self->headers_handler(\&_default_headers_handler); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
unless (defined $self->message_handler) { |
24
|
|
|
|
|
|
|
$self->message_handler(\&_default_message_handler); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if (ref $self->headers_handler ne 'CODE') { |
28
|
|
|
|
|
|
|
die 'headers_handler should be a code reference'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if (ref $self->message_handler ne 'CODE') { |
32
|
|
|
|
|
|
|
die 'message_handler should be a code reference'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub call { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
my $env = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $res = $self->_handle_amf($env); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return $res if $res; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $self->app->($env); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _handle_amf { |
48
|
|
|
|
|
|
|
my ($self, $env) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $path_match = $self->path or return; |
51
|
|
|
|
|
|
|
my $path = $env->{PATH_INFO}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
for ($path) { |
54
|
|
|
|
|
|
|
my $matched = 'CODE' eq ref $path_match ? $path_match->($_) : $_ =~ $path_match; |
55
|
|
|
|
|
|
|
return unless $matched; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $req = Plack::Request->new($env); |
59
|
|
|
|
|
|
|
my $res = $req->new_response(200); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $remoting = Data::AMF::Remoting->new( |
62
|
|
|
|
|
|
|
source => $req->raw_body, |
63
|
|
|
|
|
|
|
headers_did_process => $self->headers_handler, |
64
|
|
|
|
|
|
|
message_did_process => $self->message_handler, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
$remoting->run if $remoting->{source}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$res->content_type('application/x-amf'); |
69
|
|
|
|
|
|
|
$res->body($remoting->data); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return $res->finalize; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _default_headers_handler {} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _default_message_handler { |
77
|
|
|
|
|
|
|
my $message = shift; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my ($controller_name, $action_name) = split '\.', $message->target_uri; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$controller_name->require or die $@; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $controller = $controller_name->new; |
84
|
|
|
|
|
|
|
my $action = $controller->can($action_name); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
if (defined $action) { |
87
|
|
|
|
|
|
|
return $controller->$action(@{ $message->value }); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |