Tables.pm

filter: Statementstmt 88.2% 90 / 102 Branchbran 61.1% 11 / 18 Conditioncond 54.5% 12 / 22 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 81.8% 9 / 11 Podpod 100% 1 / 1 totaltotal 76.9% 127 / 165 CC 30 SCAR 23.8
CC
30
Cov
80%
register
19.0
__ANON__
9.9
__ANON__
6.1
CRAP 10.9
« Tables/Controller/Tables.pm ↑ Summary Tables/Model.pm »
1 package Mojolicious::Plugin::Tables;
2 3 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use File::Basename 'dirname';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use File::Spec::Functions 'catdir';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Mojolicious::Plugin::Tables::Model;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '1.08';
10  
11 3 ▶sub register {
Subroutine register: called CC=16 SCAR=29.4
Pod documented
12 3 my ($self, $app, $conf) = @_;
13  
14 3 my $log = $app->log;
15  
16 0 ▶ $app->helper(add_stash => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
17 0 my ($c, $slot, $val) = @_;
18 0 ▶ push @{$c->stash->{$slot} ||= []}, $val;
Condition0%0/2
$c->stash->{$slot} ||= []
l!l
00
MC/DC0%0/1
$c->stash->{$slot} ||= []
$c->stash->{$slot}
Truth table0%0/2
A
A= $c->stash->{$slot}
Aresult
11
00
19 3 });
20  
21 0 ▶ $app->helper(add_flash => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
22 0 my ($c, $slot, $val) = @_;
23 0 ▶ push @{$c->session->{new_flash}{$slot} ||= []}, $val;
Condition0%0/2
$c->session->{"new_flash"}{$slot} ||= []
l!l
00
MC/DC0%0/1
$c->session->{"new_flash"}{$slot} ||= []
$c->session->{"new_flash"}{$slot}
Truth table0%0/2
A
A= $c->session->{"new_flash"}{$slot}
Aresult
11
00
24 3 });
25  
26 45 ▶ $app->helper(shipped => sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
27 # special stash slot for sending json-able structs to js;
28 # get/set logic here cloned from Mojo::Util::_stash.
29 45 my $c = shift;
30 45 ▶ my $shipped = $c->stash->{shipped} ||= {};
Condition100%2/2
$c->stash->{"shipped"} ||= {}
l!l
378
MC/DC100%1/1
$c->stash->{"shipped"} ||= {}
$c->stash->{"shipped"}
Truth table100%2/2
A
A= $c->stash->{"shipped"}
Aresult
11
00
31 45 ▶ return $shipped unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 41 45
32 41 ▶ return $shipped->{$_[0]} unless @_>1 || ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 or ref $_[0] 19 22 41
Condition66%2/3
@_ > 1 or ref $_[0]
l!l&&r!l&&!r
22019
MC/DC50%1/2
@_ > 1 or ref $_[0]
@_ > 1 ref $_[0]
Truth table66%2/3
A or B
A= @_ > 1B= ref $_[0]
ABresult
1X1
011
000
33 22 ▶ my $values = ref $_[0]? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 22 22
34 22 @$shipped{keys %$values} = values %$values;
35 3 });
36  
37 3 $app->config(default_theme=>'redmond');
38 3 ▶ $app->defaults(layout => $conf->{layout} || 'tables');
Condition50%1/2
$conf->{'layout'} || 'tables'
l!l
03
MC/DC0%0/1
$conf->{'layout'} || 'tables'
$conf->{'layout'}
Truth table50%1/2
A
A= $conf->{'layout'}
Aresult
11
00
39  
40 3 ▶ my $model_class = $conf->{model_class} ||= 'Mojolicious::Plugin::Tables::Model';
Condition50%1/2
$conf->{"model_class"} ||= "Mojolicious::Plugin::Tables::Model"
l!l
03
MC/DC0%0/1
$conf->{"model_class"} ||= "Mojolicious::Plugin::Tables::Model"
$conf->{"model_class"}
Truth table50%1/2
A
A= $conf->{"model_class"}
Aresult
11
00
41 3 ▶ eval "require $model_class" or die;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $model_class" or die 3 0 3
42  
43 3 $model_class->log($log);
44 3 my $schema = $model_class->setup($conf);
45 3 my $model = $schema->model;
46 3 $app->config(model=>$model);
47  
48  
49 8 ▶ $app->hook(before_dispatch => sub {
Subroutine __ANON__: called CC=5 SCAR=22.9
50 8 my $c = shift;
51 # Move first part and slash from path to base path when deployed under a path
52 8 ▶ if ($c->app->config('deployed-under-path')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->app->config('deployed-under-path')) { } 0 8 8
53 0 my $part0 = shift @{$c->req->url->path->leading_slash(0)};
54 0 push @{$c->req->url->base->path->trailing_slash(0)}, $part0;
55 0 $c->shipped(urlbase => $c->req->url->base);
56 } else {
57 8 $c->shipped(urlbase => '');
58 }
59 # capture https into base
60 8 ▶ if ($c->req->headers->header('X-Forwarded-HTTPS')
Branch: 1 branch
BranchTrueFalseTotal
if ($c->req->headers->header("X-Forwarded-HTTPS") or ($c->req->headers->header("X-Forwarded-Proto") || "") eq "https") 0 8 8
Condition40%2/5
$c->req->headers->header("X-Forwarded-HTTPS") or ($c->req->headers->header("X-Forwarded-Proto") || "") eq "https"
l!l&&r!l&&!r
008
$c->req->headers->header('X-Forwarded-Proto') || ''
l!l
08
MC/DC0%0/2
$c->req->headers->header("X-Forwarded-HTTPS") or ($c->req->headers->header("X-Forwarded-Proto") || "") eq "https"
$c->req->headers->header("X-Forwarded-HTTPS") $c->req->headers->header('X-Forwarded-Proto')
Truth table33%1/3
A or B
A= $c->req->headers->header("X-Forwarded-HTTPS")B= $c->req->headers->header('X-Forwarded-Proto')
ABresult
1X1
011
000
61 || ($c->req->headers->header('X-Forwarded-Proto')||'') eq 'https') {
62 0 $c->req->url->base->scheme('https')
63 }
64 3 });
65  
66  
67 3 my $plugin_resources = catdir dirname(__FILE__), 'Tables', 'resources';
68 3 push @{$app->routes->namespaces}, 'Mojolicious::Plugin::Tables::Controller';
69 3 push @{$app->renderer->paths}, catdir($plugin_resources, 'templates');
70 3 push @{$app->static->paths}, catdir($plugin_resources, 'public');
71  
72 # Arrange for custom table-specific template overrides, when present.
73 # We do this by wrapping the standard ep-handler with a
74 # pre-processor to test for existence of the custom template.
75 # Any internal caching by EP renderer is preserved even for overrides.
76  
77 3 my $handlers = $app->renderer->handlers;
78 3 my $base_ep = $handlers->{ep};
79 12 ▶ $handlers->{ep} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
80 12 my ($renderer, $c, $output, $options) = @_;
81 {
82 12 ▶ my $table = $c->stash('table') || last;
Condition100%2/2
$c->stash('table') || (last)
l!l
84
MC/DC100%1/1
$c->stash('table') || (last)
$c->stash('table')
Truth table100%2/2
A
A= $c->stash('table')
Aresult
11
00
83 8 my $custom_template = "$table/$options->{template}";
84 8 ▶ my $custom_path = $renderer->template_path ({%$options,
Condition100%2/2
$renderer->template_path({%$options, 'template', $custom_template}) || (last)
l!l
26
MC/DC100%1/1
$renderer->template_path({%$options, 'template', $custom_template}) || (last)
$renderer->template_path({%$options, 'template', $custom_template})
Truth table100%2/2
A
A= $renderer->template_path({%$options, 'template', $custom_template})
Aresult
11
00
85 template=>$custom_template}) || last;
86 2 $options->{template} = $custom_template;
87 2 ▶ $log->debug("custom 'tables' template at $custom_path") if $ENV{TABLES_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TABLES_DEBUG"} 0 2 2
88 }
89 12 $base_ep->(@_)
90 3 };
91  
92 3 my $r = $app->routes;
93 3 ▶ $r->get('/' => sub{shift->redirect_to('tables')}) unless $conf->{nohome};
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"nohome"} 3 0 3
94  
95 3 my @crud_gets = (qw/view edit del nuke navigate/);
96 3 my @crud_posts = (qw/save/);
97 3 my $fmts = [format=>[qw/html json/]];
98  
99 3 for ($r->under('tables') ->to('auth#ok' )) {
100 3 for ($_->under() ->to('tables#ok' )) {
101 3 $_->get ->to('#page' );
102 3 for ($_->under(':table') ->to('#table_ok' )) {
103 3 $_->any('/'=>$fmts) ->to('#table', format=>'html' );
104 3 $_->get('add') ->to('#add' );
105 3 $_->post('save') ->to('#save' );
106 3 for ($_->under(':id') ->to('#id_ok' )) {
107 3 my $r = $_;
108 3 $r->get( $_=>$fmts) ->to("#$_", format=>'html') for @crud_gets;
109 3 $r->post($_=>$fmts) ->to("#$_", format=>'html') for @crud_posts;
110 3 $r->get('add_child/:child'=>$fmts)->to('#view', format=>'html' );
111 3 $r->any(':children'=>$fmts) ->to('#children', format=>'html' );
112 }
113 }
114 }
115 }
116  
117 3 my @tablist = @{$model->{tablist}};
118 3 $log->info ("'Tables' Framework enabled.");
119 3 $log->debug("Route namespaces are..");
120 3 $log->debug("--> $_") for @{$app->routes->namespaces};
121 3 $log->debug("Renderer paths are..");
122 3 $log->debug("--> $_") for @{$app->renderer->paths};
123 3 $log->debug("Static paths are..");
124 3 $log->debug("--> $_") for @{$app->static->paths};
125 3 $log->info ("/tables routes are in place. ".scalar(@tablist)." tables available");
126 3 $log->debug("--> $_") for @tablist;
127  
128 3 ▶ $log->debug($app->dumper($model)) if $ENV{TABLES_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TABLES_DEBUG"} 0 3 3
129  
130 }
131  
132 3 1;
133 __END__
« Tables/Controller/Tables.pm ↑ Summary Tables/Model.pm »