line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package QxExample::JsonRpcService; |
2
|
1
|
|
|
1
|
|
2311
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use Mojo::Base 'Mojolicious::Plugin::Qooxdoo::JsonRpcController'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
219
|
use Mojo::Promise; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
JsonRpcService - RPC services for Qooxdoo |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This module gets instanciated by L and provides backend functionality for your qooxdoo app |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
All methods on this class can get called remotely as long as their name does not start with an underscore. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 allow_rpc_access |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
the dispatcher will call the allow_rpc_access method to determine if it may execute |
23
|
|
|
|
|
|
|
the given method. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has service => sub { 'rpc' }; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our %allow_access = ( |
30
|
|
|
|
|
|
|
echo => 1, |
31
|
|
|
|
|
|
|
async => 1, |
32
|
|
|
|
|
|
|
asyncException => 1, |
33
|
|
|
|
|
|
|
async_p => 1, |
34
|
|
|
|
|
|
|
asyncException_p => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub allow_rpc_access { |
38
|
8
|
|
|
8
|
1
|
16
|
my $self = shift; |
39
|
8
|
|
|
|
|
20
|
my $method = shift; |
40
|
8
|
|
|
|
|
48
|
return $allow_access{$method}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 echo(var) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return the string we input |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub echo { |
50
|
3
|
|
|
3
|
1
|
20
|
my $self = shift; |
51
|
3
|
100
|
|
|
|
15
|
my $arg = shift or die QxExample::Exception->new(code=>123,message=>"Argument Required!"); |
52
|
2
|
|
|
|
|
16
|
return $arg; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 async(var) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return the answer with a 1 second delay |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub async { |
62
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
63
|
1
|
|
|
|
|
6
|
my $text = shift; |
64
|
1
|
|
|
|
|
4
|
$self->render_later; |
65
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1.5' => sub { |
66
|
1
|
|
|
1
|
|
1502029
|
$self->renderJsonRpcResult("Delayed $text for 1.5 seconds!"); |
67
|
1
|
|
|
|
|
36
|
}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub asyncException { |
71
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
72
|
1
|
|
|
|
|
5
|
$self->render_later; |
73
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1' => sub { |
74
|
1
|
|
|
1
|
|
1001557
|
$self->renderJsonRpcError(QxExample::Exception->new(code=>334, message=>"a simple error")); |
75
|
1
|
|
|
|
|
26
|
}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub async_p { |
79
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
80
|
1
|
|
|
|
|
3
|
my $text = shift; |
81
|
1
|
|
|
|
|
9
|
my $p = Mojo::Promise->new; |
82
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1.5' => sub { |
83
|
1
|
|
|
1
|
|
1502057
|
$p->resolve("Delayed $text for 1.5 seconds!"); |
84
|
1
|
|
|
|
|
75
|
}); |
85
|
1
|
|
|
|
|
76
|
return $p; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub asyncException_p { |
89
|
1
|
|
|
1
|
0
|
7
|
my $self = shift; |
90
|
1
|
|
|
|
|
7
|
my $p = Mojo::Promise->new; |
91
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1' => sub { |
92
|
1
|
|
|
1
|
|
1001673
|
$p->reject(QxExample::Exception->new(code=>334, message=>"a simple error")); |
93
|
1
|
|
|
|
|
38
|
}); |
94
|
1
|
|
|
|
|
76
|
return $p; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
package QxExample::Exception; |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
1
|
|
870
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
100
|
|
|
|
|
|
|
has 'code'; |
101
|
|
|
|
|
|
|
has 'message'; |
102
|
1
|
|
|
1
|
|
140
|
use overload ('""' => 'stringify'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
103
|
|
|
|
|
|
|
sub stringify { |
104
|
2
|
|
|
2
|
|
13
|
my $self = shift; |
105
|
2
|
|
|
|
|
5
|
return "ERROR ".$self->code.": ".$self->message; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |