« 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 ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | if ($conf->{prefix}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || '/'
MC/DC0%0/1
$conf->{'prefix'} || '/'
$conf->{'prefix'}
Truth table50%1/2
A
A= $conf->{'prefix'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | my $path = $conf->{path} || 'jsonrpc'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{'path'} || 'jsonrpc'
MC/DC0%0/1
$conf->{'path'} || 'jsonrpc'
$conf->{'path'}
Truth table50%1/2
A
A= $conf->{'path'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $r = $app->routes; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | if ($conf->{controller}){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $r->any($root.$path)->to( | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | controller => $conf->{controller}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | action => 'dispatch', | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | $conf->{namespace} ? ( namespace => $conf->{namespace}):(), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | if ($ENV{QX_SRC_MODE}){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$ENV{"QX_SRC_PATH"} and file_name_is_absolute($ENV{"QX_SRC_PATH"})
$ENV{'QX_SRC_PATH'} || catdir('..', 'frontend', 'source')
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"})
Truth table33%1/3
A || B
A= $ENV{'QX_SRC_PATH'}B= catdir('..', 'frontend', 'source')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | $ctrl->req->url->path('/'.$prefix.'/'.$ctrl->param('file')); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if (not defined $prefixCache{$prefix}){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$path ne $last_path and not -d catdir($path, $prefix_local)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 26 | ▶ | if ($file eq '/') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $file = '/index.html'; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 26 | ▶ | if (-r $app->home->rel_file('public'.$file)){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||