| 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.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 12 |
our ($plugin_directory, @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 |
## Obsolete |
| 28 |
sub magic_and_content ($$) { |
| 29 |
my ($magic, $page) = ('', $_[1]); |
| 30 |
$magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; |
| 31 |
($magic, $page); |
| 32 |
} |
| 33 |
|
| 34 |
## Obsolete |
| 35 |
sub feature ($$;%) { |
| 36 |
my ($o, $package, %o) = @_; |
| 37 |
no strict 'refs'; |
| 38 |
if (${$package . '::VERSION'}) { |
| 39 |
caller (1)->import if $o{use}; |
| 40 |
return 1; |
| 41 |
} else { |
| 42 |
if (eval qq{require $package}) { |
| 43 |
caller (1)->import if $o{use}; |
| 44 |
return 1; |
| 45 |
} else { |
| 46 |
return 0; |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
{my %Formatter; |
| 52 |
sub formatter ($$) { |
| 53 |
my $t = $_[1]; $t =~ tr/-/_/; |
| 54 |
unless ($Formatter{$t}) { |
| 55 |
$Formatter{$t} = new SuikaWiki::Plugin::xml_formatter |
| 56 |
-category_name => $t; |
| 57 |
} |
| 58 |
return $Formatter{$t}; |
| 59 |
}} |
| 60 |
|
| 61 |
## Obsolete |
| 62 |
sub db ($) { |
| 63 |
## TODO: common interface to WikiDB |
| 64 |
$main::WIKI->{db}; |
| 65 |
} |
| 66 |
|
| 67 |
sub module_package ($$) { |
| 68 |
my ($self, $module) = @_; |
| 69 |
my $pack = $SuikaWiki::Plugin::Registry::Info{$module}->{module_name}; |
| 70 |
if ($pack) { |
| 71 |
return $pack; |
| 72 |
} else { |
| 73 |
## TODO: throw |
| 74 |
die "Module $module not loaded"; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
## Obsolete |
| 79 |
sub set_data ($$$$;%) { |
| 80 |
my ($self, $prop, $key, $data, %opt) = @_; |
| 81 |
## TODO: common interface to WikiDB |
| 82 |
## TODO: error recovering |
| 83 |
$main::WIKI->{db}->set ($prop => $key => $data); |
| 84 |
if ($opt{-touch}) { |
| 85 |
$main::WIKI->{db}->set (lastmodified => $key => time); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
## Obsolete |
| 90 |
sub get_data ($$$$;%) { |
| 91 |
my ($self, $prop, $key, %opt) = @_; |
| 92 |
## TODO: common interface to WikiDB |
| 93 |
## TODO: error recovering |
| 94 |
$main::WIKI->{db}->get ($prop => $key); |
| 95 |
} |
| 96 |
|
| 97 |
=head1 PLUGIN MANAGER |
| 98 |
|
| 99 |
=over 4 |
| 100 |
|
| 101 |
=item SuikaWiki::Plugin->import_plugins |
| 102 |
|
| 103 |
Searchs plugins into $plugin_directory and loads all plugins found. |
| 104 |
This method should be called at least one time before plugin-required-features |
| 105 |
are used. |
| 106 |
|
| 107 |
=cut |
| 108 |
|
| 109 |
sub import_plugins ($) { |
| 110 |
my @plugins; |
| 111 |
for my $dir ($plugin_directory, @plugin_directory) { |
| 112 |
opendir PDIR, $dir; |
| 113 |
push @plugins, map {[$_, $dir.'/'.$_.'.pm']} grep {s/\.pm$//} readdir (PDIR); |
| 114 |
closedir PDIR; |
| 115 |
} |
| 116 |
for my $plugin (@plugins) { |
| 117 |
unless ($plugin->[0] =~ /[^A-Za-z0-9_]/) { |
| 118 |
eval qq{ require \$plugin->[1]; SuikaWiki::Plugin::$plugin->[0]\->import; 1 } or die $@; |
| 119 |
push @{$List{_all}}, qq(SuikaWiki::Plugin::$plugin->[0]); |
| 120 |
} |
| 121 |
} |
| 122 |
## callback (onLoad) |
| 123 |
for (@{$On{Load}||[]}) { |
| 124 |
&{$_}; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
=item SuikaWiki::Plugin::regist ($plugin_package, @categories) |
| 129 |
|
| 130 |
Regists the plugin categories provided by the plugin package. |
| 131 |
This method should be called from plugin packages. |
| 132 |
|
| 133 |
Example: |
| 134 |
|
| 135 |
sub import { |
| 136 |
my $self = shift; |
| 137 |
$self->SuikaWiki::Plugin::regist (qw/wikiform_input/); |
| 138 |
} |
| 139 |
|
| 140 |
=cut |
| 141 |
|
| 142 |
sub regist ($@) { |
| 143 |
my $pack = shift; |
| 144 |
for (@_) { |
| 145 |
push @{$List{$_}}, $pack; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
=back |
| 150 |
|
| 151 |
=head1 WIKIPLUGIN MANAGER OBJECT |
| 152 |
|
| 153 |
This part implements WikiPlugin manager object of SuikaWiki WikiPlugin |
| 154 |
implementation model, second edition. |
| 155 |
|
| 156 |
=over 4 |
| 157 |
|
| 158 |
=item $p = SuikaWiki::Plugin->new (wiki => $WIKI) |
| 159 |
|
| 160 |
Constructs new instance of WikiPlugin manager |
| 161 |
|
| 162 |
=cut |
| 163 |
|
| 164 |
sub new ($%) { |
| 165 |
my $class = shift; |
| 166 |
my $self = bless {@_}, $class; |
| 167 |
|
| 168 |
$self; |
| 169 |
} |
| 170 |
|
| 171 |
=item $p->use_type ($type) |
| 172 |
|
| 173 |
Declares rules classified as $type is to be used. |
| 174 |
Even in current implementation this method makes no meaning, |
| 175 |
plugin callers must declare by this method for future compatibility. |
| 176 |
|
| 177 |
=cut |
| 178 |
|
| 179 |
sub use_type ($$) { |
| 180 |
#my ($self, $type) = @_; |
| 181 |
} |
| 182 |
|
| 183 |
=item $p->{rule}->{ $type }->{ $name } = { plugin rule definition } |
| 184 |
|
| 185 |
WikiPlugin rule |
| 186 |
|
| 187 |
@@TBD@@ |
| 188 |
|
| 189 |
=item $p->{wiki} |
| 190 |
|
| 191 |
Wiki implementation $p is associated with |
| 192 |
|
| 193 |
=back |
| 194 |
|
| 195 |
=cut |
| 196 |
|
| 197 |
package SuikaWiki::Plugin::xml_formatter; |
| 198 |
require Message::Util::Formatter::Node; |
| 199 |
our @ISA = 'Message::Util::Formatter::Node'; |
| 200 |
require Message::Markup::XML::Node; |
| 201 |
|
| 202 |
sub rule_def ($) { |
| 203 |
$SuikaWiki::Plugin::Rule{$_[0]->{-category_name}}; |
| 204 |
} |
| 205 |
|
| 206 |
sub replace_option ($) { |
| 207 |
return { |
| 208 |
-class => 'Message::Markup::XML::Node', |
| 209 |
}; |
| 210 |
} |
| 211 |
|
| 212 |
=head1 SEE ALSO |
| 213 |
|
| 214 |
suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki> |
| 215 |
|
| 216 |
=head1 LICENSE |
| 217 |
|
| 218 |
Copyright 2002-2003 Wakaba <[email protected]> |
| 219 |
|
| 220 |
This program is free software; you can redistribute it and/or |
| 221 |
modify it under the same terms as Perl itself. |
| 222 |
|
| 223 |
=cut |
| 224 |
|
| 225 |
1; # $Date: 2003/10/18 07:08:34 $ |