lib/MojoMojo/Controller/Root.pm

filter: Statementstmt 74.6% 56 / 75 Branchbran 50.0% 16 / 32 Conditioncond 70.0% 14 / 20 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 86.6% 13 / 15 Podpod 100% 6 / 6 totaltotal 67.9% 108 / 159 CC 24 SCAR 25.6
CC
24
Cov
68%
auto
28.8
begin
7.8
exit
6.0
CRAP 13.0
« lib/MojoMojo/Controller/Image.pm ↑ Summary lib/MojoMojo/Formatter/IRCLog.pm »
1 package MojoMojo::Controller::Root;
2  
3 35 ▶use parent 'Catalyst::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 35 __PACKAGE__->config->{namespace} = '';
6  
7 =head1 NAME
8  
9 MojoMojo::Controller::Root - Controller to run before all others
10  
11 =head1 ACTIONS
12  
13 =head2 begin (builtin)
14  
15 TODO
16  
17 =cut
18  
19 194 ▶sub begin : Private {
Subroutine begin: called CC=7 SCAR=20.5
20 194 my ( $self, $c ) = @_;
21 194 ▶ if($c->sessionid && $c->session->{lang}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->sessionid and $c->session->{'lang'}) { } 0 194 194
Condition66%2/3
$c->sessionid and $c->session->{"lang"}
!ll&&!rl&&r
119750
MC/DC0%0/2
$c->sessionid and $c->session->{"lang"}
$c->sessionid $c->session->{"lang"}
Truth table66%2/3
A and B
A= $c->sessionidB= $c->session->{"lang"}
ABresult
0X0
100
111
22 0 $c->languages([$c->session->{lang}]);
23 }
24 else {
25 194 ▶ $c->languages([$c->pref('default_lang')]) if $c->pref('default_lang');
Branch: 1 branch
BranchTrueFalseTotal
if $c->pref("default_lang") 194 0 194
26 }
27 # $c->stash->{path} is set by MojoMojo::prepare_path, which overrides the built-in Catalyst method
28 194 ▶ if ( $c->stash->{path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash->{"path"}) 194 0 194
29 my ( $path_pages, $proto_pages ) =
30 194 $c->model('DBIC::Page')->path_pages( $c->stash->{path} );
31 194 @{ $c->stash }{qw/ path_pages proto_pages /} = ( $path_pages, $proto_pages );
32 194 $c->stash->{page} = $path_pages->[ @$path_pages - 1 ];
33 194 ▶ $c->stash->{user} = $c->user->obj() if $c->user_exists && $c->user;
Branch: 1 branch
BranchTrueFalseTotal
if $c->user_exists and $c->user 51 143 194
Condition66%2/3
$c->user_exists and $c->user
!ll&&!rl&&r
143051
MC/DC50%1/2
$c->user_exists and $c->user
$c->user_exists $c->user
Truth table66%2/3
A and B
A= $c->user_existsB= $c->user
ABresult
0X0
100
111
34 }
35 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 =head2 default (global)
38  
39 Default action - display the error page (message.tt), for example when a
40 nonexistent action was requested (like C</parent_page/child_page.fireworks>).
41  
42 =cut
43  
44 1 ▶sub default : Path {
Subroutine default: called CC=1 SCAR=0.0
Pod documented
45 1 my ( $self, $c ) = @_;
46 1 $c->res->status(404);
47 $c->stash->{message} = $c->loc(
48 'The requested URL was not found: x',
49 1 '<span class="error_detail">' . $c->stash->{pre_hacked_uri} . '</span>'
50 );
51 1 $c->stash->{template} = 'message.tt';
52 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 =head2 set_lang
55  
56 (Re)set language of current session.
57  
58 =cut
59  
60 0 ▶sub set_lang :Global {
Subroutine set_lang: not called CC=1 SCAR=6.9
Pod documented
61 0 my ($self,$c) = @_;
62 0 $c->session->{lang}=$c->req->params->{lang};
63 0 $c->res->redirect( $c->uri_for( $c->stash->{path} ) );
64 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 =head2 render
67  
68 Finally, use ActionClass RenderView to render the content.
69  
70 =cut
71  
72 194 ▶sub render : ActionClass('RenderView') {
Subroutine render: called CC=2 SCAR=7.1
Pod documented
73 194 my ($self) = shift;
74 194 my ($c) = @_;
75 194 ▶ $c->stash->{path} ||= '/';
Condition50%1/2
$c->stash->{"path"} ||= "/"
l!l
1940
MC/DC0%0/1
$c->stash->{"path"} ||= "/"
$c->stash->{"path"}
Truth table50%1/2
A
A= $c->stash->{"path"}
Aresult
11
00
76 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 =head2 end (builtin)
79  
80 At the end of any request, forward to view unless there is a template
81 or response, then render the template. If param 'die' is passed,
82 show a debug screen.
83  
84 =cut
85  
86 194 ▶sub end : Private {
Subroutine end: called CC=3 SCAR=12.0
Pod documented
87 194 my ( $self, $c ) = @_;
88  
89 194 my $theme=$c->pref('theme');
90 # if theme doesn't exist
91 194 ▶ if ( ! -d $c->path_to('root','static','themes',$theme)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $c->path_to("root", "static", "themes", $theme)) 0 194 194
92 0 $theme='default';
93 0 $c->pref('theme',$theme);
94 }
95 $c->stash->{additional_template_paths} =
96 194 [ $c->path_to('root','themes',$theme) ];
97  
98 $c->req->uri->path( $c->stash->{pre_hacked_uri}->path )
99 194 ▶ if ref $c->stash->{pre_hacked_uri};
Branch: 1 branch
BranchTrueFalseTotal
if ref $c->stash->{"pre_hacked_uri"} 194 0 194
100 194 $c->forward('render');
101 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 =head2 auto
104  
105 Runs for all requests, checks if user is in need of validation, and
106 intercepts the request if so. Also, if the requested page doesn't exist,
107 prevents any other actions from running, and detaches straight to
108 L<MojoMojo::Controller::Page/suggest>.
109  
110 =cut
111  
112 194 ▶sub auto : Private {
Subroutine auto: called CC=14 SCAR=33.6
Pod documented
113 194 my ( $self, $c ) = @_;
114
115 # Prevent most actions from running on non-existent pages. This fixes issues #36 and #80.
116 # 'render' should be allowed so that jsrpc/render can be used to preview newly created pages while the first version is being typed in
117 194 my $proto_pages = $c->stash->{proto_pages};
118 194 ▶ return 1 if $c->action->class =~ m/^MojoMojo::Extensions::/;
Branch: 1 branch
BranchTrueFalseTotal
if $c->action->class =~ /^MojoMojo::Extensions::/ 12 182 194
119 182 ▶ return $c->res->body('Page does not exist.')
Branch: 1 branch
BranchTrueFalseTotal
if $proto_pages and @$proto_pages and $c->action->name eq "inline" 0 182 182
Condition66%4/6
$proto_pages and @$proto_pages and $c->action->name eq "inline"
!ll&&!rl&&r
172100
$proto_pages and @$proto_pages
!ll&&!rl&&r
017210
MC/DC0%0/3
$proto_pages and @$proto_pages and $c->action->name eq "inline"
$proto_pages @$proto_pages $c->action->name eq "inline"
Truth table50%2/4
A and B and C
A= $proto_pagesB= @$proto_pagesC= $c->action->name eq "inline"
ABCresult
0XX0
10X0
1100
1111
120 if ($proto_pages && @$proto_pages && $c->action->name eq 'inline');
121 182 ▶ $c->detach('MojoMojo::Controller::Page', 'suggest')
Branch: 1 branch
BranchTrueFalseTotal
if $proto_pages and @$proto_pages and not $c->action->name =~ /^(edit|render|login|logout|register|recover_pass)$/ 1 181 182
Condition83%5/6
$proto_pages and @$proto_pages and not $c->action->name =~ /^(edit|render|login|logout|register|recover_pass)$/
!ll&&!rl&&r
17291
$proto_pages and @$proto_pages
!ll&&!rl&&r
017210
MC/DC66%2/3
$proto_pages and @$proto_pages and not $c->action->name =~ /^(edit|render|login|logout|register|recover_pass)$/
$proto_pages @$proto_pages not $c->action->name =~ /^(edit|render|login|logout|register|recover_pass)$/
Truth table75%3/4
A and B and not(C)
A= $proto_pagesB= @$proto_pagesC= not $c->action->name =~ /^(edit|render|login|logout|register|recover_pass)$/
ABCresult
0XX0
10X0
1100
1111
122 if ($proto_pages && @$proto_pages && $c->action->name !~ /^(edit|render|login|logout|register|recover_pass)$/);
123  
124 181 ▶ if ( $c->pref('enforce_login') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->pref("enforce_login")) 0 181 181
125 # allow a few actions
126 0 ▶ if ( grep $c->action->name eq $_, qw/login logout recover_pass register/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep(($c->action->name eq $_), ("login", "logout", "recover_pass", "register"))) 0 0 0
127 0 return 1;
128 }
129 0 ▶ if ( !$c->user_exists ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->user_exists) 0 0 0
130 $c->res->redirect(
131 $c->uri_for(
132 0 $c->stash->{path} . '.login' # send them to the login for this page
133 )
134 );
135 }
136 }
137  
138 181 ▶ return 1 unless $c->stash->{user};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->stash->{"user"} 130 51 181
139 51 ▶ return 1 if $c->stash->{user}->active != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $c->stash->{"user"}->active != -1 51 0 51
140 0 ▶ return 1 if $c->req->action eq 'logout';
Branch: 1 branch
BranchTrueFalseTotal
if $c->req->action eq "logout" 0 0 0
141 0 $c->stash->{template} = 'user/validate.tt';
142 0 return 0;
143 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
144  
145 =head2 exit
146  
147 A way to exit from MojoMojo. Useful when testing leaks.
148  
149 =cut
150  
151 0 ▶sub exit : Local {
Subroutine exit: not called CC=2 SCAR=17.9
Pod documented
152 0 my ($self, $c) = @_;
153 0 ▶ if ($ENV{MOJOMOJO_EXIT_OK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'MOJOMOJO_EXIT_OK'}) { } 0 0 0
154 0 exit(0);
155 }
156 else {
157 # $c->stash( template => 'error.tt' );
158 0 $c->res->status (403); # forbidden
159 0 $c->res->body('EXIT NOT OK');
160 0 $c->detach();
161 }
162 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
163  
164  
165 =head1 AUTHOR
166  
167 Marcus Ramberg <mramberg@cpan.org>
168  
169 =head1 LICENSE
170  
171 This library is free software. You can redistribute it and/or modify
172 it under the same terms as Perl itself.
173  
174 =cut
175  
176 35 1;
« lib/MojoMojo/Controller/Image.pm ↑ Summary lib/MojoMojo/Formatter/IRCLog.pm »