example/lib/QxExample/JsonRpcService.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 50.0% 3 / 6 totaltotal 95.9% 71 / 74 CC 2 SCAR 1.1
CC
2
Cov
100%
echo
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Mojolicious/Plugin/Qooxdoo.pm ↑ Summary example/lib/QxExample.pm »
1 package QxExample::JsonRpcService;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Mojo::Base 'Mojolicious::Plugin::Qooxdoo::JsonRpcController';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Promise;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 JsonRpcService - RPC services for Qooxdoo
10  
11 =head1 SYNOPSIS
12  
13 This module gets instanciated by L<ep::MojoApp> 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 9 ▶has service => sub { 'rpc' };
Subroutine __ANON__: called CC=1 SCAR=0.0
28  
29 1 our %allow_access = (
30 echo => 1,
31 async => 1,
32 asyncException => 1,
33 async_p => 1,
34 asyncException_p => 1,
35 );
36  
37 14 ▶sub allow_rpc_access {
Subroutine allow_rpc_access: called CC=1 SCAR=0.0
Pod documented
38 14 my $self = shift;
39 14 my $method = shift;
40 14 return $allow_access{$method};
41 }
42  
43 =head2 echo(var)
44  
45 return the string we input
46  
47 =cut
48  
49 6 ▶sub echo {
Subroutine echo: called CC=2 SCAR=6.9
Pod documented
50 6 my $self = shift;
51 6 ▶ my $arg = shift or die QxExample::Exception->new(code=>123,message=>"Argument Required!");
Branch: 1 branch
BranchTrueFalseTotal
my $arg = shift() or die "QxExample::Exception"->new("code", 123, "message", "Argument Required!") 4 2 6
52 4 return $arg;
53 }
54  
55 =head2 async(var)
56  
57 return the answer with a 1 second delay
58  
59 =cut
60  
61 2 ▶sub async {
Subroutine async: called CC=1 SCAR=0.0
Pod documented
62 2 my $self = shift;
63 2 my $text = shift;
64 2 $self->render_later;
65 2 ▶ Mojo::IOLoop->timer('1.5' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 2 $self->renderJsonRpcResult("Delayed $text for 1.5 seconds!");
67 2 });
68 }
69  
70 2 ▶sub asyncException {
Subroutine asyncException: called CC=1 SCAR=0.0
Pod undocumented
71 2 my $self = shift;
72 2 $self->render_later;
73 2 ▶ Mojo::IOLoop->timer('1' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
74 2 $self->renderJsonRpcError(QxExample::Exception->new(code=>334, message=>"a simple error"));
75 2 });
76 }
77  
78 1 ▶sub async_p {
Subroutine async_p: called CC=1 SCAR=0.0
Pod undocumented
79 1 my $self = shift;
80 1 my $text = shift;
81 1 my $p = Mojo::Promise->new;
82 1 ▶ Mojo::IOLoop->timer('1.5' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
83 1 $p->resolve("Delayed $text for 1.5 seconds!");
84 1 });
85 1 return $p;
86 }
87  
88 1 ▶sub asyncException_p {
Subroutine asyncException_p: called CC=1 SCAR=0.0
Pod undocumented
89 1 my $self = shift;
90 1 my $p = Mojo::Promise->new;
91 1 ▶ Mojo::IOLoop->timer('1' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
92 1 $p->reject(QxExample::Exception->new(code=>334, message=>"a simple error"));
93 1 });
94 1 return $p;
95 }
96  
97 package QxExample::Exception;
98  
99 1 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 has 'code';
101 1 has 'message';
102 1 ▶use overload ('""' => 'stringify');
Subroutine BEGIN: called CC=1 SCAR=0.0
103 2 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
104 2 my $self = shift;
105 2 return "ERROR ".$self->code.": ".$self->message;
106 }
107  
108 1 1;
109 __END__
« lib/Mojolicious/Plugin/Qooxdoo.pm ↑ Summary example/lib/QxExample.pm »