[Rt-commit] r15871 - in rt/branches/3.999-DANGEROUS: lib
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue Sep 9 13:39:47 EDT 2008
Author: sunnavy
Date: Tue Sep 9 13:39:47 2008
New Revision: 15871
Modified:
rt/branches/3.999-DANGEROUS/ (props changed)
rt/branches/3.999-DANGEROUS/lib/RT.pm
Log:
r16560 at sunnavys-mb: sunnavy | 2008-09-10 00:05:00 +0800
merged latest plugin stuff in RT.pm from 3.8
Modified: rt/branches/3.999-DANGEROUS/lib/RT.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT.pm (original)
+++ rt/branches/3.999-DANGEROUS/lib/RT.pm Tue Sep 9 13:39:47 2008
@@ -263,46 +263,74 @@
sub plugins {
my $self = shift;
- @PLUGINS = $self->init_plugins unless (@PLUGINS);
+ unless (@PLUGINS) {
+ $self->init_plugin_paths;
+ @PLUGINS = $self->init_plugins;
+ }
return \@PLUGINS;
}
-=head2 init_plugins
+=head2 plugin_dirs
-Initialze all Plugins found in the RT configuration file, setting up their lib and HTML::Mason component roots.
+Takes optional subdir (e.g. po, lib, etc.) and return plugins' dirs that exist.
=cut
-sub init_plugins {
+sub plugin_dirs {
my $self = shift;
- my @plugins;
- use RT::Plugin;
- foreach my $plugin ( RT->config->get('Plugins') ) {
- next unless $plugin;
+ my $subdir = shift;
+
+ my @res;
+ foreach my $plugin (grep $_, RT->config->get('Plugins')) {
my $plugindir = $plugin;
$plugindir =~ s/::/-/g;
- unless ( -d $RT::LocalPluginPath . "/$plugindir" ) {
- Jifty->log->fatal("Plugin $plugindir not found in $RT::LocalPluginPath");
- }
+ my $path = $RT::LocalPluginPath. "/$plugindir";
+ $path .= "/$subdir" if defined $subdir && length $subdir;
+ next unless -d $path;
+ push @res, $path;
+ }
+ return @res;
+}
+
+=head2 init_plugin_paths
+
+Push plugins' lib paths into @INC right after F<local/lib>.
+
+=cut
- # Splice the plugin's lib dir into @INC;
- my @tmp_inc;
+sub init_plugin_paths {
+ my $self = shift || __PACKAGE__;
- for (@INC) {
- if ( $_ eq $RT::LocalLibPath ) {
- push @tmp_inc, $_, $RT::LocalPluginPath . "/$plugindir";
- } else {
- push @tmp_inc, $_;
- }
+ my @lib_dirs = $self->plugin_dirs('lib');
+
+ my @tmp_inc;
+ for (@INC) {
+ if ( Cwd::realpath($_) eq $RT::LocalLibPath) {
+ push @tmp_inc, $_, @lib_dirs;
+ } else {
+ push @tmp_inc, $_;
}
+ }
+ my %seen;
+ @INC = grep !$seen{$_}++, @tmp_inc;
+}
+
+=head2 init_plugins
+
+Initialze all Plugins found in the RT configuration file, setting up their lib and HTML::Mason component roots.
- @INC = @tmp_inc;
+=cut
+
+sub init_plugins {
+ my $self = shift;
+ my @plugins;
+ require RT::Plugin;
+ foreach my $plugin (grep $_, RT->config->get('Plugins')) {
$plugin->require;
die $UNIVERSAL::require::ERROR if ($UNIVERSAL::require::ERROR);
- push @plugins, RT::Plugin->new( name => $plugin );
+ push @plugins, RT::Plugin->new(name =>$plugin);
}
return @plugins;
-
}
sub install_mode {
@@ -340,4 +368,5 @@
=cut
+
1;
More information about the Rt-commit
mailing list