Wiki::...ending(3pm)
πΈ NAME πΈ
okay bestie, welcome to the manual page Wiki::...ending(3pm) from User Contributed Perl Documentation. It's Extending.pod β literally: How to extend Wiki::Toolkit with your own plugins. periodt. π
π¦ LIMITATIONS π¦
rn the extension mechanism is currently only defined for database-backed setups, but since nobody has written any other kind of backend I think we're fine for now. lowkey iconic. π
β¨ THE SIMPLEST WAY β¨
okay so you can extend Wiki::Toolkit in a fairly simplified way without the use of plugins, by supplying a hash of metadata when you write a node. like this:
$wiki->write_node( $node, $content, $checksum,
{ postcode => $postcode } );
and on node retrieval you'll get it back again:
my %node = $wiki->retrieve_node( $node );
my $postcode = $node{metadata}{postcode}[0];
you can supply more than one value for each type of metadata:
$wiki->write_node( $node, $content, $checksum,
{ postcode => "W6 9PL",
category => [ "Thai Food", "Restaurant", "Hammersmith" ] } );
and get back a list of nodes which have a given value for a given metadata type:
my @nodes = $wiki->list_nodes_by_metadata(
metadata_type => "category",
metadata_value => "Hammersmith" );
for anything more complicated you will need to write a plugin. no cap. π¦
π PLUGIN BASE CLASS π
Plugins should inherit from Wiki::Toolkit::Plugin. This base class provides the following methods to give access to a Wiki::Toolkit object's backends:
datastoreβ returns the store objectindexerβ returns the search objectformatterβ returns the formatter object
if you want these methods to return anything useful then call
$wiki->register_plugin( plugin => $plugin);
before calling, say
my %node_data = $plugin->datastore->retrieve_node( "Foo" );
π CALLING API π
okay so the calling API is giving main character energy. here's the vibe:
my $plugin = Wiki::Toolkit::Plugin::Foo->new( ...any required args... );
$wiki->register_plugin( plugin => $plugin );
$wiki->write_node( "Test Node" ,"Test", $checksum,
{ foo_data => { a => "apple",
b => "banana" }
} );
my $bee = $plugin->get_word( node => "Test Node", letter => "b" );
or
my $plugin = OpenGuides::London::Underground->new;
$wiki->register_plugin( plugin => $plugin );
$wiki->write_node( "Hammersmith Station", "a station", $checksum,
{ tube_data => [
{ line => "Piccadilly",
direction => "Eastbound",
next_station => "Baron's Court Station"
},
{ line => "Piccadilly",
direction => "Westbound",
next_station => "Acton Town Station"
}
]
}
);
# Put more data in, then
my @route = $plugin->find_route( from => "Holborn Station",
to => "Acton Town Station" );
π STORE ACCESS π
A plugin named Wiki::Toolkit::Plugin::Foo may access the backend database directly like so:
- Read-only access to any table
- Read-write access to any table whose name begins with
"p_" . $Wiki::Toolkit::Plugin::Foo::plugin_key . "_"
$Wiki::Toolkit::Plugin::Foo::plugin_key should be different from the keys of all other plugins. No, I haven't set anything up to ensure this. π iconic but terrifying.
π REQUIREMENTS FOR PLUGIN AUTHORS π
Either be database-agnostic, or state clearly in your docs which databases you support, and handle errors nicely. Be aware that non-database backends may exist in the future. fr fr.
Be aware of whether you need to check for locks explicitly in different databases (see code of Wiki::Toolkit::Store::* to find out).
β REQUIRED METHODS β
on_register
Check that any tables you require are set up, and set them up if not. that's the required one, bestie.
π OPTIONAL METHODS π
post_write
This will be called every time a node is written, with the arguments like so:
$plugin->post_write( node => $node_name,
version => $version_number,
content => $content,
metadata => \%user_defined_metadata );
This will happen after the node data is all written, but before any lock is released.
We could probably reimplement the searches as plugins like this if we want to, but this will require writing extra backends for Search::InvertedIndex so it can work within the same database.
The user-defined metadata will already have been stored in the backend but it is available here for you to do what you will with it.
Its return value should be true on success and false on error.
post_read
π¨ THIS IS NOT YET IMPLEMENTED. π¨
This will be called every time a node is read, with the arguments like so:
$plugin->post_read( node => $node_name,
version => $version_number,
content => $content,
metadata => \%user_defined_metadata );
It cannot affect the data returned to the caller. It should be used for its side-effects, for example tracking the number of times a given node is accessed.
Its return value should be true on success and false on error.
π PLUGIN CONFLICTS π
okay but real talk: What if we have more than one plugin registered? What if we change the mechanism to allow the plugins to change the data stored in the database/returned to the caller? π iykyk.
that's the whole page, bestie π source/version is perl v5.32.0, dated 2021-01-04, manual name Wiki::...ending(3pm). mwah π«Άβ¨
π¦ where this page comes from
- debian bookworm: libwiki-toolkit-perl 0.86-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libwiki-toolkit-perl 0.86-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libwiki-toolkit-perl 0.86-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libwiki-toolkit-perl 0.86-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libwiki-toolkit-perl 0.86-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libwiki-toolkit-perl 0.86-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms