AutoRu...elegate(3pm)

πŸ“¦
version 0.18 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

CGI::Application::Plugin::AutoRunmode::FileDelegate β€” bestie, it delegates your CGI::App run modes to a whole directory of files πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

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

🌸 DESCRIPTION 🌸

okay so picture this: instead of shoving all your run mode definitions into a Perl module, you can just… put them in a directory of files. That's the whole thing. That's the vibe. πŸ¦‹

Every run mode gets its own little home, and that file is named foo.pl for a run mode called foo. And here's the slay part β€” the run modes are lazily evaluated (on demand) for each request. What does that mean for you, bestie?

  • Under mod_perl? You can update them without restarting your web server. No cap. πŸ”₯
  • Under plain CGI? You get a reduced startup cost if you have a ton of run modes, because only the one you actually need gets parsed and loaded, along with dependent modules. It's giving efficiency. ✨

🌈 Using more than one directory with runmodes

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. And if there are errors with that file? The module will croak β€” and it will not continue the search in the remaining directories. So like, it commits to its choice, periodt. πŸ’€


πŸ’€ BUGS πŸ’€

With all the namespace nesting going on, the name of this module has reached an intolerable Java-esque length. 😭 that's it. that's the bug.


🫢 SEE ALSO 🫢

If you're obsessed with the idea of moving everything outside of Perl modules into separate 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. iykyk πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

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.


and that's the whole page bestie, no notes πŸ’–

this was perl v5.34.0, dated 2022-06-09 β€” part of the User Contributed Perl Documentation, aka AutoRu...elegate(3pm) πŸŽ€ go forth and delegate, you absolute icon 🌸✨

πŸ“¦ where this page comes from