Providing metadata for plugins

I've been thinking that it might be a good idea to provide a small file with each plugin containing metadata about it, like the META.yml file provided with Perl modules. It could be used to generate a configuration interface for choosing which plugins to enable.

I wrote some code to try this out. I'm putting it on the back burner for now, since there just aren't enough plugins (or enough user interface) to make it worth while, but it's committed in r733 on the ‘plugins-metadata’ branch.

Metadata format

This is what the metadata for an article loader plugin might look like:

<?xml version="1.0"?>
<plugin xmlns="http://www.daizucms.org/ns/plugin/">
 <meta name="Daizu::Plugin::XHTMLArticle"
       description="Load article content from files containing
           fragments of XHTML markup, with optional Daizu
           extension elements and XInclude instructions." />

 <article-loader type="text/html application/xhtml+xml" />
</plugin>

Article filter plugins just have an article-filter element with no attributes.

Currently I'm assuming the plugins provide standard method names in their classes which Daizu will call, but I could easily add a method attribute to the metadata to allow that to be changed. That would allow a plugin module to provide several different services of the same type, for example offering to load articles in several related formats.

On the other hand it might be easier to use Perl syntax for the metadata. Something like this:

{
    name => 'Daizu::Plugin::XHTMLArticle',
    description =>
        "Load article content from files containing fragments" .
        " of XHTML markup, with optional Daizu extension" .
        " elements and XInclude instructions.",

    article_loader => {
        type => 'text/html application/xhtml+xml',
    },
}

Loading plugin metadata

The nice thing about using Perl code for the metadata is that it's easy to load. The metadata for plugins installed in the Perl library path can be loaded with require:

my $filename = $class_name;
$filename =~ s!::!/!g;
$filename .= '.plugin';

my $meta = require $filename;

With the support I've added for the special _lib directory, this will already work with plugins stored in the content repository.

If I use XML though I would have to write my own loading function to search through paths in @INC, and parse the files.

< Daizu repository | New _lib directory >