summaryrefslogtreecommitdiff
path: root/scripts/Dpkg
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2017-07-15 15:21:33 +0200
committerGuillem Jover <guillem@debian.org>2017-09-24 21:03:09 +0200
commit5ea09cee634e4fe0cfac726937ccd2be81c272e8 (patch)
treedad072d56a64932f53733d79aaf5a22f153c3e0c /scripts/Dpkg
parent8829502bfc75a74b1539634bb3ca1f801589c0ff (diff)
downloaddpkg-5ea09cee634e4fe0cfac726937ccd2be81c272e8.tar.gz
Dpkg::ErrorHandling: Move color setup into report_pretty
Call setup_color() only if we are going to print something, so that we remove code executed at import time.
Diffstat (limited to 'scripts/Dpkg')
-rw-r--r--scripts/Dpkg/ErrorHandling.pm7
1 files changed, 4 insertions, 3 deletions
diff --git a/scripts/Dpkg/ErrorHandling.pm b/scripts/Dpkg/ErrorHandling.pm
index b1f5ed0a2..a5b549f62 100644
--- a/scripts/Dpkg/ErrorHandling.pm
+++ b/scripts/Dpkg/ErrorHandling.pm
@@ -15,6 +15,7 @@ package Dpkg::ErrorHandling;
use strict;
use warnings;
+use feature qw(state);
our $VERSION = '0.02';
our @EXPORT_OK = qw(
@@ -52,11 +53,11 @@ use Dpkg::Gettext;
my $quiet_warnings = 0;
my $debug_level = 0;
my $info_fh = \*STDOUT;
-my $use_color = 0;
sub setup_color
{
my $mode = $ENV{'DPKG_COLORS'} // 'auto';
+ my $use_color;
if ($mode eq 'auto') {
## no critic (InputOutput::ProhibitInteractiveTest)
@@ -70,8 +71,6 @@ sub setup_color
require Term::ANSIColor if $use_color;
}
-setup_color();
-
use constant {
REPORT_PROGNAME => 1,
REPORT_COMMAND => 2,
@@ -153,6 +152,8 @@ sub report_pretty
{
my ($msg, $color) = @_;
+ state $use_color = setup_color();
+
if ($use_color) {
return Term::ANSIColor::colored($msg, $color);
} else {