/[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.2 - (hide annotations) (download)
Sun Apr 27 11:45:59 2003 UTC (22 years ago) by wakaba
Branch: MAIN
Changes since 1.1: +25 -2 lines
Markup: New.

1 wakaba 1.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 wakaba 1.2 our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
12 wakaba 1.1 our ($plugin_directory, %List, %Index, %Cache);
13     push @main::INC, $plugin_directory.'/../..';
14    
15     =head1 PLUGIN INTERFACE
16    
17     =over 4
18    
19     =item $o->new_index ($index_name)
20    
21     Increments the index number and returns the new index number.
22    
23     =cut
24    
25     sub new_index ($$) { ++$Index{$_[1]} }
26    
27     =item $o->magic_and_conten ($document)
28    
29     Splits the documents into the magic line and content part.
30    
31     =cut
32    
33     sub magic_and_content ($$) {
34     my ($magic, $page) = ('', $_[1]);
35     $magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s;
36     ($magic, $page);
37     }
38    
39 wakaba 1.2 =item $o->feature ($package_name)
40    
41     Returns whether the feature is enabled or not.
42     If the feature is usable but not loaded, it is loaded and C<1> is returned.
43    
44     =cut
45    
46     sub feature ($$;%) {
47     my ($o, $package, %o) = @_;
48     no strict 'refs';
49     if (${$package . '::VERSION'}) {
50     caller (1)->import if $o{use};
51     return 1;
52     } else {
53     if (eval qq{require $package}) {
54     caller (1)->import if $o{use};
55     return 1;
56     } else {
57     return 0;
58     }
59     }
60     }
61    
62 wakaba 1.1 =head1 PLUGIN MANAGER
63    
64     =over 4
65    
66     =item SuikaWiki::Plugin::import_plugins
67    
68     Searchs plugins into $plugin_directory and loads all plugins found.
69     This method should be called at least one time before plugin-required-features
70     are used.
71    
72     =cut
73    
74     sub import_plugins () {
75     opendir PDIR, $plugin_directory;
76     my @plugin = grep {s/\.pm$//} readdir (PDIR);
77     closedir PDIR;
78     for (@plugin) {
79     eval qq{ use SuikaWiki::Plugin::$_ } unless /[^A-Za-z0-9_]/;
80     push @{$List{_all}}, qq(SuikaWiki::Plugin::$_);
81     }
82     }
83    
84     =item SuikaWiki::Plugin::regist ($plugin_package, @categories)
85    
86     Regists the plugin categories provided by the plugin package.
87     This method should be called from plugin packages.
88    
89     Example:
90    
91     sub import {
92     my $self = shift;
93     $self->SuikaWiki::Plugin::regist (qw/wikiform_input/);
94     }
95    
96     =cut
97    
98     sub regist ($@) {
99     my $pack = shift;
100     for (@_) {
101     push @{$List{$_}}, $pack;
102     }
103     }
104    
105     =back
106    
107     =head1 SEE ALSO
108    
109     suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki>
110    
111     =head1 LICENSE
112    
113     Copyright 2002-2003 Wakaba <w@suika.fam.cx>
114    
115     This program is free software; you can redistribute it and/or
116     modify it under the same terms as Perl itself.
117    
118     =cut
119    
120 wakaba 1.2 1; # $Date: 2003/04/03 01:08:16 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24  
Google Analytics is used in this page; Cookies are used. 忍者AdMax is used in this page; Cookies are used. Privacy policy.