/[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.4 - (hide annotations) (download)
Sat May 10 05:58:06 2003 UTC (23 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +17 -12 lines
Rewrite import_plugins

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.4 our $VERSION = do{my @r=(q$Revision: 1.3 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
12     our ($plugin_directory, @plugin_directory, %List, %Index, %Cache, %On);
13 wakaba 1.1 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 wakaba 1.4 my @plugins;
76     for my $dir ($plugin_directory, @plugin_directory) {
77     opendir PDIR, $dir;
78     push @plugins, map {[$_, $dir.'/'.$_.'.pm']} grep {s/\.pm$//} readdir (PDIR);
79 wakaba 1.1 closedir PDIR;
80 wakaba 1.4 }
81     for my $plugin (@plugins) {
82     unless ($plugin->[0] =~ /[^A-Za-z0-9_]/) {
83     eval qq{ require \$plugin->[1]; SuikaWiki::Plugin::$plugin->[0]\->import };
84     push @{$List{_all}}, qq(SuikaWiki::Plugin::$plugin->[0]);
85 wakaba 1.3 }
86 wakaba 1.4 }
87     ## callback (onLoad)
88     for (@{$On{Load}||[]}) {
89     &{$_};
90     }
91 wakaba 1.1 }
92    
93     =item SuikaWiki::Plugin::regist ($plugin_package, @categories)
94    
95     Regists the plugin categories provided by the plugin package.
96     This method should be called from plugin packages.
97    
98     Example:
99    
100     sub import {
101     my $self = shift;
102     $self->SuikaWiki::Plugin::regist (qw/wikiform_input/);
103     }
104    
105     =cut
106    
107     sub regist ($@) {
108     my $pack = shift;
109     for (@_) {
110     push @{$List{$_}}, $pack;
111     }
112     }
113    
114     =back
115    
116     =head1 SEE ALSO
117    
118     suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki>
119    
120     =head1 LICENSE
121    
122     Copyright 2002-2003 Wakaba <[email protected]>
123    
124     This program is free software; you can redistribute it and/or
125     modify it under the same terms as Perl itself.
126    
127     =cut
128    
129 wakaba 1.4 1; # $Date: 2003/04/29 10:36:17 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24