NAME
PSA::Cache - Cache of compiled scripts
SYNOPSIS
my $cache = new PSA::Cache
(
base_dir => "psa-bin/",
default_type => {
'\.psa$' => "PSA",
'\.pl$' => "Perl",
},
includes_dirs => [ "/usr/lib/psa/bin",
"/usr/local/lib/libfoo-psa/" ],
)
$cache->run("script.psa", @args);
DESCRIPTION
The PSA Cache is a useful tool for managing large programs built up of several small scripts.
PSA `scripts' are much like calling a function, except that preprocessing can be performed (without having to meddle with Perl source filters), and if the file is changed on the disk, the function will be re-loaded, without having to restart the entire server.
The way it works is this:
The script is preprocessed to a piece of perl, that must return a CODE reference (ie, it simply declares a subroutine).
That script is placed in its own package/namespace, and then
eval()
'd into a compiled piece of perl. Whilst I haven't got this working with the Safe module yet (see Safe), this is a handy place to put such a hook, which would give the whole system that extra level of security if you can't trust the components to be behaved.When you call
$cache-
run("script", @args)>, that script is looked up, possiblystat
(see perlfunc) is called to see if the file has changed since we last called it, and then the code ref is called with the arguments you pass.
The PSA Cache is populated with PSA::Cache::Entry
objects. By sub-classing PSA::Cache::Entry
, you may define new ways for scripts to work. Essentially, each of the above steps are methods of the PSA::Cache::Entry
objects.