File Coverage

lib/Mojolicious/Plugin/QooxdooJsonrpc.pm
Criterion Covered Total %
statement 22 58 37.9
branch 2 12 16.6
condition 3 15 20.0
subroutine 6 8 75.0
pod 1 1 100.0
total 34 94 36.1


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::QooxdooJsonrpc;
2              
3 1     1   877 use Mojo::Base 'Mojolicious::Plugin';
  1         2  
  1         5  
4 1     1   779 use File::Spec::Functions qw(splitdir updir catdir file_name_is_absolute);
  1         3  
  1         56  
5 1     1   5 use Cwd qw(abs_path);
  1         1  
  1         86  
6              
7             BEGIN {
8 1 50   1   57 warn "Mojolicious::Plugin::QooxdooJsonrpc is DEPRECATED. Please switch to using Mojolicious::Plugin::Qooxdoo.\n" unless $ENV{DISABLE_DEPRECATION_WARNING_MPQ};
9             }
10              
11             our $VERSION = '0.96';
12             # the dispatcher module gets autoloaded, we list it here to
13             # make sure it is available and compiles at startup time and not
14             # only on demand.
15 1     1   6 use MojoX::Dispatcher::Qooxdoo::Jsonrpc;
  1         1  
  1         6  
16              
17             sub register {
18 1     1 1 104 my ($self, $app, $conf) = @_;
19              
20             # Config
21 1   50     4 $conf ||= {};
22 1   50     8 my $root = ($conf->{prefix} || '') . '/';
23 1         2 my $services = $conf->{services};
24 1   50     4 my $path = $conf->{path} || 'jsonrpc';
25 1         20 my $r = $app->routes;
26              
27 1         11 $r->route($root.$path)->to(
28             controller => 'Jsonrpc',
29             action => 'dispatch',
30             namespace => 'MojoX::Dispatcher::Qooxdoo',
31             # our own properties
32             services => $services
33             );
34              
35 1 50       546 if ($ENV{QX_SRC_MODE}){
36 0 0 0     0 my $qx_app_src = abs_path(
      0        
37             $ENV{QX_SRC_PATH} && file_name_is_absolute($ENV{QX_SRC_PATH})
38             ? $ENV{QX_SRC_PATH}
39             : $app->home->rel_dir($ENV{QX_SRC_PATH} || catdir(updir,'frontend','source'))
40             );
41 0         0 $app->log->info("Runnning in QX_SRC_MODE with files from $qx_app_src");
42 0         0 $app->static->paths([$qx_app_src]);
43 0         0 my %prefixCache;
44 0         0 my $static = Mojolicious::Static->new();
45             my $static_cb = sub {
46 0     0   0 my $self = shift;
47 0         0 my $prefix = $self->param('prefix');
48 0 0       0 if ($self->param('file')){
49 0         0 $self->req->url->path('/'.$prefix.'/'.$self->param('file'));
50             }
51 0 0       0 if (not defined $prefixCache{$prefix}){
52 0         0 my $prefix_local = catdir(split /\//, $prefix);
53 0         0 my $path = $qx_app_src;
54 0         0 my $last_path = '';
55 0   0     0 while ($path ne $last_path and not -d catdir($path,$prefix_local)){
56 0         0 $last_path = $path;
57 0         0 $path = abs_path(catdir($last_path,updir));
58             }
59 0         0 $app->log->info("Auto register static path mapping from '$prefix' to '$path'");
60 0         0 $prefixCache{$prefix} = $path;
61             }
62 0         0 $static->paths([$prefixCache{$prefix}]);
63              
64 0 0       0 unless ($static->dispatch($self)){
65 0         0 $self->render(text=>$self->req->url->path.' not found', status => 404);
66             }
67 0         0 };
68              
69 0         0 $r->get('/(*prefix)/framework/source/(*a)' => $static_cb );
70 0         0 $r->get('/(*prefix)/source/class/(*a)' => $static_cb );
71 0         0 $r->get('/(*prefix)/source/resource/(*a)' => $static_cb );
72 0         0 $r->get('/(*prefix)/source/script/(*a)' => $static_cb );
73 0         0 $r->get('/(*prefix)/downloads/(*a)/source/(*b)' => $static_cb );
74 0         0 $r->get('/source/index.html' => {prefix=>'source'} => $static_cb );
75 0         0 $r->get('/source/class/(*b)' => {prefix=>'source'} => $static_cb );
76 0         0 $r->get('/source/resource/(*b)' => {prefix=>'source'} => $static_cb );
77 0         0 $r->get('/source/script/(*b)' => {prefix=>'source'} => $static_cb );
78 0         0 $r->get($root.'(*file)' => {prefix => 'source', file => 'index.html' } => $static_cb);
79             }
80             else {
81             $r->get($root.'(*file)' => {file => 'index.html' } => sub {
82 0     0     my $self = shift;
83 0           my $file = $self->param('file');
84 0           $self->req->url->path('/'.$file);
85 0           return $app->static->dispatch($self);
86 1         14 });
87             }
88             }
89              
90             1;
91              
92             __END__