blib/lib/Mojolicious/Command/generate/qx_mojo_app/lib/App/Controller/RpcService.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 46 CC 1 SCAR 6.9
CC
1
Cov
0%
allow_rpc_access
2.0
ping
2.0
getUptime
2.0
CRAP 2.0
1 % my $p = shift;
2 package <%= $p->{controller} %>;
3 use Mojo::Base qw(Mojolicious::Plugin::Qooxdoo::JsonRpcController);
4  
5 =head1 NAME
6  
7 <%= $p->{controller} %> - RPC services for <%= $p->{class} %>
8  
9 =head1 SYNOPSIS
10  
11 $route->any("jsonrpc")->to(<%= $p->{controller} %>#dispatch");
12  
13 =head1 DESCRIPTION
14  
15 This controller handles the rpc calls from the Qooxdoo frontend.
16  
17 =head1 ATTRIBUTES
18  
19 All the attributes from L<Mojolicious::Plugin::Qooxdoo::JsonRpcController>.
20  
21 =cut
22  
23 =head1 METHODS
24  
25 All the methods of L<Mojolicious::Plugin::Qooxdoo::JsonRpcController> as well as:
26  
27 =cut
28  
29 =head1 ATTRIBUTES
30  
31 The controller has the following attributes.
32  
33 =cut
34  
35 =head2 service
36  
37 The service property defines the name of the service.
38  
39 =cut
40  
41 has service => sub { "<%= $p->{name} %>"};
42  
43 has log => sub { shift->app->log };
44  
45 =head1 METHODS
46  
47 The controller provides the following methods:
48  
49 =cut
50  
51 =head2 allow_rpc_access(method)
52  
53 The dispatcher will call allow_rpc_access prior to handing over controll.
54  
55 =cut
56  
57 our %allow = (
58 ping => 1,
59 getUptime => 1,
60 makeException => 1,
61 );
62  
63  
64 sub allow_rpc_access {
65 my $self = shift;
66 my $method = shift;
67 return $allow{$method};
68 }
69  
70  
71 =head2 ping(text)
72  
73 The ping response.
74  
75 =cut
76  
77 sub ping {
78 my $self = shift;
79 my $text = shift;
80 $self->log->info("We got pinged");
81 return 'got '.$text;
82 }
83  
84 =head2 getUptime
85  
86 Return the output of uptime.
87  
88 =cut
89  
90 sub getUptime {
91 my $self = shift;
92 return `/usr/bin/uptime`;
93 }
94  
95 =head2 makeException(code,message)
96  
97 Create an exception.
98  
99 =cut
100  
101 sub makeException {
102 my $self = shift;
103 my $arg = shift;
104 die Exception->new(code => $arg->{code}, message => $arg->{message} );
105 }
106  
107 package Exception;
108  
109 use Mojo::Base -base;
110 has 'code';
111 has 'message';
112 use overload ('""' => 'stringify');
113 sub stringify {
114 my $self = shift;
115 return "ERROR ".$self->code.": ".$self->message;
116 }
117  
118 1;
119 <%= '__END__' %>
120  
121 =head1 COPYRIGHT
122  
123 Copyright (c) <%= $p->{year} %> by <%= $p->{fullName} %>. All rights reserved.
124  
125 =head1 AUTHOR
126  
127 S<<%= $p->{fullName} %> E<lt><%= $p->{email} %>E<gt>>
128  
129 =cut
130