+=head1 CLASS METHODS
+
+=head2 Config
+
+Returns the current L<config object RT::Config>, but note that
+you must L<load config /LoadConfig> first otherwise this method
+returns undef.
+
+Method can be called as class method.
+
+=cut
+
+sub Config { return $Config }
+
+=head2 DatabaseHandle
+
+Returns the current L<database handle object RT::Handle>.
+
+See also L</ConnectToDatabase>.
+
+=cut
+
+sub DatabaseHandle { return $Handle }
+
+=head2 Logger
+
+Returns the logger. See also L</InitLogging>.
+
+=cut
+
+sub Logger { return $Logger }
+
+=head2 System
+
+Returns the current L<system object RT::System>. See also
+L</InitSystemObjects>.
+
+=cut
+
+sub System { return $System }
+
+=head2 SystemUser
+
+Returns the system user's object, it's object of
+L<RT::CurrentUser> class that represents the system. See also
+L</InitSystemObjects>.
+
+=cut
+
+sub SystemUser { return $SystemUser }
+
+=head2 Nobody
+
+Returns object of Nobody. It's object of L<RT::CurrentUser> class
+that represents a user who can own ticket and nothing else. See
+also L</InitSystemObjects>.
+
+=cut
+
+sub Nobody { return $Nobody }
+
+=head2 Plugins
+
+Returns a listref of all Plugins currently configured for this RT instance.
+You can define plugins by adding them to the @Plugins list in your RT_SiteConfig
+
+=cut
+
+our @PLUGINS = ();
+sub Plugins {
+ my $self = shift;
+ unless (@PLUGINS) {
+ $self->InitPluginPaths;
+ @PLUGINS = $self->InitPlugins;
+ }
+ return \@PLUGINS;
+}
+
+=head2 PluginDirs
+
+Takes optional subdir (e.g. po, lib, etc.) and return plugins' dirs that exist.
+
+This code chacke plugins names or anything else and required when main config
+is loaded to load plugins' configs.
+
+=cut
+
+sub PluginDirs {
+ my $self = shift;
+ my $subdir = shift;
+
+ require RT::Plugin;
+
+ my @res;
+ foreach my $plugin (grep $_, RT->Config->Get('Plugins')) {
+ my $path = RT::Plugin->new( name => $plugin )->Path( $subdir );
+ next unless -d $path;
+ push @res, $path;
+ }
+ return @res;
+}
+
+=head2 InitPluginPaths
+
+Push plugins' lib paths into @INC right after F<local/lib>.
+In case F<local/lib> isn't in @INC, append them to @INC
+
+=cut
+
+sub InitPluginPaths {
+ my $self = shift || __PACKAGE__;
+
+ my @lib_dirs = $self->PluginDirs('lib');
+
+ my @tmp_inc;
+ my $added;
+ for (@INC) {
+ if ( Cwd::realpath($_) eq $RT::LocalLibPath) {
+ push @tmp_inc, $_, @lib_dirs;
+ $added = 1;
+ } else {
+ push @tmp_inc, $_;
+ }
+ }
+
+ # append @lib_dirs in case $RT::LocalLibPath isn't in @INC
+ push @tmp_inc, @lib_dirs unless $added;
+
+ my %seen;
+ @INC = grep !$seen{$_}++, @tmp_inc;
+}
+
+=head2 InitPlugins
+
+Initialze all Plugins found in the RT configuration file, setting up their lib and HTML::Mason component roots.
+
+=cut
+
+sub InitPlugins {
+ 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);
+ }
+ return @plugins;
+}
+
+
+sub InstallMode {
+ my $self = shift;
+ if (@_) {
+ $_INSTALL_MODE = shift;
+ if($_INSTALL_MODE) {
+ require RT::CurrentUser;
+ $SystemUser = RT::CurrentUser->new();
+ }
+ }
+ return $_INSTALL_MODE;
+}
+
+