/[pub]/suikawiki/script/lib/SuikaWiki/Plugin.pm
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download)
Thu Jun 3 06:38:48 2004 UTC (21 years, 1 month ago) by wakaba
Branch: MAIN
CVS Tags: release-3-0-0
Changes since 1.15: +7 -5 lines
Static output of stylesheet implemented; Use of simple HTML serializer (new to manakai) if text/html output

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24