GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AutoRunmode::FileDelegate(3) User Contributed Perl Documentation AutoRunmode::FileDelegate(3)

CGI::Application::Plugin::AutoRunmode::FileDelegate - delegate CGI::App run modes to a directory of files

        # in file runmodes/my_run_mode.pl
                sub  {
                        my ($app, $delegate) = @_;
                                # do something here
                };
                
        # in file runmodes/another_run_mode.pl
                sub {
                                # do something else
                };
                
        
        package MyApp;
        use base 'CGI::Application';
        use CGI::Application::Plugin::AutoRunmode 
                qw [ cgiapp_prerun];
        use CGI::Application::Plugin::AutoRunmode::FileDelegate();
                
                sub setup{
                        my ($self) = @_;
                        my $delegate = new CGI::Application::Plugin::AutoRunmode::FileDelegate
                                        ('/path/to/runmodes')
                        $self->param('::Plugin::AutoRunmode::delegate' => $delegate);
                }
        
         # you now have two run modes
         # "my_run_mode" and "another_run_mode"

Using this module, you can place the definition of your run modes for a CGI::Application into directory of files (as opposed to into a Perl module).

Each run mode is contained in its own file, named foo.pl for a run mode called foo. The run modes are lazily evaluated (on demand) for each request. In the case of mod_perl this means you can update them without restarting your web server. In the case of plain CGI it means a reduced startup cost if you have many run modes (because only the one that you need gets parsed and loaded, along with dependent modules).

You can pass multiple directory paths to the constructor for the delegate:

        my $delegate = new CGI::Application::Plugin::AutoRunmode::FileDelegate
                        ('/path/to/runmodes', '/path/to/more_runmodes')

In this case, they will be searched in order. The first matching file becomes the run mode. In the case of errors with that file, the module will croak (and not continue the search in the remaining directories).

With all the namespace nesting going on the name of this module has reached an intolerable Java-esque length.

If you like the idea of moving everything outside of Perl modules into seperate files, you should also have a look at CGI::Application::Plugin::TemplateRunner, which does a similar thing for HTML templates and the Perl code needed to provide them with data.

Thilo Planz, <thilo@cpan.org>

Copyright 2005 by Thilo Planz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2011-02-18 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.