lib/MojoMojo/Formatter/Redirect.pm

filter: Statementstmt 91.6% 11 / 12 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 71.4% 20 / 28 CC 5 SCAR 15.7
CC
5
Cov
71%
format_content
6.3
BEGIN
1.0
format_content_order
1.0
CRAP 4.8
« lib/MojoMojo/Formatter/File.pm ↑ Summary lib/MojoMojo/Schema.pm »
1 package MojoMojo::Formatter::Redirect;
2  
3 27 ▶use parent qw/MojoMojo::Formatter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 MojoMojo::Formatter::Redirect - Handles {{redirect /path}}
8  
9 =head1 DESCRIPTION
10  
11 Redirect to another page. Useful if your URL changes and
12 you want to make sure bookmarked URLs will still work:
13 C</help/tutrial> could contain:
14 C<{{redirect /help/tutorial}}>
15  
16 To edit a page that redirects, surf to $page_URL . '.edit'
17 See also http://mojomojo.ideascale.com/akira/dtd/6415-2416
18  
19 =head1 METHODS
20  
21 =head2 format_content_order
22  
23 Format order can be 1-99. The Redirect formatter runs first.
24  
25 =cut
26  
27 496 ▶sub format_content_order { 1 }
Subroutine format_content_order: called CC=1 SCAR=0.0
Pod documented
28  
29 =head2 format_content
30  
31 Calls the formatter. Takes a ref to the content as well as the
32 context object.
33  
34 =cut
35  
36 126 ▶sub format_content {
Subroutine format_content: called CC=5 SCAR=18.4
Pod documented
37 126 my ( $class, $content, $c ) = @_;
38 126 ▶ if ( my ($page) = $$content =~ m/
Branch: 1 branch
BranchTrueFalseTotal
if (my($page) = $$content =~ / \{\{ \s*redirect\s+ (\S+) \s*}}/x) 2 124 126
39 \{\{
40 \s*redirect\s+
41 (\S+)
42 \s*}}/x
43 ) {
44 2 ▶ if ($c->action->name eq 'view' && !$c->ajax) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->action->name eq 'view' and not $c->ajax) { } 2 0 2
elsif ($c->action->name eq 'render') { } 0 0 0
Condition33%1/3
$c->action->name eq "view" and not $c->ajax
!ll&&!rl&&r
002
MC/DC0%0/2
$c->action->name eq "view" and not $c->ajax
$c->action->name eq "view" not $c->ajax
Truth table33%1/3
A and not(B)
A= $c->action->name eq "view"B= not $c->ajax
ABresult
0X0
100
111
45 2 $c->flash->{'redirect'}=$c->stash->{'path'};;
46 2 $c->res->redirect( $c->uri_for($page) );
47 } elsif ($c->action->name eq 'render') {
48 0 $$content=$c->loc("redirect to")." ".$page;
49 }
50 # We don't want to precompile a redirected page so turn it off
51 2 $c->stash->{precompile_off} = 1;
52 }
53
54  
55 }
56  
57 =head1 SEE ALSO
58  
59 L<MojoMojo>, L<Module::Pluggable::Ordered>, L<URI::Fetch>
60  
61 =head1 AUTHORS
62  
63 Marcus Ramberg <mramberg@cpan.org>
64  
65 =head1 LICENSE
66  
67 This library is free software. You can redistribute it and/or modify
68 it under the same terms as Perl itself.
69  
70 =cut
71  
72 27 1;
« lib/MojoMojo/Formatter/File.pm ↑ Summary lib/MojoMojo/Schema.pm »