Wiki-Toolkit-Plugin-Categoriser-0.08/0002755000175000017500000000000011271076310015610 5ustar domdomWiki-Toolkit-Plugin-Categoriser-0.08/Changes0000644000175000017500000000111511271076257017111 0ustar domdom0.08 25 October 2009 Add t/pod.t to MANIFEST 0.07 25 October 2009 Add POD tests and fix some broken POD 0.06 31 January 2009 Explicitly skip tests if no backends configured, to avoid spurious test failure reports. Sign distribution 0.05 8 March 2007 Fix bug - ->categories was picking up out-of-date categories. 0.04 13 May 2006 Renamed Wiki::Toolkit::Plugin::Categoriser 0.03 Updated tests. 0.02 23 June 2003 Made a start at subcategory support. 0.01 10 May 2003 Initial release. Wiki-Toolkit-Plugin-Categoriser-0.08/SIGNATURE0000644000175000017500000000227611271076310017101 0ustar domdomThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.55. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 3da76f1256b991f277e7093294ef4c2029636df4 Changes SHA1 17ccae049a10e59da6b55818e65c16da41f7b082 MANIFEST SHA1 79b03c748a3745a312b1a626fe07b89d89fb290e META.yml SHA1 53a49fe85dcb5c87439cf865a94f80170c5af447 Makefile.PL SHA1 e09ce7033035158c9bfc1bd65a3fe3c6970089f9 lib/Wiki/Toolkit/Plugin/Categoriser.pm SHA1 1bf411c36941891c8137ef0cb31126ff52a2efd1 t/categoriser.t SHA1 51f31ec687aa79b759c086a6a6cf31636e5941e1 t/nested_categories.t SHA1 e9c6a5881fc60173fbc8d479c1afd2ce3b43bef1 t/pod.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iD8DBQFK5HzFYzuFKFF44qURAnfwAKCsjCbFqq5KpbGANtjR9gwgebYDrACguTw9 7/mIEv5Tq/qNPaWdTNM0/WQ= =app1 -----END PGP SIGNATURE----- Wiki-Toolkit-Plugin-Categoriser-0.08/META.yml0000644000175000017500000000072311271076305017065 0ustar domdom--- #YAML:1.0 name: Wiki-Toolkit-Plugin-Categoriser version: 0.08 abstract: ~ license: ~ author: ~ generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: Carp: 0 Test::More: 0 Wiki::Toolkit: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Wiki-Toolkit-Plugin-Categoriser-0.08/MANIFEST0000644000175000017500000000042411271076305016743 0ustar domdomChanges MANIFEST Makefile.PL lib/Wiki/Toolkit/Plugin/Categoriser.pm t/categoriser.t t/nested_categories.t t/pod.t META.yml Module meta-data (added by MakeMaker) SIGNATURE Public-key signature (added by MakeMaker) Wiki-Toolkit-Plugin-Categoriser-0.08/t/0002755000175000017500000000000011271076305016057 5ustar domdomWiki-Toolkit-Plugin-Categoriser-0.08/t/nested_categories.t0000644000175000017500000000205111271076257021735 0ustar domdomuse strict; use Wiki::Toolkit::Plugin::Categoriser; use Wiki::Toolkit::TestLib; use Test::More; my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker; if ( $iterator->number ) { plan tests => ( $iterator->number * 1 ); } else { plan skip_all => "No backends configured."; } while ( my $wiki = $iterator->new_wiki ) { print "#\n##### TEST CONFIG: Store: " . (ref $wiki->store) . "\n"; my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; $wiki->register_plugin( plugin => $categoriser ); $wiki->write_node( "Pub Food", "pubs that serve food", undef, { category => [ "Pubs", "Food", "Category" ] } ) or die "Can't write node"; $wiki->write_node( "Restaurants", "places that serve food", undef, { category => [ "Food", "Category" ] } ) or die "Can't write node"; my @subcategories = $categoriser->subcategories( category => "Pubs" ); is_deeply( \@subcategories, [ "Pub Food" ], "->subcategories returns things that belong, and not things that don't" ); } Wiki-Toolkit-Plugin-Categoriser-0.08/t/categoriser.t0000644000175000017500000000444311271076257020564 0ustar domdomuse strict; use Wiki::Toolkit::TestLib; use Test::More; my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker; plan tests => ( 1 + $iterator->number * 7 ); use_ok( "Wiki::Toolkit::Plugin::Categoriser" ); while ( my $wiki = $iterator->new_wiki ) { print "#\n##### TEST CONFIG: Store: " . (ref $wiki->store) . "\n"; my $categoriser = eval { Wiki::Toolkit::Plugin::Categoriser->new; }; is( $@, "", "'new' doesn't croak" ); isa_ok( $categoriser, "Wiki::Toolkit::Plugin::Categoriser" ); $wiki->register_plugin( plugin => $categoriser ); $wiki->write_node( "Calthorpe Arms", "beer", undef, { category => [ "Pubs", "Pub Food" ] } ) or die "Can't write node"; $wiki->write_node( "Albion", "pub", undef, { category => [ "Pubs", "Pub Food" ] } ) or die "Can't write node"; $wiki->write_node( "Ken Livingstone", "Congestion charge hero", undef, { category => [ "People" ] } ) or die "Can't write node"; # Test ->in_category my $isa_pub = $categoriser->in_category( category => "Pubs", node => "Albion" ); ok( $isa_pub, "in_category returns true for things in the category" ); $isa_pub = $categoriser->in_category( category => "Pubs", node => "Ken Livingstone" ); ok( !$isa_pub, "...and false for things not in the category" ); $isa_pub = $categoriser->in_category( category => "pubs", node => "Albion" ); ok( $isa_pub, "...and is case-insensitive" ); # Test ->categories my @categories = $categoriser->categories( node => "Calthorpe Arms" ); is_deeply( [ sort @categories ], [ "Pub Food", "Pubs" ], "...->categories returns all categories" ); # Make sure we only look at current category data. my %node_data = $wiki->retrieve_node( "Calthorpe Arms" ); $wiki->write_node( "Calthorpe Arms", "Oh noes, they stopped doing food!", $node_data{checksum}, { category => [ "Pubs" ] } ) or die "Can't write node"; @categories = $categoriser->categories( node => "Calthorpe Arms" ); is_deeply( \@categories, [ "Pubs" ], "->categories ignores out-of-date data" ); } Wiki-Toolkit-Plugin-Categoriser-0.08/t/pod.t0000644000175000017500000000020111271076257017023 0ustar domdomuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Wiki-Toolkit-Plugin-Categoriser-0.08/Makefile.PL0000644000175000017500000000074711271076257017602 0ustar domdomuse ExtUtils::MakeMaker; WriteMakefile( (MM->can('signature_target') ? (SIGN => 1) : ()), NAME => "Wiki::Toolkit::Plugin::Categoriser", VERSION_FROM => "lib/Wiki/Toolkit/Plugin/Categoriser.pm", PREREQ_PM => { 'Wiki::Toolkit' => 0, 'Test::More' => 0, 'Carp' => 0 }, clean => { FILES => "t/sqlite-test.db t/sii-db-file-test.db" } ); Wiki-Toolkit-Plugin-Categoriser-0.08/lib/0002755000175000017500000000000011271076305016362 5ustar domdomWiki-Toolkit-Plugin-Categoriser-0.08/lib/Wiki/0002755000175000017500000000000011271076305017265 5ustar domdomWiki-Toolkit-Plugin-Categoriser-0.08/lib/Wiki/Toolkit/0002755000175000017500000000000011271076305020712 5ustar domdomWiki-Toolkit-Plugin-Categoriser-0.08/lib/Wiki/Toolkit/Plugin/0002755000175000017500000000000011271076305022150 5ustar domdomWiki-Toolkit-Plugin-Categoriser-0.08/lib/Wiki/Toolkit/Plugin/Categoriser.pm0000644000175000017500000001144611271076257024767 0ustar domdompackage Wiki::Toolkit::Plugin::Categoriser; use strict; use Wiki::Toolkit::Plugin; use vars qw( $VERSION @ISA ); $VERSION = '0.08'; @ISA = qw( Wiki::Toolkit::Plugin ); =head1 NAME Wiki::Toolkit::Plugin::Categoriser - Category management for Wiki::Toolkit. =head1 DESCRIPTION Uses node metadata to build a model of how nodes are related to each other in terms of categories. =head1 SYNOPSIS 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" ); =head1 METHODS =over 4 =item B my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; $wiki->register_plugin( plugin => $categoriser ); =cut sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } =item B 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 B, so C is the same category as C. I might do something to make it plural-insensitive at some point too. =cut sub in_category { my ($self, %args) = @_; my @catarr = $self->categories( node => $args{node} ); my %categories = map { lc($_) => 1 } @catarr; return $categories{lc($args{category})}; } =item B $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 to a given category C, write a node called any one of C, C, or C with metadata indicating that it's in categories C and C. Yes, this pays specific attention to the Wiki convention of defining categories by prefacing the category name with 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. =cut sub subcategories { my ($self, %args) = @_; return () unless $args{category}; my $datastore = $self->datastore; my %cats = map { $_ => 1 } $datastore->list_nodes_by_metadata( metadata_type => "category", metadata_value => "Category" ); my @in_cat = $datastore->list_nodes_by_metadata( metadata_type => "category", metadata_value => $args{category} ); return map { s/^Category\s+//; $_ } grep { $cats{$_} } @in_cat; } =item B my @cats = $categoriser->categories( node => "Holborn Station" ); Returns an array of category names in no particular order. =cut sub categories { my ($self, %args) = @_; my $dbh = $self->datastore->dbh; my $sth = $dbh->prepare( "SELECT metadata_value FROM node INNER JOIN metadata ON ( node.id = metadata.node_id AND node.version = metadata.version ) WHERE name = ? AND metadata_type = 'category'" ); $sth->execute( $args{node} ); my @categories; while ( my ($cat) = $sth->fetchrow_array ) { push @categories, $cat; } return @categories; } =back =head1 SEE ALSO =over 4 =item * L =item * L =back =head1 AUTHOR Kake Pugh (kake@earth.li). The Wiki::Toolkit team (http://www.wiki-toolkit.org/) =head1 COPYRIGHT 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. =cut 1;