/[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.5 - (show annotations) (download)
Thu Jul 17 23:58:41 2003 UTC (23 years, 1 month ago) by w
Branch: MAIN
Branch point for: branch-suikawiki-1
Changes since 1.4: +23 -7 lines
*** empty log message ***

1 # -*- perl -*-
2
3 =head1 NAME
4
5 SuikaWiki::Plugin --- SuikaWiki: Plugin manager and the interface to the Wiki database from plugins
6
7 =cut
8
9 package SuikaWiki::Plugin;
10 use strict;
11 our $VERSION = do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
12 our ($plugin_directory, @plugin_directory, %List, %Index, %Cache, %On);
13 push @main::INC, $plugin_directory.'/../..';
14 require SuikaWiki::Markup::XML; ## Used by plugins
15
16 =head1 PLUGIN INTERFACE
17
18 =over 4
19
20 =item $o->new_index ($index_name)
21
22 Increments the index number and returns the new index number.
23
24 =cut
25
26 sub new_index ($$) { ++$Index{$_[1]} }
27
28 =item $o->magic_and_content ($document)
29
30 (DEPRECATED) Splits the documents into the magic line and content part.
31 Use SuikaWiki::SrcFormat.
32
33 =cut
34
35 sub magic_and_content ($$) {
36 my ($magic, $page) = ('', $_[1]);
37 $magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s;
38 ($magic, $page);
39 }
40
41 =item $o->feature ($package_name)
42
43 Returns whether the feature is enabled or not.
44 If the feature is usable but not loaded, it is loaded and C<1> is returned.
45
46 =cut
47
48 sub feature ($$;%) {
49 my ($o, $package, %o) = @_;
50 no strict 'refs';
51 if (${$package . '::VERSION'}) {
52 caller (1)->import if $o{use};
53 return 1;
54 } else {
55 if (eval qq{require $package}) {
56 caller (1)->import if $o{use};
57 return 1;
58 } else {
59 return 0;
60 }
61 }
62 }
63
64 {my %Formatter;
65 sub formatter ($$) {
66 my $t = $_[1]; $t =~ tr/-/_/;
67 unless ($Formatter{$t}) {
68 require Message::Util::Formatter;
69 $Formatter{$t} = Message::Util::Formatter->new;
70 for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) {
71 $_->load_formatter ($Formatter{$t}, type => 'wiki'.$t);
72 }
73 $Formatter{$t}->option (return_class => 'SuikaWiki::Markup::XML');
74 }
75 return $Formatter{$t};
76 }}
77
78 =head1 PLUGIN MANAGER
79
80 =over 4
81
82 =item SuikaWiki::Plugin->import_plugins
83
84 Searchs plugins into $plugin_directory and loads all plugins found.
85 This method should be called at least one time before plugin-required-features
86 are used.
87
88 =cut
89
90 sub import_plugins ($) {
91 my @plugins;
92 for my $dir ($plugin_directory, @plugin_directory) {
93 opendir PDIR, $dir;
94 push @plugins, map {[$_, $dir.'/'.$_.'.pm']} grep {s/\.pm$//} readdir (PDIR);
95 closedir PDIR;
96 }
97 for my $plugin (@plugins) {
98 unless ($plugin->[0] =~ /[^A-Za-z0-9_]/) {
99 eval qq{ require \$plugin->[1]; SuikaWiki::Plugin::$plugin->[0]\->import; 1 } or die $@;
100 push @{$List{_all}}, qq(SuikaWiki::Plugin::$plugin->[0]);
101 }
102 }
103 ## callback (onLoad)
104 for (@{$On{Load}||[]}) {
105 &{$_};
106 }
107 }
108
109 =item SuikaWiki::Plugin::regist ($plugin_package, @categories)
110
111 Regists the plugin categories provided by the plugin package.
112 This method should be called from plugin packages.
113
114 Example:
115
116 sub import {
117 my $self = shift;
118 $self->SuikaWiki::Plugin::regist (qw/wikiform_input/);
119 }
120
121 =cut
122
123 sub regist ($@) {
124 my $pack = shift;
125 for (@_) {
126 push @{$List{$_}}, $pack;
127 }
128 }
129
130 =back
131
132 =head1 SEE ALSO
133
134 suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki>
135
136 =head1 LICENSE
137
138 Copyright 2002-2003 Wakaba <[email protected]>
139
140 This program is free software; you can redistribute it and/or
141 modify it under the same terms as Perl itself.
142
143 =cut
144
145 1; # $Date: 2003/05/10 05:58:06 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24