CGI::Snapp::Plugin::Forward - A plugin for CGI::Snapp to switch cleanly to another run mode within the same app
package My::App; use parent 'CGI::Snapp'; use CGI::Snapp::Plugin::Forward; # ------------------------------------------------ sub setup { my($self) = @_; $self -> run_modes([qw(start second)]); } # ------------------------------------------------ sub start { my($self) = @_; my($rm) = $self -> get_current_runmode; # 'start'. return $self -> forward('second', 'some', 'data'); } # ------------------------------------------------ sub second { my($self, @args) = @_; my($rm) = $self -> get_current_runmode; # 'second'. return $html; } # ------------------------------------------------ 1;
When you 'use' this module in your sub-class of CGI::Snapp (as in the Synopsis), it automatically imports into your sub-class the "forward($run_mode[, @args])" method, to give you a single call to switch run modes and run a hook before entering the new run mode. See that method's details below for exactly what effect a call to forward() has.
If you want to redirect to another (external) url, then CGI::Snapp::Plugin::Redirect's redirect() method is more suitable.
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.
Install CGI::Snapp::Plugin::Forward as you would for any Perl module:
Perl
Run:
cpanm CGI::Snapp::Plugin::Forward
or run:
sudo cpan CGI::Snapp::Plugin::Forward
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
This module does not have, and does not need, a constructor.
Switches from the current run mode to the given $run_mode, passing the optional @args.
Returns the output of the $run_mode method.
For this to work, you must have previously called $self -> run_modes($run_mode => 'some_method'), so the code knows which method it must call.
Just before the method associated with $run_mode is invoked, the current run mode (within CGI::Snapp) is set to $run_mode, and any methods attached to the hook 'forward_prerun' are called.
Calling this hook gives you the opportunity of making any preparations you wish before the new run mode is entered. See sub setup() in t/lib/ForwardTest.pm for sample code.
Finally, $run_mode's method is called.
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.
CGI::Application
The following are all part of this set of distros:
CGI::Snapp - A almost back-compat fork of CGI::Application
CGI::Snapp::Dispatch - Dispatch requests to CGI::Snapp-based objects
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
The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
Please read https://metacpan.org/module/CGI::Application::Plugin::Forward#AUTHOR, since this code is basically copied from CGI::Application::Plugin::Forward.
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=CGI::Snapp::Plugin::Forward.
CGI::Snapp::Plugin::Forward was written by Ron Savage <ron@savage.net.au> in 2012.
Home page: http://savage.net.au/index.html.
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
To install CGI::Snapp::Plugin::Forward, copy and paste the appropriate command in to your terminal.
cpanm
CPAN shell
perl -MCPAN -e shell install CGI::Snapp::Plugin::Forward
For more information on module installation, please visit the detailed CPAN module installation guide.