/[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.12 - (hide annotations) (download)
Fri Jan 16 08:04:59 2004 UTC (21 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.11: +21 -4 lines
Plugin.pm (text_formatter): New

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24