Galileo/Page.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 8 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 91.2% 52 / 57 CC 6 SCAR 8.8
CC
6
Cov
98%
edit
3.0
show
3.0
__ANON__
2.0
CRAP 2.4
« Galileo/Menu.pm ↑ Summary Galileo/DB/Deploy.pm »
1 package Galileo::Page;
2 3 ▶use Mojo::Base 'Mojolicious::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 18 ▶sub show {
Subroutine show: called CC=3 SCAR=11.0
Pod undocumented
5 18 my $self = shift;
6 18 my $name = $self->param('name');
7  
8 18 my $page = $self->schema->resultset('Page')->single({ name => $name });
9 18 ▶ if ($page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page) { } 14 4 18
10 14 $self->render( page => $page );
11 } else {
12 4 ▶ if ( $self->is_author ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_author) { } 2 2 4
13 2 $self->redirect_to(edit_page => name => $name);
14 } else {
15 2 $self->reply->not_found;
16 }
17 }
18 }
19  
20 3 ▶sub edit {
Subroutine edit: called CC=3 SCAR=11.0
Pod undocumented
21 3 my $self = shift;
22 3 my $name = $self->param('name');
23 3 $self->title( "Editing Page: $name" );
24 3 $self->content_for( banner => "Editing Page: $name" );
25  
26 3 my $schema = $self->schema;
27  
28 3 my $page = $schema->resultset('Page')->single({name => $name});
29 3 ▶ if ($page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page) { } 1 2 3
30 1 my $title = $page->title;
31 1 $self->stash( title_value => $title );
32 1 $self->stash( input => $page->md );
33 } else {
34 2 $self->stash( title_value => '' );
35 2 $self->stash( input => "Hello World" );
36 }
37  
38 $self->stash(
39 sanitize => $self->config->{sanitize} // 1, #/# highlight fix
40 pagedown_extra_options => $self->config->{pagedown_extra_options},
41 3 ▶ );
Condition50%1/2
$self->config->{"sanitize"} // 1
l!l
30
MC/DC0%0/1
$self->config->{"sanitize"} // 1
$self->config->{"sanitize"}
Truth table50%1/2
A
A= $self->config->{"sanitize"}
Aresult
11
00
42  
43 3 $self->render;
44 }
45  
46 4 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod undocumented
47 4 my $self = shift;
48 4 ▶ $self->on( json => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
49 4 my ($self, $data) = @_;
50  
51 4 my $schema = $self->schema;
52  
53 4 ▶ unless ( $data->{title} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data->{"title"}) 1 3 4
54 1 $self->send({ json => {
55 message => 'Not saved! A title is required!',
56 success => \0,
57 } });
58 1 return;
59 }
60  
61 3 my $author = $schema->resultset('User')->single({name=>$self->session->{username}});
62 3 $data->{author_id} = $author->id;
63 3 $schema->resultset('Page')->update_or_create(
64 $data, {key => 'pages_name'},
65 );
66 3 $self->memorize->expire('main');
67 3 $self->send({ json => {
68 message => 'Changes saved',
69 success => \1,
70 } });
71 4 });
72 }
73  
74 3 1;
75  
« Galileo/Menu.pm ↑ Summary Galileo/DB/Deploy.pm »