MojoMojo::Formatter::Redirect - Handles {{redirect /path}}


MojoMojo documentation Contained in the MojoMojo distribution.

Index


Code Index:

NAME

Top

MojoMojo::Formatter::Redirect - Handles {{redirect /path}}

DESCRIPTION

Top

Redirect to another page. Useful if your URL changes and you want to make sure bookmarked URLs will still work: /help/tutrial could contain: {{redirect /help/tutorial}}

To edit a page that redirects, surf to $page_URL . '.edit' See also http://mojomojo.ideascale.com/akira/dtd/6415-2416

METHODS

Top

format_content_order

Format order can be 1-99. The Redirect formatter runs first.

format_content

Calls the formatter. Takes a ref to the content as well as the context object.

SEE ALSO

Top

MojoMojo, Module::Pluggable::Ordered, URI::Fetch

AUTHORS

Top

Marcus Ramberg <mramberg@cpan.org>

LICENSE

Top

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.


MojoMojo documentation Contained in the MojoMojo distribution.
package MojoMojo::Formatter::Redirect;

use parent qw/MojoMojo::Formatter/;

sub format_content_order { 1 }

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;
    }
    

}

1;