/[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.13 - (hide annotations) (download)
Sun Feb 1 12:23:24 2004 UTC (21 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.12: +3 -17 lines
(new_index): Removed

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24