TWiki::Func module to check dependencies in their plugins.
Modules packaged in this way are called Contrib modules. While the mechanism described here is mainly intended for packaging code, it could also be used for shipping other contributed modules that have dependencies, such as content or templates.
Note: it would have been nice to re-use one of the standard packaging and distribution mechanisms, such as RPM or CPAN. Unfortunately these make assumptions about the target installation environment that would be incompatible with the way that TWiki is distributed.
TWiki::Contrib namespace. The simplest possible module contains just a version number. For example, for the JSCalendarContrib module (which is principally Javascript) has the following stub:
package TWiki::Contrib::JSCalendar; use vars qw( $VERSION ); $VERSION = 0.96; 1;
xxxxContrib (where xxxx is the name of the contribution), and contains the documentation for the module.
Documentation for Perl modules can be hand-authored, or automatically extracted from the code via POD by the BuildContrib module. For other languages it may be hand-authored, or consist of links to documentation topics shipped in the pub directory (e.g. javadoc). In all cases it should follow the template shown in NewContribTemplate. View this template with ?raw=on, and copy and paste the content into your own documentation topic.
NewContribTemplate includes the definition of a variable called STUB, that must be set to the name of the Perl module for the code.
Note that the standard search summary is used as the code library equivalent of "SHORTDESCRIPTION".
When uploading the documentation topic to twiki.org, please ensure that the form type is PackageForm and the TopicClassification in the form is set to 'ContributedCode'.
$twikiroot/lib/TWiki/Contrib....
%TWIKIWEB/JSCalendarContrib/JScalendar...
bin scripts should ship in bin
contrib e.g.
$twikiroot/contrib/GNURegexp/src/gnu/regexp/RE.java --- used by several plugins $twikiroot/contrib/twiki_dav/dav_twiki.c --- WebDAVPlugin apache module sourceNote: CPAN modules should not be repackaged as Contrib modules. It is much better to document the requirement to install them for the end-user to resolve in a way that is appropriate for their installation.
TWiki::Func function checkDependencies can be used to check dependencies at run-time. For example, your initPlugin might contain:
if( $TWiki::Plugins::VERSION >= 1.025 ) {
my @deps = (
{ package => 'TWiki::Contrib::JSCalendar', constraint => '>= 0.96' },
{ package => 'TWiki::Contrib::Attrs', constraint => '>= 1.00' },
);
my $err = TWiki::Func::checkDependencies( $pluginName, \@deps );
if( $err ) {
TWiki::Func::writeWarning( $err );
print STDERR $err; # print to webserver log file
return 0; # plugin initialisation failed
}
}
Note the use of a print to STDERR to output error messages. This will print a message to the Apache log file if the installation is using Apache. This is in addition to writing to warning.txt.
Tip: If you use lazy loading to delay loading modules until they are actually required, you may also have to make the checkDependencies call lazy, as it internally calls use on each dependency.
Test::Unit, automatic extraction of documentation using POD, manifest based packaging, and automatic upload mechanisms,
| ~Total: -1 | ~Tested on TWiki version | ~Installed at TWiki.org: ~Installed at TWiki.org: %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}%: 1 |
~Submitted by - Last Author - Last Change |
| WebForm | |
|---|---|
| TopicClassification | AdminTopic |
| TopicSummary | How to contribute shared code |
| InterestedParties | |
| RelatedTopics | |
| I | Attachment | Action | Size | Date | Who | Comment |
|---|---|---|---|---|---|---|
| |
sharedcodediscuss.txt | manage | 9.3 K | 08 Aug 2004 - 09:17 | CrawfordCurrie |