| 1 |
# -*- perl -*- |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
SuikaWiki::Plugin --- SuikaWiki: Plugin manager and the interface to the Wiki database from plugins |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package SuikaWiki::Plugin; |
| 10 |
use strict; |
| 11 |
our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 12 |
our ($plugin_directory, %List, %Index, %Cache, %On); |
| 13 |
push @main::INC, $plugin_directory.'/../..'; |
| 14 |
|
| 15 |
=head1 PLUGIN INTERFACE |
| 16 |
|
| 17 |
=over 4 |
| 18 |
|
| 19 |
=item $o->new_index ($index_name) |
| 20 |
|
| 21 |
Increments the index number and returns the new index number. |
| 22 |
|
| 23 |
=cut |
| 24 |
|
| 25 |
sub new_index ($$) { ++$Index{$_[1]} } |
| 26 |
|
| 27 |
=item $o->magic_and_conten ($document) |
| 28 |
|
| 29 |
Splits the documents into the magic line and content part. |
| 30 |
|
| 31 |
=cut |
| 32 |
|
| 33 |
sub magic_and_content ($$) { |
| 34 |
my ($magic, $page) = ('', $_[1]); |
| 35 |
$magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; |
| 36 |
($magic, $page); |
| 37 |
} |
| 38 |
|
| 39 |
=item $o->feature ($package_name) |
| 40 |
|
| 41 |
Returns whether the feature is enabled or not. |
| 42 |
If the feature is usable but not loaded, it is loaded and C<1> is returned. |
| 43 |
|
| 44 |
=cut |
| 45 |
|
| 46 |
sub feature ($$;%) { |
| 47 |
my ($o, $package, %o) = @_; |
| 48 |
no strict 'refs'; |
| 49 |
if (${$package . '::VERSION'}) { |
| 50 |
caller (1)->import if $o{use}; |
| 51 |
return 1; |
| 52 |
} else { |
| 53 |
if (eval qq{require $package}) { |
| 54 |
caller (1)->import if $o{use}; |
| 55 |
return 1; |
| 56 |
} else { |
| 57 |
return 0; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
=head1 PLUGIN MANAGER |
| 63 |
|
| 64 |
=over 4 |
| 65 |
|
| 66 |
=item SuikaWiki::Plugin::import_plugins |
| 67 |
|
| 68 |
Searchs plugins into $plugin_directory and loads all plugins found. |
| 69 |
This method should be called at least one time before plugin-required-features |
| 70 |
are used. |
| 71 |
|
| 72 |
=cut |
| 73 |
|
| 74 |
sub import_plugins () { |
| 75 |
opendir PDIR, $plugin_directory; |
| 76 |
my @plugin = grep {s/\.pm$//} readdir (PDIR); |
| 77 |
closedir PDIR; |
| 78 |
for (@plugin) { |
| 79 |
eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/; |
| 80 |
push @{$List{_all}}, qq(SuikaWiki::Plugin::$_); |
| 81 |
} |
| 82 |
# callback (onLoad) |
| 83 |
for (@{$On{Load}||[]}) { |
| 84 |
&{$_}; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
=item SuikaWiki::Plugin::regist ($plugin_package, @categories) |
| 89 |
|
| 90 |
Regists the plugin categories provided by the plugin package. |
| 91 |
This method should be called from plugin packages. |
| 92 |
|
| 93 |
Example: |
| 94 |
|
| 95 |
sub import { |
| 96 |
my $self = shift; |
| 97 |
$self->SuikaWiki::Plugin::regist (qw/wikiform_input/); |
| 98 |
} |
| 99 |
|
| 100 |
=cut |
| 101 |
|
| 102 |
sub regist ($@) { |
| 103 |
my $pack = shift; |
| 104 |
for (@_) { |
| 105 |
push @{$List{$_}}, $pack; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
=back |
| 110 |
|
| 111 |
=head1 SEE ALSO |
| 112 |
|
| 113 |
suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki> |
| 114 |
|
| 115 |
=head1 LICENSE |
| 116 |
|
| 117 |
Copyright 2002-2003 Wakaba <[email protected]> |
| 118 |
|
| 119 |
This program is free software; you can redistribute it and/or |
| 120 |
modify it under the same terms as Perl itself. |
| 121 |
|
| 122 |
=cut |
| 123 |
|
| 124 |
1; # $Date: 2003/04/27 11:45:59 $ |