|Declare run modes with subroutine attributes.||You can flag methods in your CGI::App subclass with the attribute Runmode or StartRunmode (these attributes are case-insensitive)|
|Declare that every method in a class is a run mode.||
You can assign a
delegate object, all whose methods will become runmodes
You can also mix both approaches.
It is possible to chain multiple delegates by specifying an array reference containing the delegate instances or class names. This chain is checked from left to right and the runmode will be delegated to the first match.
This module needs to export some symbols to do its job.
First of all, there are the handlers for the Runmode attribute.
In addition to that, the cgiapp_prerun hook is installed in your application class. This is not done as an export per se, but the hook installation is still done in the import subroutine. Sound confusing, is confusing, but you do not really need to know what is going on exactly, just keep in mind that in order to let things go on, you have to use the module with the default exports:
You can also explicitly import the cgiapp_prerun method. This will disable the installation of the hook. Basically, you only want to do this if you are using CGI::Application prior to version 4, where hooks are not supported.
After CGI::App has determined the name of the run mode to be executed in the normal way, cgiapp_prerun checks if such a run mode exists in the map configured by $self->run_modes().
If the run mode already exists, it gets executed normally (this module does nothing). This means that you can mix the ways to declare run modes offered by this plugin with the style provided by core CGI::App.
If that is not the case, it tries to find a method of the same name in the application class (or its superclasses) that has been flagged as a Runmode. If it finds one, it augments the mapping with a subroutine reference to that method.
If that step fails, it looks if a delegate has been defined and searches the methods of that delegate object for one that matches the name of the runmode.
The run mode called start
Note that because the plugin only gets activated when you call a run mode that is not registered in the usual run mode map, you cannot use it to create a run mode called start. The CGI:App base class always registers a run mode of that name.
If you have a cgiapp_prerun method and change the run mode there, the installed hook will not be able to catch it (because of the ordering of hooks).
So, if you do that, you have to explicitly make this call before returning from cgiapp_prerun:
The attribute StartRunmode designates that subroutine to be the start (default) run mode. If you use this feature, the traditional way of setting the start run mode (calling $self->start_mode(name)) is disabled and can no longer be used in this application (including subclasses and instance scripts).
The attribute ErrorRunmode designates that subroutine to be the error run mode. If you use this feature, the traditional way of setting the error run mode (calling $self->error_mode(name)) is disabled and can no longer be used in this application (including subclasses and instance scripts). This feature requires CGI::App of at least version 3.30.
Note that this error run mode is not a run mode that is directly accessible using its name as a query parameter. It will only be dispatched to internally if the original run mode produced an error. This is exactly how plain CGI:App error_mode behaves as well (you could still declare the method to also be a :Runmode ).
The whole idea of this module (to reduce code complexity by automatically mapping a URL to a subroutine that gets executed) is a potential security hazard and great care has to be taken so that a remote user cannot run code that you did not intend them to.
In order to prevent a carefully crafted URL to access code in other packages, this module disallows non-word characters (such as : ) in run mode names.
Also, you have to make sure that when using a delegate object, that it (and its superclasses) only contain run modes (and no other subroutines).
The following run mode names are disallowed by this module:
can isa VERSION AUTOLOAD new DESTROY
This module only inserts the current run mode into the run_mode map (unless it is already in there). It does not place any other :Runmodes there. As a result of this behaviour, users of AutoRunmode will most likely find the run mode map almost completely empty. This can lead to strange results if you expect a more complete list of possible run modes there. At this time, there is no workaround for this. Feel free to complain to the author if you have a requirement here.
It is possible, however, to query the AutoRunmode plugin if an AutoRunmode exists for a given name.
This function returns a code ref if such an AutoRunmode exists.
o CGI::Application::Plugin::AutoRunmode::FileDelegate o CGI::Application o The CGI::App wiki at <http://www.cgi-app.org/>. o CGI::Application::Plugin::ActionDispatch provides an alternative set of attributes that dispatch according to PATH_INFO. It is very similar to the mechanism used in the Catalyst framework.
Thilo Planz, <firstname.lastname@example.org>
Please use the request tracker at CPAN to report bugs or feature requests: <https://rt.cpan.org/Public/Dist/Display.html?Name=CGI-Application-Plugin-AutoRunmode>
If you want to support the development of this module with money, you can donate using Flattr: <https://flattr.com/thing/132835>
Copyright 2004-2011 by Thilo Planz
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|perl v5.20.3||AUTORUNMODE (3)||2011-02-18|