NAME
App::ZofCMS::Plugin::ConditionalRedirect - redirect users based on conditions
SYNOPSIS
In Main Config file or ZofCMS template:
plugins => [ qw/ConditionalRedirect/ ],
plug_redirect => sub { time() % 2 ? 'http://google.com/' : undef },
DESCRIPTION
The module is a plugin for App::ZofCMS. It provides means to redirect user to pages depending on certain conditions, e.g. some key having a value in ZofCMS Template hashref or anything else, really.
This documeantation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
MAIN CONFIG FILE AND ZofCMS TEMPLATE KEYS
plugins
plugins => [ qw/ConditionalRedirect/ ],
plugins => [ { UserLogin => 1000 }, { ConditionalRedirect => 2000 } ],
The obvious is that you'd want to stick this plugin into the list of plugins to be executed. However, since functionality of this plugin can be easily implemeanted using exec
and exec_before
special keys in ZofCMS Template, being able to set the priority to when the plugin should be run would probably one of the reasons for you to use this plugin (it was for me at least).
plug_redirect
plug_redirect => sub {
my ( $template_ref, $query_ref, $config_obj ) = @_;
return $template_ref->{foo} ? 'http://google.com/' : undef;
}
The plug_redirect
first-level key in Main Config file or ZofCMS Template takes a subref as a value. The sub will be executed and its return value will determine where to redirect (if at all). Returning undef
from this sub will NOT cause any redirects at all. Returning anything else will be taken as a URL to which to redirect and the plugin will call exit()
after printing the redirect headers.
The @_
of the sub will receive the following: ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object (in that order).
If you set plug_redirect
in both Main Config File and ZofCMS Template, the one in ZofCMS Template will take precedence.
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
BUGS
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org
AUTHOR
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
LICENSE
You can use and distribute this module under the same terms as Perl itself. See the LICENSE
file included in this distribution for complete details.