# -*- perl -*- =head1 NAME SuikaWiki::Plugin --- SuikaWiki: Plugin manager and the interface to the Wiki database from plugins =cut package SuikaWiki::Plugin; use strict; our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; our ($plugin_directory, %List, %Index, %Cache); push @main::INC, $plugin_directory.'/../..'; =head1 PLUGIN INTERFACE =over 4 =item $o->new_index ($index_name) Increments the index number and returns the new index number. =cut sub new_index ($$) { ++$Index{$_[1]} } =item $o->magic_and_conten ($document) Splits the documents into the magic line and content part. =cut sub magic_and_content ($$) { my ($magic, $page) = ('', $_[1]); $magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; ($magic, $page); } =item $o->feature ($package_name) Returns whether the feature is enabled or not. If the feature is usable but not loaded, it is loaded and C<1> is returned. =cut sub feature ($$;%) { my ($o, $package, %o) = @_; no strict 'refs'; if (${$package . '::VERSION'}) { caller (1)->import if $o{use}; return 1; } else { if (eval qq{require $package}) { caller (1)->import if $o{use}; return 1; } else { return 0; } } } =head1 PLUGIN MANAGER =over 4 =item SuikaWiki::Plugin::import_plugins Searchs plugins into $plugin_directory and loads all plugins found. This method should be called at least one time before plugin-required-features are used. =cut sub import_plugins () { opendir PDIR, $plugin_directory; my @plugin = grep {s/\.pm$//} readdir (PDIR); closedir PDIR; for (@plugin) { eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/; push @{$List{_all}}, qq(SuikaWiki::Plugin::$_); } } =item SuikaWiki::Plugin::regist ($plugin_package, @categories) Regists the plugin categories provided by the plugin package. This method should be called from plugin packages. Example: sub import { my $self = shift; $self->SuikaWiki::Plugin::regist (qw/wikiform_input/); } =cut sub regist ($@) { my $pack = shift; for (@_) { push @{$List{$_}}, $pack; } } =back =head1 SEE ALSO suikawiki.pl, suikawiki-config.ph, =head1 LICENSE Copyright 2002-2003 Wakaba This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2003/04/27 11:45:59 $