1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
package MojoMojo::Formatter::Redirect;
use parent qw/MojoMojo::Formatter/;
=head1 NAME
MojoMojo::Formatter::Redirect - Handles {{redirect /path}}
=head1 DESCRIPTION
Redirect to another page. Useful if your URL changes and
you want to make sure bookmarked URLs will still work:
C</help/tutrial> could contain:
C<{{redirect /help/tutorial}}>
To edit a page that redirects, surf to $page_URL . '.edit'
See also http://mojomojo.ideascale.com/akira/dtd/6415-2416
=head1 METHODS
=head2 format_content_order
Format order can be 1-99. The Redirect formatter runs first.
=cut
sub format_content_order { 1 }
=head2 format_content
Calls the formatter. Takes a ref to the content as well as the
context object.
=cut
sub format_content {
my ( $class, $content, $c ) = @_;
if ( my ($page) = $$content =~ m/
\{\{
\s*redirect\s+
(\S+)
\s*}}/x
) {
if ($c->action->name eq 'view' && !$c->ajax) {
$c->flash->{'redirect'}=$c->stash->{'path'};;
$c->res->redirect( $c->uri_for($page) );
} elsif ($c->action->name eq 'render') {
$$content=$c->loc("redirect to")." ".$page;
}
# We don't want to precompile a redirected page so turn it off
$c->stash->{precompile_off} = 1;
}
}
=head1 SEE ALSO
L<MojoMojo>, L<Module::Pluggable::Ordered>, L<URI::Fetch>
=head1 AUTHORS
Marcus Ramberg <mramberg@cpan.org>
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
1;
|