Name

CodeRepository — specify directory containing code that can be included in the running installation when needed

SYNOPSIS

directory_name

DESCRIPTION

There is a huge base of Interchange code (collection of UserTags and CodeDefs) included in the default installation. Much of it is not needed for the usual installations, causing a larger process memory profile than necessary.

Furthermore, it is hard to manually determine what subset of code is required, especially when an ITL tag calls $Tag->TAGNAME() which calls some filter which calls some sort of an action — you get the idea.

CodeRepository allows building catalogs with a more optimal set of code than just "everything".

CodeRepository depends on a related directive, AccumulateCode. If AccumulateCode is disabled, operation is traditional and everything gets loaded at Interchange startup time. (There have been some code initialization changes and routine calling changes, but the data structures are identical and no difference in operation should be seen).

It's when you remove the ICROOT/code/ directory and enable AccumulateCode that things get interesting. Interchange starts looking into CodeRepository for pieces it finds missing (ITL tags, ActionMaps, filters, widgets, etc.) and compiles these as needed, in runtime! The code is sent to the master process for compilation and incorporation, so that on the next page access (or in the worst case, after HouseKeeping seconds), Interchange will find the code already compiled and ready to go.

Fetched code blocks are copied to $Global::TagDir/Accumulated/. When you restart Interchange the next time, these code blocks will be found, read normally and need not be recompiled and loaded on the fly again.

Over time, as you access pages and routines, a full set of tags will be developed and you can then disable AccumulateCode. (In fact, AccumulateCode is recommended only for development and should really be turned off in production systems).

DIRECTIVE TYPE AND DEFAULT VALUE

Global directive

EXAMPLES

Example: Setting up CodeRepository

Put the following in interchange.cfg:

AccumulateCode Yes
CodeRepository /usr/interchange/code.pool/

To prepare the code.pool/ directory, you can do something like this:

$ mkdir /usr/interchange/code.pool/
$ mv /usr/interchange/code/* /usr/interchange/code.pool/

NOTES

There can be failures due to calling $Tag->TAGNAME() from within embedded Perl for the first time, particularly when it uses a "MapRoutine" or calls another $Tag->TAGNAME() within. This is due to Safe, and there is probably not much to be done about it. The good news is that the error should go away after HouseKeeping seconds, when the tag gets compiled by the master. [area], [tmp], [tmpn], and [image] are examples of tags known to fail in this manner. Tags that are frequently called in this fashion should probably be manually placed in directory code/Vital/ and not be accumulated "by chance". Anyway, this temporary failure could be avoided by listing catalog in the AllowGlobal directive, and it might also be possible to make a directive that allows AllowGlobal for a catalog automatically, when in AccumulateCode mode. (If you don't want to trade immediate code loading for the lack of AllowGlobal protection, then just set HouseKeeping to something like 20 seconds — and only do it on your development system!)

One convenient side-effect is that you can easily load new code (such as new Interchange tags) "on the fly" by simply adding files to the CodeRepository directory. This alleviates the need for Interchange server restart. It might also be possible to dynamically remove and load code from the server in this manner, but this has yet to be looked at.

[Warning] Warning

Nice features are often dangerous! Don't run this in production — you have been warned!

"OrderCheck" CodeDef is not yet implemented, and a full audit has not been done on all compiled code directives.

Not fully tested in PreFork mode, and really not intended for that mode.

Defining multiple tags or code blocks (UserTags or CodeDefs) within a single file may result in an unpredictable behavior.

This feature only applies to global code — catalog-based code is not affected and behaves as usual.

AVAILABILITY

CodeRepository is available in Interchange versions:

4.6.0-5.7.0 (git-head)

SOURCE

Interchange 5.7.0:

Source: lib/Vend/Config.pm
Line 429

['CodeRepository',   'root_dir',         ''],

Source: lib/Vend/Config.pm
Line 3906 (context shows lines 3906-3913)

sub parse_root_dir {
my($var, $value) = @_;
return '' unless $value;
$value = "$Global::VendRoot/$value"
  unless file_name_is_absolute($value);
$value =~ s./+$..;
return $value;
}

AUTHORS

Mike Heins

SEE ALSO

AccumulateCode(7ic)

DocBook! Interchange!