use module_available instead of eval { require } to avoid triggering
the __DIE__ handler
mschilli
20 years ago
5 | 5 | use strict; |
6 | 6 | use warnings; |
7 | 7 | use Carp; |
8 | use Log::Log4perl::Util; | |
8 | 9 | use Log::Log4perl::Level; |
9 | 10 | use Log::Log4perl::DateFormat; |
10 | 11 | use Log::Log4perl::NDC; |
26 | 27 | # just set a flag so we know later on that we can't have fine-grained |
27 | 28 | # time stamps |
28 | 29 | $TIME_HIRES_AVAILABLE = 0; |
29 | eval { require Time::HiRes; }; | |
30 | if($@) { | |
31 | $PROGRAM_START_TIME = time(); | |
32 | } else { | |
30 | if(Log::Log4perl::Util::module_available("Time::HiRes")) { | |
31 | require Time::HiRes; | |
33 | 32 | $TIME_HIRES_AVAILABLE = 1; |
34 | 33 | $PROGRAM_START_TIME = [Time::HiRes::gettimeofday()]; |
34 | } else { | |
35 | $PROGRAM_START_TIME = time(); | |
35 | 36 | } |
36 | 37 | |
37 | 38 | # Check if we've got Sys::Hostname. If not, just punt. |
38 | 39 | $HOSTNAME = "unknown.host"; |
39 | eval { require Sys::Hostname; }; | |
40 | $HOSTNAME = Sys::Hostname::hostname() unless $@; | |
40 | if(Log::Log4perl::Util::module_available("Sys::Hostname")) { | |
41 | require Sys::Hostname; | |
42 | $HOSTNAME = Sys::Hostname::hostname(); | |
43 | } | |
41 | 44 | } |
42 | 45 | |
43 | 46 | ################################################## |