line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package QxExample::JsonRpcService; |
2
|
1
|
|
|
1
|
|
2487
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use Mojo::Base 'Mojolicious::Plugin::Qooxdoo::JsonRpcController'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
261
|
use Mojo::Promise; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
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
|
|
|
|
|
19
|
my $method = shift; |
40
|
8
|
|
|
|
|
47
|
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
|
21
|
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
|
|
|
|
|
3
|
my $text = shift; |
64
|
1
|
|
|
|
|
5
|
$self->render_later; |
65
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1.5' => sub { |
66
|
1
|
|
|
1
|
|
1502074
|
$self->renderJsonRpcResult("Delayed $text for 1.5 seconds!"); |
67
|
1
|
|
|
|
|
32
|
}); |
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
|
|
1001405
|
$self->renderJsonRpcError(QxExample::Exception->new(code=>334, message=>"a simple error")); |
75
|
1
|
|
|
|
|
50
|
}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub async_p { |
79
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
80
|
1
|
|
|
|
|
2
|
my $text = shift; |
81
|
1
|
|
|
|
|
9
|
my $p = Mojo::Promise->new; |
82
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1.5' => sub { |
83
|
1
|
|
|
1
|
|
1502043
|
$p->resolve("Delayed $text for 1.5 seconds!"); |
84
|
1
|
|
|
|
|
68
|
}); |
85
|
1
|
|
|
|
|
74
|
return $p; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub asyncException_p { |
89
|
1
|
|
|
1
|
0
|
11
|
my $self = shift; |
90
|
1
|
|
|
|
|
9
|
my $p = Mojo::Promise->new; |
91
|
|
|
|
|
|
|
Mojo::IOLoop->timer('1' => sub { |
92
|
1
|
|
|
1
|
|
1001608
|
$p->reject(QxExample::Exception->new(code=>334, message=>"a simple error")); |
93
|
1
|
|
|
|
|
46
|
}); |
94
|
1
|
|
|
|
|
74
|
return $p; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
package QxExample::Exception; |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
1
|
|
517
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
100
|
|
|
|
|
|
|
has 'code'; |
101
|
|
|
|
|
|
|
has 'message'; |
102
|
1
|
|
|
1
|
|
139
|
use overload ('""' => 'stringify'); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
103
|
|
|
|
|
|
|
sub stringify { |
104
|
2
|
|
|
2
|
|
16
|
my $self = shift; |
105
|
2
|
|
|
|
|
6
|
return "ERROR ".$self->code.": ".$self->message; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |