/[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.10 - (hide annotations) (download)
Sat Dec 6 02:20:58 2003 UTC (21 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.9: +116 -41 lines
SuikaWiki::Plugin::error: New package

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.10 our $VERSION = do{my @r=(q$Revision: 1.9 $=~/\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     =item $p->{wiki}
136    
137     Wiki implementation $p is associated with
138    
139     =back
140    
141 wakaba 1.8 =cut
142    
143     package SuikaWiki::Plugin::xml_formatter;
144     require Message::Util::Formatter::Node;
145     our @ISA = 'Message::Util::Formatter::Node';
146     require Message::Markup::XML::Node;
147    
148     sub rule_def ($) {
149     $SuikaWiki::Plugin::Rule{$_[0]->{-category_name}};
150     }
151    
152 wakaba 1.10 sub replace_option () {+{
153 wakaba 1.8 -class => 'Message::Markup::XML::Node',
154 wakaba 1.10 }}
155    
156     package SuikaWiki::Plugin::error;
157     require Message::Util::Error;
158     our @ISA = 'Message::Util::Error';
159    
160     =head1 EXCEPTIONS
161    
162     =over 4
163    
164     =item PLUGIN_COMPILE_ERROR
165    
166     Something wrong while loading WikiPlugin module file C<file>,
167     because of C<message>.
168    
169     =item PLUGIN_DIRECTORY_CANT_OPEN
170    
171     WikiPlugin directory C<file> cannot be opened, because of C<message>.
172    
173     =item PLUGIN_NOT_FOUND
174    
175     WikiPlugin module C<module> not found.
176    
177     =cut
178    
179     sub ___errors () {+{
180     PLUGIN_COMPILE_ERROR => {
181     description => q(%t(name => method);: %t(name => file);: %t(name => message);),
182     },
183     PLUGIN_DIRECTORY_CANT_OPEN => {
184     description => q(%t(name => method);: %t(name => file);: %t(name => message);),
185     },
186     PLUGIN_NOT_FOUND => {
187     description => q(%t(name => method);: WikiPlugin module "%t(name => module);" not loaded),
188     },
189     }}
190    
191     =back
192 wakaba 1.8
193 wakaba 1.1 =head1 SEE ALSO
194    
195 wakaba 1.10 <IW:SuikaWiki:SuikaWiki:WikiPlugin>
196    
197     C<lib/SuikaWiki/Plugin/*>,
198     C<misc/pluging/*>
199 wakaba 1.1
200     =head1 LICENSE
201    
202     Copyright 2002-2003 Wakaba <w@suika.fam.cx>
203    
204     This program is free software; you can redistribute it and/or
205     modify it under the same terms as Perl itself.
206    
207     =cut
208    
209 wakaba 1.10 1; # $Date: 2003/12/01 07:43:35 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24