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