lib/Mojolicious/Plugin/Qooxdoo.pm

filter: Statementstmt 92.6% 63 / 68 Branchbran 61.5% 16 / 26 Conditioncond 40.0% 6 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 73.0% 92 / 126 CC 20 SCAR 22.0
CC
20
Cov
78%
register
14.1
__ANON__
7.3
__ANON__
4.0
CRAP 9.0
« lib/Mojolicious/Plugin/Qooxdoo/JsonRpcController.pm ↑ Summary example/lib/QxExample/JsonRpcService.pm »
1 package Mojolicious::Plugin::Qooxdoo;
2  
3 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Spec::Functions qw(splitdir updir catdir file_name_is_absolute);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '1.1.0';
8  
9 2 ▶sub register {
Subroutine register: called CC=12 SCAR=26.5
Pod documented
10 2 my ($self, $app, $conf) = @_;
11  
12 # Config
13 2 ▶ $conf ||= {};
Condition50%1/2
$conf ||= {}
l!l
20
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
Aresult
11
00
14 2 ▶ if ($conf->{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"prefix"}) 2 0 2
15 2 $conf->{prefix} =~ s{^/+}{};
16 2 $conf->{prefix} .= '/';
17 2 $conf->{prefix} =~ s{/+/$}{/};
18 }
19 2 ▶ my $root = ($conf->{prefix} || '/');
Condition50%1/2
$conf->{'prefix'} || '/'
l!l
20
MC/DC0%0/1
$conf->{'prefix'} || '/'
$conf->{'prefix'}
Truth table50%1/2
A
A= $conf->{'prefix'}
Aresult
11
00
20 2 ▶ my $path = $conf->{path} || 'jsonrpc';
Condition50%1/2
$conf->{'path'} || 'jsonrpc'
l!l
20
MC/DC0%0/1
$conf->{'path'} || 'jsonrpc'
$conf->{'path'}
Truth table50%1/2
A
A= $conf->{'path'}
Aresult
11
00
21 2 my $r = $app->routes;
22  
23 2 ▶ if ($conf->{controller}){
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"controller"}) 2 0 2
24 $r->any($root.$path)->to(
25 controller => $conf->{controller},
26 action => 'dispatch',
27 2 ▶ $conf->{namespace} ? ( namespace => $conf->{namespace}):(),
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'namespace'} ? : 0 2 2
28 );
29 }
30 2 ▶ if ($ENV{QX_SRC_MODE}){
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'QX_SRC_MODE'}) { } 1 1 2
31 my $qx_app_src = abs_path(
32 $ENV{QX_SRC_PATH} && file_name_is_absolute($ENV{QX_SRC_PATH})
33 ? $ENV{QX_SRC_PATH}
34 1 ▶ : $app->home->rel_file($ENV{QX_SRC_PATH} || catdir(updir,'frontend','source'))
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'QX_SRC_PATH'} && file_name_is_absolute($ENV{'QX_SRC_PATH'}) ? : 0 1 1
Condition33%2/6
$ENV{"QX_SRC_PATH"} and file_name_is_absolute($ENV{"QX_SRC_PATH"})
!ll&&!rl&&r
010
$ENV{'QX_SRC_PATH'} || catdir('..', 'frontend', 'source')
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{"QX_SRC_PATH"} and file_name_is_absolute($ENV{"QX_SRC_PATH"})
$ENV{"QX_SRC_PATH"} file_name_is_absolute($ENV{"QX_SRC_PATH"})
MC/DC0%0/2
$ENV{'QX_SRC_PATH'} || catdir('..', 'frontend', 'source')
$ENV{'QX_SRC_PATH'} catdir('..', 'frontend', 'source')
Truth table33%1/3
A and B
A= $ENV{"QX_SRC_PATH"}B= file_name_is_absolute($ENV{"QX_SRC_PATH"})
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $ENV{'QX_SRC_PATH'}B= catdir('..', 'frontend', 'source')
ABresult
1X1
011
000
35 );
36 1 $app->log->info("Runnning in QX_SRC_MODE with files from $qx_app_src");
37 1 unshift @{$app->static->paths}, $qx_app_src;
38 1 my %prefixCache;
39 1 my $static = Mojolicious::Static->new();
40 1 ▶ my $static_cb = sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
41 1 my $ctrl = shift;
42 1 my $prefix = $ctrl->param('prefix');
43 1 ▶ if ($ctrl->param('file')){
Branch: 1 branch
BranchTrueFalseTotal
if ($ctrl->param("file")) 1 0 1
44 1 $ctrl->req->url->path('/'.$prefix.'/'.$ctrl->param('file'));
45 }
46 1 ▶ if (not defined $prefixCache{$prefix}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prefixCache{$prefix}) 1 0 1
47 1 my $prefix_local = catdir(split /\//, $prefix);
48 1 my $path = $qx_app_src;
49 1 my $last_path = '';
50 1 ▶ while ($path ne $last_path and not -d catdir($path,$prefix_local)){
Branch: 1 branch
BranchTrueFalseTotal
if ($path ne $last_path and not -d catdir($path, $prefix_local)) 0 1 1
Condition33%1/3
$path ne $last_path and not -d catdir($path, $prefix_local)
!ll&&!rl&&r
010
MC/DC0%0/2
$path ne $last_path and not -d catdir($path, $prefix_local)
$path ne $last_path not -d catdir($path, $prefix_local)
Truth table33%1/3
A and not(B)
A= $path ne $last_pathB= not -d catdir($path, $prefix_local)
ABresult
0X0
100
111
51 0 $last_path = $path;
52 0 $path = abs_path(catdir($last_path,updir));
53 }
54 1 $app->log->info("Auto register static path mapping from '$prefix' to '$path'");
55 1 $prefixCache{$prefix} = $path;
56 }
57 1 $static->paths([$prefixCache{$prefix}]);
58  
59 1 ▶ unless ($static->dispatch($ctrl)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($static->dispatch($ctrl)) 0 1 1
60 0 $ctrl->render(text=>$ctrl->req->url->path.' not found', status => 404);
61 }
62 1 };
63  
64 1 $r->get('/*prefix/framework/source/*a' => $static_cb );
65 1 $r->get('/*prefix/source/class/*a' => $static_cb );
66 1 $r->get('/*prefix/source/resource/*a' => $static_cb );
67 1 $r->get('/*prefix/source/script/*a' => $static_cb );
68 1 $r->get('/*prefix/downloads/*a/source/*b' => $static_cb );
69 1 $r->get('/source/index.html' => {prefix=>'source'} => $static_cb );
70 1 $r->get('/source/class/*b' => {prefix=>'source'} => $static_cb );
71 1 $r->get('/source/resource/*b' => {prefix=>'source'} => $static_cb );
72 1 $r->get('/source/script/*b' => {prefix=>'source'} => $static_cb );
73 1 $r->get($root.'*file' => {prefix => 'source', file => 'index.html' } => $static_cb);
74 }
75 else {
76 # redirect root to index.html
77 0 ▶ $r->any('/' => sub { shift->reply->static('/index.html')});
Subroutine __ANON__: not called CC=1 SCAR=1.2
78 1 ▶ if ($root ne '/'){
Branch: 1 branch
BranchTrueFalseTotal
if ($root ne "/") 1 0 1
79 27 ▶ $app->hook(before_dispatch => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
80 27 my $self = shift;
81 27 my $file = $self->req->url->path->to_string;
82 27 ▶ if ($file =~ s|^/${root}|/|){
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ s[^/$root][/]u) 26 1 27
83 26 ▶ if ($file eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "/") 0 26 26
84 0 $file = '/index.html';
85 }
86 26 ▶ if (-r $app->home->rel_file('public'.$file)){
Branch: 1 branch
BranchTrueFalseTotal
if (-r $app->home->rel_file('public' . $file)) 1 25 26
87 1 $self->req->url->path($file);
88 1 return $app->static->dispatch($self);
89 }
90 }
91 1 });
92 }
93 }
94 }
95  
96 2 1;
97  
98 __END__
« lib/Mojolicious/Plugin/Qooxdoo/JsonRpcController.pm ↑ Summary example/lib/QxExample/JsonRpcService.pm »