lib/MojoMojo/Controller/Page.pm

filter: Statementstmt 80.0% 208 / 260 Branchbran 39.6% 23 / 58 Conditioncond 51.8% 14 / 27 MC/DCmcdc 33.3% 5 / 15 Subroutinesub 97.5% 40 / 41 Podpod 100% 16 / 16 totaltotal 73.3% 306 / 417 CC 43 SCAR 33.9
CC
43
Cov
71%
search
118.9
subtree
20.0
view
12.4
CRAP 29.7
« lib/MojoMojo/Schema/Result/Content.pm ↑ Summary lib/MojoMojo/Controller/User.pm »
1 package MojoMojo::Controller::Page;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use parent 'Catalyst::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use IO::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use Text::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use HTML::Strip;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use Data::Page;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 MojoMojo::Controller::Page - Page controller
15  
16 =head1 SYNOPSIS
17  
18 =head1 DESCRIPTION
19  
20 This controller is the main juice of MojoMojo. It handles all the
21 actions related to wiki pages. Actions are redispatched to this
22 controller based on MojoMojo's custom prepare_path method.
23  
24 Every private action here expects to have a page path in args. They
25 can be called with urls like "/page1/page2.action".
26  
27 =head1 ACTIONS
28  
29 =head2 view (.view)
30  
31 This is probably the most common action in MojoMojo. A lot of the
32 other actions redispatch to this one. It will prepare the stash
33 for page view, and set the template to C<view.tt>, unless another is
34 already set.
35  
36 It also takes an optional 'rev' parameter, in which case it will
37 load the provided revision instead.
38  
39 =cut
40  
41 28 ▶sub view : Global {
Subroutine view: called CC=12 SCAR=25.2
42 28 my ( $self, $c, $path ) = @_;
43  
44 28 my $stash = $c->stash;
45 28 ▶ $stash->{template} ||= 'page/view.tt';
Condition100%2/2
$stash->{"template"} ||= "page/view.tt"
l!l
226
MC/DC100%1/1
$stash->{"template"} ||= "page/view.tt"
$stash->{"template"}
Truth table100%2/2
A
A= $stash->{"template"}
Aresult
11
00
46  
47 28 $c->forward('inline_tags');
48  
49 # FIXME NOTE: Highlight has been turned off until someone makes it work perfectly in all cases.
50 # In particular it sucks with TOC and valid HTML
51 # $c->stash->{render} = 'highlight'
52 # if $c->req->referer && $c->req->referer =~ /.edit$/;
53  
54 my ( $path_pages, $proto_pages, $id ) =
55 28 @$stash{qw/ path_pages proto_pages id /};
56  
57 # we should always have at least "/" in path pages. if we don't,
58 # we must not have had these structures in the stash
59  
60 28 ▶ return $c->forward('suggest')
Branch: 1 branch
BranchTrueFalseTotal
if $proto_pages and @$proto_pages 0 28 28
Condition33%1/3
$proto_pages and @$proto_pages
!ll&&!rl&&r
0280
MC/DC0%0/2
$proto_pages and @$proto_pages
$proto_pages @$proto_pages
Truth table33%1/3
A and B
A= $proto_pagesB= @$proto_pages
ABresult
0X0
100
111
61 if $proto_pages && @$proto_pages;
62  
63 28 my $page = $stash->{page};
64  
65 28 ▶ return unless $c->check_view_permission;
Branch: 1 branch
BranchTrueFalseTotal
unless $c->check_view_permission 0 28 28
66  
67 28 my $content;
68  
69 28 my $rev = $c->req->params->{rev};
70 28 ▶ if ( $rev && defined $page->content_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev and defined $page->content_version) { } 2 26 28
Condition66%2/3
$rev and defined $page->content_version
!ll&&!rl&&r
2602
MC/DC50%1/2
$rev and defined $page->content_version
$rev defined $page->content_version
Truth table66%2/3
A and B
A= $revB= defined $page->content_version
ABresult
0X0
100
111
71 2 $content = $c->model("DBIC::Content")->find(
72 {
73 page => $page->id,
74 version => $rev
75 }
76 );
77 2 ▶ $stash->{rev} = ( defined $content ? $content->version : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $content ? : 1 1 2
78 2 ▶ unless ( $stash->{rev} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stash->{"rev"}) 1 1 2
79 1 $stash->{message} = $c->loc(
80 'No revision x for x',
81 $rev,
82 '<span class="error_detail">'
83 . '<a href="'
84 . $page->path . '">'
85 . $page->name . '</a>'
86 . '</span>'
87 );
88 1 $stash->{template} = 'message.tt';
89 }
90 }
91 else {
92 26 $content = $page->content;
93 26 ▶ unless ($content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content) 0 26 26
94 0 $c->detach('/pageadmin/edit');
95  
96 }
97 26 $stash->{rev} = $content->version;
98 }
99  
100 # cache a precompiled version when missing
101 28 ▶ if ( $content && not defined $content->precompiled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content and not defined $content->precompiled) 1 27 28
Condition100%3/3
$content and not defined $content->precompiled
!ll&&!rl&&r
1261
MC/DC100%2/2
$content and not defined $content->precompiled
$content not defined $content->precompiled
Truth table100%3/3
A and not(B)
A= $contentB= not defined $content->precompiled
ABresult
0X0
100
111
102 1 my $precomp_body = $content->body;
103 1 MojoMojo->call_plugins( 'format_content', \$precomp_body, $c, $page );
104 1 $content->precompiled( $precomp_body );
105 1 $content->update;
106 }
107  
108 28 $stash->{content} = $content;
109 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 =head2 search (.search)
112  
113 This action is called as C<.search> on the current page when the user
114 performs a search. The user can choose to search the entire site or a
115 subtree starting from the current page.
116  
117 =cut
118  
119 3 ▶sub search : Global {
Subroutine search: called CC=18 SCAR=47.8
Pod documented
120 3 my ( $self, $c ) = @_;
121  
122 3 my $stash = $c->stash;
123  
124 # number of search results to show per page
125 3 my $results_per_page = 10;
126  
127 3 my $page = $c->stash->{page};
128  
129 # $q represents the search query
130 3 ▶ my $q = $c->req->params->{q} || $c->stash->{query} || q();
Condition40%2/5
$c->req->params->{'q'} || $c->stash->{'query'} || ''
l!l
03
$c->req->params->{"q"} or $c->stash->{"query"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$c->req->params->{'q'} || $c->stash->{'query'} || ''
$c->req->params->{"q"} $c->stash->{"query"}
Truth table33%1/3
A or B
A= $c->req->params->{"q"}B= $c->stash->{"query"}
ABresult
1X1
011
000
131 3 ▶ my $search_type = $c->req->params->{search_type} || "subtree";
Condition50%1/2
$c->req->params->{'search_type'} || 'subtree'
l!l
03
MC/DC0%0/1
$c->req->params->{'search_type'} || 'subtree'
$c->req->params->{'search_type'}
Truth table50%1/2
A
A= $c->req->params->{'search_type'}
Aresult
11
00
132 3 $stash->{query} = $q;
133 3 $stash->{search_type} = $search_type;
134  
135 3 my $strip = HTML::Strip->new;
136  
137 3 my $results = [];
138  
139 # For subtree searches, we'll use the (modified) page path to restrict the search hits.
140 3 my $fixed_path;
141 3 ▶ if ( $search_type eq "subtree" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search_type eq "subtree") 3 0 3
142 3 $fixed_path = $page->path;
143  
144 # Replace slashes with X so fixed path format matches hit path format.
145 3 $fixed_path =~ s{/}{X}g;
146 }
147  
148 3 my $hits = $c->model('Search')->search($q);
149 3 my %results_hash;
150 3 ▶ while ( my $hit = $hits->fetch_hit_hashref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $hits->fetch_hit_hashref) 0 3 3
151  
152 # Filter out hits that aren't part of subtree
153 0 ▶ if ( $search_type eq 'subtree' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search_type eq "subtree") 0 0 0
154 0 ▶ next if $hit->{path} !~ m/$fixed_path/mx;
Branch: 1 branch
BranchTrueFalseTotal
unless $hit->{"path"} =~ /$fixed_path/mx 0 0 0
155 }
156 0 $hit->{path} =~ s{X}{/}g;
157 0 my ($path_pages) = $c->model('DBIC::Page')->path_pages( $hit->{path} );
158 0 my $page = $path_pages->[ @$path_pages - 1 ];
159  
160 # skip search result depending on permissions
161 0 my $user;
162 0 ▶ if ( $c->pref('check_permission_on_view') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->pref("check_permission_on_view")) 0 0 0
163 0 ▶ if ( $c->user_exists() ) { $user = $c->user->obj; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c->user_exists) 0 0 0
164 0 my $perms = $c->check_permissions( $page->path, $user );
165 0 ▶ next unless $perms->{view};
Branch: 1 branch
BranchTrueFalseTotal
unless $perms->{"view"} 0 0 0
166 }
167  
168 # add a snippet of text containing the search query
169 0 ▶ my $content = $strip->parse( $page->content->precompiled || $page->content->formatted($c) );
Condition0%0/3
$page->content->precompiled || $page->content->formatted($c)
l!l&&r!l&&!r
000
MC/DC0%0/2
$page->content->precompiled || $page->content->formatted($c)
$page->content->precompiled $page->content->formatted($c)
Truth table0%0/3
A || B
A= $page->content->precompiledB= $page->content->formatted($c)
ABresult
1X1
011
000
170 0 $strip->eof;
171  
172 # FIXME: Bug? Some snippet text doesn't get displayed properly by Text::Context
173 0 my $snippet = Text::Context->new( $content, split( / /, $q ) );
174  
175 # Store goods to be used in search results listing
176 # NOTE: $page->path is '/' for app root,
177 # but $c->request->path is empty for app root.
178 0 my $title_base_nodes;
179 0 ▶ if ( $page->path ne '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page->path ne "/") 0 0 0
180 0 ($title_base_nodes) = $page->path =~ m{(.*/).*$};
181 0 $title_base_nodes =~ s{^/}{};
182 0 $title_base_nodes =~ s{/}{ > }g;
183 }
184 $results_hash{ $hit->{path} } = {
185 snippet => $snippet->as_html,
186 page => $page,
187 score => $hit->{score},
188 0 title_base_nodes => $title_base_nodes,
189 };
190  
191 }
192  
193 # Order hits by score.
194 3 my @results;
195 3 foreach my $hit_path (
196 0 sort { $results_hash{$b}->{score} <=> $results_hash{$a}->{score} }
197 keys %results_hash
198 )
199 {
200 0 push @results, $results_hash{$hit_path};
201 }
202 3 $results = \@results;
203 3 my $result_count = scalar @$results;
204 3 ▶ if ($result_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_count) 0 3 3
205  
206 # Paginate the results.
207 # This is done even with 1 page of results so the template doesn't need
208 # to do two separate things.
209 0 my $pager = Data::Page->new;
210 0 $pager->total_entries($result_count);
211 0 $pager->entries_per_page($results_per_page);
212 0 ▶ $pager->current_page( $c->req->params->{p} || 1 );
Condition0%0/2
$c->req->params->{'p'} || 1
l!l
00
MC/DC0%0/1
$c->req->params->{'p'} || 1
$c->req->params->{'p'}
Truth table0%0/2
A
A= $c->req->params->{'p'}
Aresult
11
00
213  
214 0 ▶ if ( $result_count > $results_per_page ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_count > $results_per_page) 0 0 0
215  
216 # trim down the results to just this page
217 0 @$results = $pager->splice($results);
218 }
219  
220 0 $c->stash->{pager} = $pager;
221 0 ▶ my $last_page = ( $pager->last_page > 10 ) ? 10 : $pager->last_page;
Branch: 1 branch
BranchTrueFalseTotal
$pager->last_page > 10 ? : 0 0 0
222 0 $c->stash->{pages_to_link} = [ 1 .. $last_page ];
223 0 $c->stash->{results} = $results;
224 0 $c->stash->{result_count} = $result_count;
225 }
226 3 $stash->{template} = 'page/search.tt';
227 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
228  
229 =head2 print
230  
231 This action is the same as the L</view> action, but with a printer-friendly
232 template.
233  
234 =cut
235  
236 1 ▶sub print : Global {
Subroutine print: called CC=1 SCAR=0.0
Pod documented
237 1 my ( $self, $c, $page ) = @_;
238 1 $c->stash->{template} = 'page/print.tt';
239 1 $c->forward('view');
240 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
241  
242 =head2 inline
243  
244 Same as L</view> action, but with a template that only outputs the barebones
245 body of the page. There are no headers, footers, or navigation bars. Useful
246 for transclusion (see L<MojoMojo::Formatter::Include>).
247  
248 =cut
249  
250 1 ▶sub inline : Global {
Subroutine inline: called CC=1 SCAR=0.0
Pod documented
251 1 my ( $self, $c, $page ) = @_;
252 1 $c->stash->{template} = 'page/inline.tt';
253 1 $c->forward('view');
254 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
255  
256 =head2 inline_tags (.inline_tags)
257  
258 Tag list for the bottom of page views.
259  
260 =cut
261  
262 35 ▶sub inline_tags : Global {
Subroutine inline_tags: called CC=3 SCAR=11.0
Pod documented
263 35 my ( $self, $c, $highlight ) = @_;
264 35 ▶ $c->stash->{template} ||= 'page/tags.tt';
Condition100%2/2
$c->stash->{"template"} ||= "page/tags.tt"
l!l
287
MC/DC100%1/1
$c->stash->{"template"} ||= "page/tags.tt"
$c->stash->{"template"}
Truth table100%2/2
A
A= $c->stash->{"template"}
Aresult
11
00
265 35 $c->stash->{highlight} = $highlight;
266 35 my $page = $c->stash->{page};
267 35 ▶ if ( $c->user_exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->user_exists) { } 13 22 35
268 13 my @tags = $page->others_tags( $c->user->obj->id );
269 13 $c->stash->{others_tags} = [@tags];
270 13 @tags = $page->user_tags( $c->user->obj->id );
271 13 $c->stash->{taglist} = ' ' . join( ' ', map { $_->tag } @tags ) . ' ';
272 13 $c->stash->{tags} = [@tags];
273 }
274 else {
275 22 $c->stash->{others_tags} = [ $page->tags_with_counts ];
276 }
277 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
278  
279 =head2 pages_viewable($c, $user, @pages)
280  
281 Filters an array of pages, returning only those that the given user has
282 permission to view.
283  
284 =cut
285  
286 6 ▶sub pages_viewable {
Subroutine pages_viewable: called CC=1 SCAR=0.0
Pod documented
287 6 my ( $c, $user, @pages ) = @_;
288 6 return grep { $c->check_permissions( $_->path, $user )->{view}; } @pages;
289 }
290  
291 =head2 list (.list)
292  
293 All nodes in this namespace. Computes tags, all pages, backlinks, wanted and
294 orphan pages.
295  
296 =cut
297  
298 1 ▶sub list : Global {
Subroutine list: called CC=5 SCAR=16.5
Pod documented
299 1 my ( $self, $c, $tag ) = @_;
300 1 my $page = $c->stash->{page};
301 1 ▶ my $resultset_page_number = $c->req->param('page') || 1;
Condition50%1/2
$c->req->param('page') || 1
l!l
01
MC/DC0%0/1
$c->req->param('page') || 1
$c->req->param('page')
Truth table50%1/2
A
A= $c->req->param('page')
Aresult
11
00
302
303 1 $c->stash->{tags} = $c->model("DBIC::Tag")->most_used();
304 1 ▶ $c->detach('/tag/list') if $tag;
Branch: 1 branch
BranchTrueFalseTotal
if $tag 0 1 1
305 1 $c->stash->{template} = 'page/list.tt';
306  
307 1 my $rs = $page->descendants($resultset_page_number);
308 1 $c->stash->{pager} = $rs->pager;
309 1 my @all_pages_viewable = $rs->all;
310
311
312 1 my @backlinks_viewable =
313 $c->model("DBIC::Link")->search( {to_page => $page->id} );
314 1 ▶ if ( $c->pref('check_permission_on_view') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->pref("check_permission_on_view")) 1 0 1
315 1 my $user;
316 0 ▶ if ( $c->user_exists() ) { $user = $c->user->obj; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c->user_exists) 0 1 1
317 1 @all_pages_viewable = pages_viewable( $c, $user, @all_pages_viewable );
318 @backlinks_viewable = grep {
319  
320 # does the user have permission to view the page from which ours is linked?
321 0 $c->check_permissions( $_->from_page->path, $user )->{view};
322 } @backlinks_viewable;
323 }
324 1 $c->stash->{pages} = \@all_pages_viewable;
325 1 $c->stash->{backlinks} = \@backlinks_viewable;
326  
327 1 $c->stash->{orphans} = []; # FIXME - real data here please
328  
329 # no need to check any permissions here because the user already
330 # views this page, and wanted pages are redlinks in it
331 $c->stash->{wanted} = [
332 $c->model("DBIC::WantedPage")->search(
333 1 { from_page => [ $page->id, map { $_->id } @all_pages_viewable ] }
334 )
335 ];
336 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
337  
338 =head2 subtree (.subtree)
339  
340 Display all pages that are part of the subtree for the current node.
341  
342 =cut
343  
344 0 ▶sub subtree : Global {
Subroutine subtree: not called CC=4 SCAR=30.0
Pod documented
345 0 my ( $self, $c ) = @_;
346
347 0 my $page = $c->stash->{page};
348 0 my @all_pages_viewable = sort { $a->{path} cmp $b->{path} } $page->descendants;
349 0 ▶ if ( $c->pref('check_permission_on_view') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->pref("check_permission_on_view")) 0 0 0
350 0 my $user;
351 0 ▶ if ( $c->user_exists() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->user_exists) { } 0 0 0
352 0 $user = $c->user->obj;
353 } else {
354 # if anonymous user is allowed
355 0 my $anonymous = $c->pref('anonymous_user');
356 0 ▶ if ($anonymous) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anonymous) 0 0 0
357 # get anonymous user for no logged-in users
358 0 $user = $c->model('DBIC::Person') ->search( {login => $anonymous} )->first;
359 }
360 }
361 0 @all_pages_viewable = pages_viewable( $c, $user, @all_pages_viewable );
362 }
363 0 $c->stash->{pages} = \@all_pages_viewable;
364 0 $c->stash->{template} = 'page/subtree.tt';
365 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
366  
367  
368 =head2 recent (.recent)
369  
370 Recently changed pages in this namespace. Also computes the most used
371 tags.
372  
373 =cut
374  
375 5 ▶sub recent : Global {
Subroutine recent: called CC=4 SCAR=14.3
Pod documented
376 5 my ( $self, $c, $tag ) = @_;
377 5 ▶ $c->detach( '/tag/recent', [$tag] ) if $tag;
Branch: 1 branch
BranchTrueFalseTotal
if $tag 0 5 5
378 5 $c->stash->{tags} = $c->model("DBIC::Tag")->most_used;
379 5 my $page = $c->stash->{page};
380 5 $c->stash->{template} = 'page/recent.tt';
381  
382 5 my @pages_viewable = $page->descendants_by_date;
383 5 ▶ if ( $c->pref('check_permission_on_view') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->pref("check_permission_on_view")) 5 0 5
384 5 my $user;
385 0 ▶ if ( $c->user_exists() ) { $user = $c->user->obj; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c->user_exists) 0 5 5
386 5 @pages_viewable = pages_viewable( $c, $user, @pages_viewable );
387 }
388 5 $c->stash->{pages} = \@pages_viewable;
389 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
390  
391 =head2 feeds (.feeds)
392  
393 Overview of available feeds for this node.
394  
395 =cut
396  
397 2 ▶sub feeds : Global {
Subroutine feeds: called CC=1 SCAR=0.0
Pod documented
398 2 my ( $self, $c ) = @_;
399 2 $c->stash->{template} = 'feeds.tt';
400 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
401  
402 =head2 rss (.rss)
403  
404 RSS feed with headlines of recent nodes in this namespace.
405  
406 =cut
407  
408 1 ▶sub rss : Global {
Subroutine rss: called CC=1 SCAR=0.0
Pod documented
409 1 my ( $self, $c ) = @_;
410 1 $c->forward('recent');
411 1 $c->stash->{template} = 'page/rss.tt';
412 1 $c->res->content_type('application/rss+xml');
413 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
414  
415 =head2 atom (.atom)
416  
417 Full content ATOM feed of recent nodes in this namespace.
418  
419 =cut
420  
421 1 ▶sub atom : Global {
Subroutine atom: called CC=1 SCAR=0.0
Pod documented
422 1 my ( $self, $c ) = @_;
423 1 $c->forward('recent');
424 1 $c->res->content_type('application/atom+xml');
425 1 $c->stash->{template} = 'page/atom.tt';
426 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
427  
428 =head2 rss_full (.rss_full)
429  
430 Full content RSS feed of recent nodes in this namespace.
431  
432 =cut
433  
434 1 ▶sub rss_full : Global {
Subroutine rss_full: called CC=1 SCAR=0.0
Pod documented
435 1 my ( $self, $c ) = @_;
436 1 $c->forward('recent');
437 1 $c->res->content_type('application/rss+xml');
438 1 $c->stash->{template} = 'page/rss_full.tt';
439 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
440  
441 =head2 export (.export)
442  
443 Page showing available export options.
444  
445 =cut
446  
447 2 ▶sub export : Global {
Subroutine export: called CC=2 SCAR=7.4
Pod documented
448 2 my ( $self, $c ) = @_;
449 2 ▶ if ( !$c->user_exists() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->user_exists) 2 0 2
450 2 $c->stash->{message} = $c->loc('To export, you must be logged in.');
451 2 $c->detach('MojoMojo::Controller::PageAdmin', 'unauthorized');
452 }
453
454 0 $c->stash->{template} = 'export.tt';
455 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
456  
457 =head2 suggest (.suggest)
458  
459 "Page not found" page, suggesting alternatives, and allowing creation of the page.
460 Root::auto detaches here for actions on nonexistent pages (e.g. c<bogus.export>).
461  
462 =cut
463  
464 2 ▶sub suggest : Global {
Subroutine suggest: called CC=1 SCAR=0.0
Pod documented
465 2 my ( $self, $c ) = @_;
466 2 $c->stash->{template} = 'page/suggest.tt';
467 2 $c->res->status(404);
468 # force the Catalyst flow to jump straight to the most specific 'end' action, which is Root::end
469 2 return 0; # otherwise, when Root::auto detaches here, we'd call the original action (e.g. 'export') too
470 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
471  
472 =head2 search_inline (.search/inline)
473  
474 Search results embeddable in another page (for use with L</suggest>).
475  
476 =cut
477  
478 1 ▶sub search_inline : Path('/search/inline') {
Subroutine search_inline: called CC=1 SCAR=0.0
Pod documented
479 1 my ( $self, $c ) = @_;
480 1 $c->forward('search');
481 1 $c->stash->{template} = 'page/search_inline.tt';
482 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
483  
484 =head2 info (.info)
485  
486 Meta information about the current page: revision list, content size, number of
487 children and descendants, links to/from, attachments.
488  
489 =cut
490  
491 1 ▶sub info : Global {
Subroutine info: called CC=2 SCAR=6.9
Pod documented
492 1 my ( $self, $c ) = @_;
493 1 my $attachments_size = 0;
494 1 my $attachments_count = 0;
495 1 foreach my $attachment ( $c->stash->{page}->attachments ) {
496 1 $attachments_size+=$attachment->size;
497 1 $attachments_count++;
498 }
499 1 $c->stash->{attachments} = $attachments_count;
500 1 $c->stash->{attachments_size} = $attachments_size;
501 1 $c->stash->{body_length} = length( $c->stash->{page}->content->body );
502 1 $c->stash->{template} = 'page/info.tt';
503 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
504  
505 =head1 AUTHOR
506  
507 Marcus Ramberg <mramberg@cpan.org>
508  
509 =head1 LICENSE
510  
511 This library is free software. You can redistribute it and/or modify
512 it under the same terms as Perl itself.
513  
514 =cut
515  
516 35 1;
« lib/MojoMojo/Schema/Result/Content.pm ↑ Summary lib/MojoMojo/Controller/User.pm »