If your plugin depends on some condition to be successfully
loaded, you should include a test for whatever is required in a
BEGIN
block, and if the conditions are not present,
you should call the Perl die
function passing a
descriptive message telling why the plugin could not be loaded.
For example, here is part of a hypothetical spell-checker plugin
that uses the file /usr/share/dict/words
file:
package spellcheck; #: Version: 1.0 #: Description: Spell Checker #: Author: Somebody BEGIN { die("Word file (/usr/share/dict/words) could not be read") unless -r /usr/share/dict/words; } ...
When the user tries to load that plugin, the test will be made.
If the file cannot be read (because it does not exist, or the
permissiosn are wrong, or for any other reason),
die
will be called, the plugin will not be
loaded, and the given message will be printed in the screen.
If your plugin requires some other plugin, you should use the
$world->requireplugin
function in a
BEGIN
block. This function will verify if the named
plugin is already loaded. If it is, it returns successfully. If it is
not loaded, the function will try to load the plugin. If it could be
loaded, the function exits successfully. If, however, the plugin
could not be loaded (because it was not found, or because it failed
some condition), $world->requireplugin
will call
die
, which will abort the loading the plugin that
required the other plugin.
As an example, consider the plugin foo, which requires the bar sec_plugin_
package foo; #: Version: 1.0 #: Description: The Super Frobnicator #: Author: Somebody BEGIN { $::world->requireplugin('bar'); } ...
If foo was loaded successfully, you can be sure that the bar plugin and its functionality is present. If bar could not be loaded, foo will not be loaded.