X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT.pm;h=0f0c79a55facc3f5fd5efaa0c8dcbbbdb32b529d;hp=063f7f7199db1e1d2a1e64324ec1ce58693fefd5;hb=e9e0cf0989259b94d9758eceff448666a2e5a5cc;hpb=6686c29104e555ea23446fe1db330664fa110bc0 diff --git a/rt/lib/RT.pm b/rt/lib/RT.pm index 063f7f719..0f0c79a55 100644 --- a/rt/lib/RT.pm +++ b/rt/lib/RT.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -83,12 +83,56 @@ RT - Request Tracker =head1 SYNOPSIS -A fully featured request tracker package +A fully featured request tracker package. + +This documentation describes the point-of-entry for RT's Perl API. To learn +more about what RT is and what it can do for you, visit +L. =head1 DESCRIPTION =head2 INITIALIZATION +If you're using RT's Perl libraries, you need to initialize RT before using any +of the modules. + +You have the option of handling the timing of config loading and the actual +init sequence yourself with: + + use RT; + BEGIN { + RT->LoadConfig; + RT->Init; + } + +or you can let RT do it all: + + use RT -init; + +This second method is particular useful when writing one-liners to interact with RT: + + perl -MRT=-init -e '...' + +The first method is necessary if you need to delay or conditionalize +initialization or if you want to fiddle with C<< RT->Config >> between loading +the config files and initializing the RT environment. + +=cut + +{ + my $DID_IMPORT_INIT; + sub import { + my $class = shift; + my $action = shift || ''; + + if ($action eq "-init" and not $DID_IMPORT_INIT) { + $class->LoadConfig; + $class->Init; + $DID_IMPORT_INIT = 1; + } + } +} + =head2 LoadConfig Load RT's config file. First, the site configuration file @@ -137,6 +181,8 @@ up logging|/InitLogging>, and L. =cut sub Init { + shift if @_%2; # code is inconsistent about calling as method + my %args = (@_); CheckPerlRequirements(); @@ -145,8 +191,8 @@ sub Init { #Get a database connection ConnectToDatabase(); InitSystemObjects(); - InitClasses(); - InitLogging(); + InitClasses(%args); + InitLogging(%args); InitPlugins(); RT::I18N->Init; RT->Config->PostLoadCheck; @@ -174,6 +220,8 @@ Create the Logger object and set up signal handlers. sub InitLogging { + my %arg = @_; + # We have to set the record separator ($, man perlvar) # or Log::Dispatch starts getting # really pissy, as some other module we use unsets it. @@ -216,7 +264,7 @@ sub InitLogging { my ($package, $filename, $line) = caller($frame); $p{'message'} =~ s/(?:\r*\n)+$//; - return "[". gmtime(time) ."] [". $p{'level'} ."]: " + return "[$$] [". gmtime(time) ."] [". $p{'level'} ."]: " . $p{'message'} ." ($filename:$line)\n"; }; @@ -235,9 +283,9 @@ sub InitLogging { $p{message} =~ s/(?:\r*\n)+$//; if ($p{level} eq 'debug') { - return "$p{message}\n"; + return "[$$] $p{message} ($filename:$line)\n"; } else { - return "$p{message} ($filename:$line)\n"; + return "[$$] $p{message}\n"; } }; @@ -309,11 +357,24 @@ sub InitLogging { )); } } - InitSignalHandlers(); + InitSignalHandlers(%arg); +} + +{ # Work around bug in Log::Dispatch < 2.30, wherein the short forms + # of ->warn, ->err, and ->crit do not usefully propagate out, unlike + # ->warning, ->error, and ->critical + package Log::Dispatch; + no warnings 'redefine'; + sub warn { shift->warning(@_) } + sub err { shift->error(@_) } + sub crit { shift->critical(@_) } } sub InitSignalHandlers { + my %arg = @_; + return if $arg{'NoSignalHandlers'}; + # Signal handlers ## This is the default handling of warnings and die'ings in the code ## (including other used modules - maybe except for errors catched by @@ -329,6 +390,11 @@ sub InitSignalHandlers { unshift @_, $RT::Logger, qw(level warning message); goto &Log::Dispatch::log; } + # Return value is used only by RT::Test to filter warnings from + # reaching the Test::NoWarnings catcher. If Log::Dispatch::log() ever + # starts returning 'IGNORE', we'll need to switch to something more + # clever. I don't expect that to happen. + return 'IGNORE'; }; #When we call die, trap it and log->crit with the value of the die.