1 |
wakaba |
1.10 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
SuikaWiki::Plugin - SuikaWiki: WikiPlugin common interface |
4 |
|
|
|
5 |
|
|
=head1 DESCRIPTION |
6 |
|
|
|
7 |
|
|
This module provides WikiPlugin interface implementation. |
8 |
wakaba |
1.1 |
|
9 |
wakaba |
1.10 |
There are two interface: class methods collection and WikiPlugin object. |
10 |
|
|
Class methods collection provides some useful facilities to be |
11 |
|
|
called by WikiPlugin module and/or by contexts using WikiPlugin. |
12 |
wakaba |
1.1 |
|
13 |
wakaba |
1.10 |
This module is part of SuikaWiki. |
14 |
wakaba |
1.1 |
|
15 |
|
|
=cut |
16 |
|
|
|
17 |
|
|
package SuikaWiki::Plugin; |
18 |
|
|
use strict; |
19 |
wakaba |
1.11 |
our $VERSION = do{my @r=(q$Revision: 1.10 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
20 |
wakaba |
1.1 |
|
21 |
wakaba |
1.10 |
=head1 CLASS METHODS |
22 |
wakaba |
1.1 |
|
23 |
|
|
=over 4 |
24 |
|
|
|
25 |
wakaba |
1.10 |
=begin temp |
26 |
|
|
|
27 |
wakaba |
1.1 |
=item $o->new_index ($index_name) |
28 |
|
|
|
29 |
|
|
Increments the index number and returns the new index number. |
30 |
|
|
|
31 |
wakaba |
1.10 |
=end temp |
32 |
|
|
|
33 |
wakaba |
1.1 |
=cut |
34 |
|
|
|
35 |
wakaba |
1.10 |
## Should be obsolete? Need consideration |
36 |
wakaba |
1.9 |
{my %Index; |
37 |
wakaba |
1.1 |
sub new_index ($$) { ++$Index{$_[1]} } |
38 |
wakaba |
1.9 |
} |
39 |
wakaba |
1.1 |
|
40 |
wakaba |
1.10 |
=item $formatter = SuikaWiki::Plugin->formatter ($category_name) |
41 |
|
|
|
42 |
|
|
Returns an instance of formatter whose category (context) is |
43 |
|
|
$category_name. |
44 |
|
|
|
45 |
|
|
=cut |
46 |
wakaba |
1.1 |
|
47 |
w |
1.5 |
{my %Formatter; |
48 |
|
|
sub formatter ($$) { |
49 |
|
|
my $t = $_[1]; $t =~ tr/-/_/; |
50 |
wakaba |
1.7 |
unless ($Formatter{$t}) { |
51 |
wakaba |
1.8 |
$Formatter{$t} = new SuikaWiki::Plugin::xml_formatter |
52 |
|
|
-category_name => $t; |
53 |
wakaba |
1.7 |
} |
54 |
w |
1.5 |
return $Formatter{$t}; |
55 |
|
|
}} |
56 |
|
|
|
57 |
wakaba |
1.10 |
=item $package = SuikaWiki::Plugin->module_package ($plugin_name) |
58 |
|
|
|
59 |
|
|
Returns package name of the plugin module named $plugin_name. |
60 |
|
|
|
61 |
|
|
=cut |
62 |
|
|
|
63 |
wakaba |
1.8 |
sub module_package ($$) { |
64 |
|
|
my ($self, $module) = @_; |
65 |
|
|
my $pack = $SuikaWiki::Plugin::Registry::Info{$module}->{module_name}; |
66 |
|
|
if ($pack) { |
67 |
|
|
return $pack; |
68 |
|
|
} else { |
69 |
wakaba |
1.10 |
throw SuikaWiki::Plugin::error |
70 |
|
|
-type => 'PLUGIN_NOT_FOUND', |
71 |
|
|
module => $module, |
72 |
|
|
-object => $self, method => 'module_package'; |
73 |
wakaba |
1.8 |
} |
74 |
|
|
} |
75 |
|
|
|
76 |
wakaba |
1.10 |
=item SuikaWiki::Plugin->load_directory ($dir1, $dir2,...) |
77 |
|
|
|
78 |
|
|
Loads plugin modules in specified directories. |
79 |
|
|
|
80 |
|
|
=cut |
81 |
wakaba |
1.6 |
|
82 |
wakaba |
1.10 |
sub load_directory ($;@) { |
83 |
|
|
my $self = shift; |
84 |
|
|
for my $dir (@_) { |
85 |
|
|
opendir PDIR, $dir or throw SuikaWiki::Plugin::error |
86 |
|
|
-type => 'PLUGIN_DIRECTORY_CANT_OPEN', |
87 |
|
|
file => $dir, |
88 |
|
|
message => $!, |
89 |
|
|
-object => $self, method => 'load_directory'; |
90 |
|
|
for (grep {substr ($_, -3) eq '.pm'} readdir (PDIR)) { |
91 |
|
|
eval { require $dir.'/'.$_ }; |
92 |
|
|
if ($@) { |
93 |
|
|
throw SuikaWiki::Plugin::error |
94 |
|
|
-type => 'PLUGIN_COMPILE_ERROR', |
95 |
|
|
file => $dir.'/'.$_, |
96 |
|
|
message => $@, |
97 |
|
|
method => 'load_directory', -object => $self; |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
closedir PDIR; |
101 |
|
|
} |
102 |
wakaba |
1.1 |
} |
103 |
|
|
|
104 |
|
|
=back |
105 |
|
|
|
106 |
wakaba |
1.6 |
=head1 WIKIPLUGIN MANAGER OBJECT |
107 |
|
|
|
108 |
|
|
This part implements WikiPlugin manager object of SuikaWiki WikiPlugin |
109 |
|
|
implementation model, second edition. |
110 |
|
|
|
111 |
wakaba |
1.10 |
Note that class methods such as C<< ->load_directory >> |
112 |
|
|
and C<< ->formatter >> as also available as methods of WikiPlugin object, |
113 |
|
|
although result of those operation is still "global". |
114 |
|
|
|
115 |
|
|
WikiPlugin manager object is usually instantiated by C<init_plugins> |
116 |
|
|
method of Wiki implementation object (C<SuikaWiki::Implementation> module). |
117 |
|
|
|
118 |
|
|
$wiki = <SuikaWiki::Implementation instance>; |
119 |
|
|
$wiki->init_plugins; |
120 |
|
|
$plugin_manager = $wiki->{plugin}; |
121 |
|
|
|
122 |
wakaba |
1.6 |
=over 4 |
123 |
|
|
|
124 |
|
|
=item $p = SuikaWiki::Plugin->new (wiki => $WIKI) |
125 |
|
|
|
126 |
|
|
Constructs new instance of WikiPlugin manager |
127 |
|
|
|
128 |
|
|
=cut |
129 |
|
|
|
130 |
wakaba |
1.10 |
sub new ($;%) { |
131 |
wakaba |
1.6 |
my $class = shift; |
132 |
wakaba |
1.10 |
bless {@_}, $class; |
133 |
wakaba |
1.6 |
} |
134 |
|
|
|
135 |
wakaba |
1.11 |
sub exit ($) { |
136 |
|
|
my $self = shift; |
137 |
|
|
delete $self->{wiki}; |
138 |
|
|
$self->{exited} = 1; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
sub DESTROY ($) { |
142 |
|
|
my $self = shift; |
143 |
|
|
$self->exit unless $self->{exited}; |
144 |
|
|
} |
145 |
|
|
|
146 |
wakaba |
1.6 |
=item $p->{wiki} |
147 |
|
|
|
148 |
|
|
Wiki implementation $p is associated with |
149 |
|
|
|
150 |
|
|
=back |
151 |
|
|
|
152 |
wakaba |
1.8 |
=cut |
153 |
|
|
|
154 |
|
|
package SuikaWiki::Plugin::xml_formatter; |
155 |
|
|
require Message::Util::Formatter::Node; |
156 |
|
|
our @ISA = 'Message::Util::Formatter::Node'; |
157 |
|
|
require Message::Markup::XML::Node; |
158 |
|
|
|
159 |
wakaba |
1.11 |
sub ___rule_def ($) { |
160 |
wakaba |
1.8 |
$SuikaWiki::Plugin::Rule{$_[0]->{-category_name}}; |
161 |
|
|
} |
162 |
|
|
|
163 |
wakaba |
1.10 |
sub replace_option () {+{ |
164 |
wakaba |
1.8 |
-class => 'Message::Markup::XML::Node', |
165 |
wakaba |
1.10 |
}} |
166 |
|
|
|
167 |
|
|
package SuikaWiki::Plugin::error; |
168 |
|
|
require Message::Util::Error; |
169 |
|
|
our @ISA = 'Message::Util::Error'; |
170 |
|
|
|
171 |
|
|
=head1 EXCEPTIONS |
172 |
|
|
|
173 |
|
|
=over 4 |
174 |
|
|
|
175 |
|
|
=item PLUGIN_COMPILE_ERROR |
176 |
|
|
|
177 |
|
|
Something wrong while loading WikiPlugin module file C<file>, |
178 |
|
|
because of C<message>. |
179 |
|
|
|
180 |
|
|
=item PLUGIN_DIRECTORY_CANT_OPEN |
181 |
|
|
|
182 |
|
|
WikiPlugin directory C<file> cannot be opened, because of C<message>. |
183 |
|
|
|
184 |
|
|
=item PLUGIN_NOT_FOUND |
185 |
|
|
|
186 |
|
|
WikiPlugin module C<module> not found. |
187 |
|
|
|
188 |
|
|
=cut |
189 |
|
|
|
190 |
wakaba |
1.11 |
sub ___error_def () {+{ |
191 |
wakaba |
1.10 |
PLUGIN_COMPILE_ERROR => { |
192 |
|
|
description => q(%t(name => method);: %t(name => file);: %t(name => message);), |
193 |
|
|
}, |
194 |
|
|
PLUGIN_DIRECTORY_CANT_OPEN => { |
195 |
|
|
description => q(%t(name => method);: %t(name => file);: %t(name => message);), |
196 |
|
|
}, |
197 |
|
|
PLUGIN_NOT_FOUND => { |
198 |
|
|
description => q(%t(name => method);: WikiPlugin module "%t(name => module);" not loaded), |
199 |
|
|
}, |
200 |
|
|
}} |
201 |
|
|
|
202 |
|
|
=back |
203 |
wakaba |
1.8 |
|
204 |
wakaba |
1.1 |
=head1 SEE ALSO |
205 |
|
|
|
206 |
wakaba |
1.10 |
<IW:SuikaWiki:SuikaWiki:WikiPlugin> |
207 |
|
|
|
208 |
|
|
C<lib/SuikaWiki/Plugin/*>, |
209 |
|
|
C<misc/pluging/*> |
210 |
wakaba |
1.1 |
|
211 |
|
|
=head1 LICENSE |
212 |
|
|
|
213 |
|
|
Copyright 2002-2003 Wakaba <w@suika.fam.cx> |
214 |
|
|
|
215 |
|
|
This program is free software; you can redistribute it and/or |
216 |
|
|
modify it under the same terms as Perl itself. |
217 |
|
|
|
218 |
|
|
=cut |
219 |
|
|
|
220 |
wakaba |
1.11 |
1; # $Date: 2003/12/06 02:20:58 $ |