The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

Synopsis

        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;

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 "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.

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::Forward as you would for any Perl module:

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

Constructor and Initialization

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

Methods

forward($run_mode[, @args])

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.

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::Dispatch - Dispatch requests to CGI::Snapp-based objects

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::Forward#AUTHOR, since this code is basically copied from CGI::Application::Plugin::Forward.

Support

Email the author, or log a bug on RT:

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

Author

CGI::Snapp::Plugin::Forward 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