Category management for wiki::toolkit.
Uses node metadata to build a model of how nodes are related to each other in terms of categories.
use Wiki::Toolkit; use Wiki::Toolkit::Plugin::Categoriser; my $wiki = Wiki::Toolkit->new( ... ); $wiki->write_node( "Red Lion", "nice beer", $checksum, { category => [ "Pubs", "Pub Food" ] } ) or die "Can't write node"; $wiki->write_node( "Holborn Station", "busy at peak times", $checksum, { category => "Tube Station" } ) or die "Can't write node"; my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; $wiki->register_plugin( plugin => $categoriser ); my $isa_pub = $categoriser->in_category( category => "Pubs", node => "Red Lion" ); my @categories = $categoriser->categories( node => "Holborn Station" );
my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; $wiki->register_plugin( plugin => $categoriser );
my $isa_pub = $categoriser->in_category( category => "Pubs", node => "Red Lion" ); Returns true if the node is in the category, and false otherwise. Note that this is case-insensitive, so \*(C`Pubs\*(C' is the same category as \*(C`pubs\*(C'. I might do something to make it plural-insensitive at some point too.
$wiki->write_node( "Category Pub Food", "mmm food", $checksum, { category => [ "Pubs", "Food", "Category" ] } ) or die "Can't write node"; my @subcats = $categoriser->subcategories( category => "Pubs" ); # will return ( "Pub Food" )
# Or if you prefer CamelCase node names: $wiki->write_node( "CategoryPubFood", "mmm food", $checksum, { category => [ "Pubs", "Food", "Category" ] } ) or die "Can't write node"; my @subcats = $categoriser->subcategories( category => "Pubs" ); # will return ( "PubFood" ) To add a subcategory \*(C`Foo\*(C' to a given category \*(C`Bar\*(C', write a node called any one of \*(C`Foo\*(C', \*(C`Category Foo\*(C', or \*(C`CategoryFoo\*(C' with metadata indicating that it's in categories \*(C`Bar\*(C' and \*(C`Category\*(C'. Yes, this pays specific attention to the Wiki convention of defining categories by prefacing the category name with \*(C`Category\*(C' and creating a node by that name. If different behaviour is required we should probably implement it using an optional argument in the constructor.
my @cats = $categoriser->categories( node => "Holborn Station" ); Returns an array of category names in no particular order.
Wiki::Toolkit
Wiki::Toolkit::Plugin
Kake Pugh ([email protected]). The Wiki::Toolkit team (http://www.wiki-toolkit.org/)
Copyright (C) 2003-4 Kake Pugh. All Rights Reserved. Copyright (C) 2006-2009 the Wiki::Toolkit team. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.