NAME
DBIx::VersionedSubs::AutoLoad - autload subroutines from the database
SYNOPSIS
package My::App;
use strict;
use base 'DBIx::VersionedSubs::AutoLoad';
package main;
use strict;
My::App->startup($dsn);
while (my $request = Some::Server->get_request) {
My::App->update_code; # update code from the DB
My::App->handle_request($request);
}
ABSTRACT
This module overrides some methods in DBIx::VersionedSubs to prevent loading of the whole code at startup and installs an AUTOLOAD handler to load the needed code on demand. This is useful if startup time is more important than response time or you fork() before loading the code from the database.
CAVEATS
You should be able to switch between the two implementations without almost any further code changes. There is one drawback of the AUTOLOAD implementation:
Preexisting functions don't get overwritten from the database
You need to explicitly load functions from the database that you wish to overwrite Perl code obtained from elsewhere.
This is the price you pay for using AUTOLOAD.
CLASS METHODS
__PACKAGE__->init_code
Overridden to just install the AUTOLOAD handler.
__PACKAGE__->install_and_invoke NAME, ARGS
Loads code from the database, installs it into the namespace and immediately calls it with the remaining arguments via goto &code;
.
If no row with a matching name exists, an error is raised.
__PACKAGE__->update_code
Overridden to do lazy updates. It wipes all code that is out of date from the namespace and lets the AUTOLOAD handler sort out the reloading.
__PACKAGE__->load_code NAME
Retrieves the code for the subroutine NAME
from the database and calls __PACKAGE__->install_code $name,$code
to install it.
INSTALLED CODE
AUTOLOAD
An AUTOLOAD handler is installed to manage the loading of code that has not been retrieved from the database yet. If another AUTOLOAD handler already exists, the AUTOLOAD handler is not installed and a warning is issued.