line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package QxExample::JsonRpcService; |
2
|
1
|
|
|
1
|
|
3088
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use Mojo::Base 'Mojolicious::Plugin::Qooxdoo::JsonRpcController'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
295
|
use Mojo::Promise; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
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
|
20
|
my $self = shift; |
39
|
8
|
|
|
|
|
20
|
my $method = shift; |
40
|
8
|
|
|
|
|
50
|
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
|
22
|
my $self = shift; |
51
|
3
|
100
|
|
|
|
20
|
my $arg = shift or die QxExample::Exception->new(code=>123,message=>"Argument Required!"); |
52
|
2
|
|
|
|
|
12
|
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
|
8
|
my $self = shift; |
63
|
1
|
|
|
|
|
4
|
my $text = shift; |
64
|
1
|
|
|
|
|
6
|
$self->render_later; |
65
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1.5' => sub { |
66
|
1
|
|
|
1
|
|
1502134
|
$self->renderJsonRpcResult("Delayed $text for 1.5 seconds!"); |
67
|
1
|
|
|
|
|
41
|
}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub asyncException { |
71
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
72
|
1
|
|
|
|
|
6
|
$self->render_later; |
73
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1' => sub { |
74
|
1
|
|
|
1
|
|
1001548
|
$self->renderJsonRpcError(QxExample::Exception->new(code=>334, message=>"a simple error")); |
75
|
1
|
|
|
|
|
28
|
}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub async_p { |
79
|
1
|
|
|
1
|
0
|
10
|
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
|
|
1502046
|
$p->resolve("Delayed $text for 1.5 seconds!"); |
84
|
1
|
|
|
|
|
73
|
}); |
85
|
1
|
|
|
|
|
74
|
return $p; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub asyncException_p { |
89
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
90
|
1
|
|
|
|
|
10
|
my $p = Mojo::Promise->new; |
91
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1' => sub { |
92
|
1
|
|
|
1
|
|
1001618
|
$p->reject(QxExample::Exception->new(code=>334, message=>"a simple error")); |
93
|
1
|
|
|
|
|
48
|
}); |
94
|
1
|
|
|
|
|
111
|
return $p; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
package QxExample::Exception; |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
1
|
|
546
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
100
|
|
|
|
|
|
|
has 'code'; |
101
|
|
|
|
|
|
|
has 'message'; |
102
|
1
|
|
|
1
|
|
170
|
use overload ('""' => 'stringify'); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
103
|
|
|
|
|
|
|
sub stringify { |
104
|
2
|
|
|
2
|
|
42
|
my $self = shift; |
105
|
2
|
|
|
|
|
7
|
return "ERROR ".$self->code.": ".$self->message; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |