NAME

CGI::Snapp::Plugin::Redirect - A plugin for CGI::Snapp to simplify using HTTP redirects

Synopsis

package My::App;

use parent 'CGI::Snapp';

use CGI::Snapp::Plugin::Redirect;

sub cgiapp_prerun
{
	my($self) = @_;

	if (<< not logged in >>)
	{
		$self -> redirect('login.html');
	}

} # End of cgiapp_prerun.

sub teardown
{
	my($self) = @_;

	return $self -> redirect('http://www.example.com/', '301 Moved Permanently');

} # End of teardown.

Description

When you 'use' this module in your sub-class of CGI::Snapp (as in the Synopsis), it automatically imports into your sub-class the "redirect($url[, $status])" method, to give you a single call to set the HTTP headers for redirection to an external $url. See that method's details below for exactly what effect a call to redirect() has.

If you just want to display the results of another run mode within the same application, then CGI::Snapp::Plugin::Forward's forward() method is more suitable.

Distributions

This module is available as a Unix-style distro (*.tgz).

See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing distros.

Installation

Install CGI::Snapp::Plugin::Redirect as you would for any Perl module:

Run:

cpanm CGI::Snapp::Plugin::Redirect

or run:

sudo cpan CGI::Snapp::Plugin::Redirect

or unpack the distro, and then either:

perl Build.PL
./Build
./Build test
sudo ./Build install

or:

perl Makefile.PL
make (or dmake or nmake)
make test
make install

Constructor and Initialization

This module does not have, and does not need, a constructor.

Methods

redirect($url[, $status])

Interrupts the current request, and redirects to the given (external) $url, optionally setting the HTTP status to $status.

Here, the [] indicate an optional parameter.

The redirect happens even if you are inside a method attached to the 'prerun' hook when you call redirect().

Specifically, this method does these 3 things:

o Sets the HTTP header 'location' to the given $url
o Sets the HTTP 'status' (if provided) to $status
o Sets the CGI::Snapp header type to 'redirect'

FAQ

Why don't you 'use Exporter;'?

It is not needed; it would be for documentation only.

For the record, Exporter V 5.567 ships with Perl 5.8.0. That's what I had in Build.PL and Makefile.PL until I tested the fact I can omit it.

See Also

CGI::Application

The following are all part of this set of distros:

CGI::Snapp - A almost back-compat fork of CGI::Application

CGI::Snapp::Plugin::Forward - A plugin for CGI::Snapp to switch cleanly to another run mode within the same app

CGI::Snapp::Plugin::Redirect - A plugin for CGI::Snapp to simplify using HTTP redirects

CGI::Snapp::Demo::One - A template-free demo of CGI::Snapp using just 1 run mode

CGI::Snapp::Demo::Two - A template-free demo of CGI::Snapp using N run modes

CGI::Snapp::Demo::Three - A template-free demo of CGI::Snapp using CGI::Snapp::Plugin::Forward

CGI::Snapp::Demo::Four - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI

CGI::Snapp::Demo::Four::Wrapper - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI

Config::Plugin::Tiny - A plugin which uses Config::Tiny

Config::Plugin::TinyManifold - A plugin which uses Config::Tiny with 1 of N sections

Data::Session - Persistent session data management

Log::Handler::Plugin::DBI - A plugin for Log::Handler using Log::Hander::Output::DBI

Log::Handler::Plugin::DBI::CreateTable - A helper for Log::Hander::Output::DBI to create your 'log' table

Machine-Readable Change Log

The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.

Version Numbers

Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.

Credits

Please read https://metacpan.org/module/CGI::Application::Plugin::Redirect#AUTHOR, since this code is basically copied from CGI::Application::Plugin::Redirect.

Support

Email the author, or log a bug on RT:

https://rt.cpan.org/Public/Dist/Display.html?Name=CGI::Snapp::Plugin::Redirect.

Author

CGI::Snapp::Plugin::Redirect was written by Ron Savage <ron@savage.net.au> in 2012.

Home page: http://savage.net.au/index.html.

Copyright

Australian copyright (c) 2012, Ron Savage.

All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Artistic License, a copy of which is available at:
http://www.opensource.org/licenses/index.html