Jifty/Action/Redirect.pm

filter: Statementstmt 45.4% 10 / 22 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 43.2% 16 / 37 CC 4 SCAR 17.7
CC
4
Cov
36%
take_action
12.0
new
6.0
arguments
2.0
CRAP 5.9
« Jifty/Web/Session/ApacheSession.pm ↑ Summary Jifty/Plugin/Deflater.pm »
1 113 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 113 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Jifty::Action::Redirect - Redirect the browser
7  
8 =head1 SYNOPSIS
9  
10 Jifty->web->new_action(
11 class => 'Redirect',
12 arguments => {
13 url => '/my/other/page',
14 },
15 )->run;
16  
17 =head1 DESCRIPTION
18  
19 Given a URL, this action forces Jifty to perform a redirect to that URL after processing the rest of the request.
20  
21 =cut
22  
23 package Jifty::Action::Redirect;
24 113 ▶use base qw/Jifty::Action/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 =head1 METHODS
27  
28 =head2 new
29  
30 By default, redirect actions happen as late as possible in the run
31 order. Defaults the L<Jifty::Action/order> to be 100 so it runs later
32 than most actions.
33  
34 =cut
35  
36 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
37 0 my $class = shift;
38 0 my $self = $class->SUPER::new(@_);
39  
40 # XXX TODO This is wrong -- it should be -1 or some equivilent, so
41 # it is sorted last all the time.
42 0 ▶ $self->order(100) unless defined $self->order;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->order 0 0 0
43 0 return $self;
44 }
45  
46 =head2 arguments
47  
48 The only argument to redirect is the C<url> to redirect to.
49  
50 =cut
51  
52 0 ▶sub arguments {
Subroutine arguments: not called CC=1 SCAR=6.9
Pod documented
53 {
54 0 url => { constructor => 1 },
55 }
56 }
57  
58 =head2 take_action
59  
60 If the other actions in the request have been a success so far,
61 redirects to the provided C<url>. The redirect preserves all of the
62 L<Jifty::Result>s for this action, in case the destination page wishes
63 to inspect them.
64  
65 =cut
66  
67 0 ▶sub take_action {
Subroutine take_action: not called CC=3 SCAR=24.8
Pod documented
68 0 my $self = shift;
69  
70 # Return now if the URL is not set
71 0 ▶ return 1 unless ($self->argument_value('url'));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->argument_value("url") 0 0 0
72  
73 # Return now if the response is already sent (i.e., too late to redirect)
74 0 ▶ return 0 unless Jifty->web->response->success;
Branch: 1 branch
BranchTrueFalseTotal
unless "Jifty"->web->response->success 0 0 0
75  
76 # Find the URL to redirect to
77 0 my $page = $self->argument_value('url');
78  
79 # Set the next page and force the redirect
80 0 Jifty->web->next_page($page);
81 0 Jifty->web->force_redirect(1);
82 0 return 1;
83 }
84  
85 =head1 SEE ALSO
86  
87 L<Jifty::Action>, L<Jifty::Web/next_page>, L<Jity::Web/force_redirect>
88  
89 =head1 LICENSE
90  
91 Jifty is Copyright 2005-2010 Best Practical Solutions, LLC.
92 Jifty is distributed under the same terms as Perl itself.
93  
94 =cut
95  
96 113 1;
97  
« Jifty/Web/Session/ApacheSession.pm ↑ Summary Jifty/Plugin/Deflater.pm »