From 2e52637b517688f6be2bf6560a995361b85423da Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 22 Jul 2010 15:30:07 +0200 Subject: [PATCH] Configure: Better reporting of test results Test() now reports preset values differently from auto-detected ones. Added TestBool() which translates 1->yes and 0->no in log messages. --- ucw/perl/UCW/Configure.pm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ucw/perl/UCW/Configure.pm b/ucw/perl/UCW/Configure.pm index 958a0842..5d458adb 100644 --- a/ucw/perl/UCW/Configure.pm +++ b/ucw/perl/UCW/Configure.pm @@ -1,6 +1,6 @@ # Perl module for UCW Configure Scripts # -# (c) 2005--2008 Martin Mares +# (c) 2005--2010 Martin Mares # # This software may be freely distributed and used according to the terms # of the GNU Lesser General Public License. @@ -16,7 +16,7 @@ BEGIN { our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.0; @ISA = qw(Exporter); - @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &IsGiven &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile &DebugDump &PostConfig &AtWrite); + @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &IsGiven &Set &UnSet &Append &Override &Get &Test &TestBool &Include &Finish &FindFile &TryFindFile &DebugDump &PostConfig &AtWrite); @EXPORT_OK = qw(); %EXPORT_TAGS = (); } @@ -89,10 +89,25 @@ sub Override($;$) { sub Test($$$) { my ($var,$msg,$sub) = @_; Log "$msg ... "; - if (!IsSet($var)) { - Set $var, &$sub(); + if (IsSet($var)) { + Log Get($var) . " (preset)\n"; + } else { + my $val = &$sub(); + Set($var, $val); + Log "$val\n"; + } +} + +sub TestBool($$$) { + my ($var,$msg,$sub) = @_; + Log "$msg ... "; + if (IsSet($var) || IsGiven($var)) { + Log ((Get($var) ? "yes" : "no") . " (set)\n"); + } else { + my ($val, $comment) = &$sub(); + Set($var, $val); + Log (($val ? "yes" : "no") . "\n"); } - Log Get($var) . "\n"; } sub TryFindFile($) { -- 2.39.2