diff --git a/lib/Math/Round/Fair.pm b/lib/Math/Round/Fair.pm index 262b789..3136341 100644 --- a/lib/Math/Round/Fair.pm +++ b/lib/Math/Round/Fair.pm @@ -12,13 +12,15 @@ our $VERSION = '0.01_01'; our @EXPORT_OK = qw/round_fair round_adjacent/; -our $debug; BEGIN { + my $debug; + sub DEBUG { $debug } + $debug = $ENV{MATH_ROUND_FAIR_DEBUG} || 0; - use Devel::Assert $debug ? ('-all -verbose') : (); + use Devel::Assert DEBUG() ? ('-all -verbose') : (); # used in assertions - eval q{use Perl6::Junction 'none'} if $debug; + eval q{use Perl6::Junction 'none'} if DEBUG(); } @@ -230,8 +232,8 @@ sub _round_adjacent_core { # See bottom of file for proof of this property: assert($tslack + $eps >= $p0 * (1.0 - $p0)); - # wrapped in assert to make it a noop when $debug == 0 - assert(do { warn "TSLACK = $tslack\n" if $debug > 1; 1 }); + # wrapped in assert to make it a noop when DEBUG() == 0 + assert(do { warn "TSLACK = $tslack\n" if DEBUG() > 1; 1 }); if ( $tslack > $eps1 ) { $eps += 128.0 * $eps1 * $eps / $tslack; @@ -295,7 +297,7 @@ sub _adjust_input { sub _check_invariants { my ( $eps, $v, $fp ) = @_; - if ( $debug > 1 ) { + if ( DEBUG() > 1 ) { warn sprintf "%d %f\n", floor($_), $_ for @$fp; } diff --git a/t/01-round_fair.t b/t/01-round_fair.t index a4e011e..ac34e90 100644 --- a/t/01-round_fair.t +++ b/t/01-round_fair.t @@ -6,7 +6,7 @@ use List::Util qw/sum min max/; BEGIN { use_ok 'Math::Round::Fair', qw/round_fair/ } -ok $Math::Round::Fair::debug, 'assertions enabled for tests'; +ok Math::Round::Fair::DEBUG(), 'assertions enabled for tests'; my $to_allocate = 7; my @weights = (1) x 10; diff --git a/t/10-nearest.t b/t/10-nearest.t index 3c7d493..913743f 100644 --- a/t/10-nearest.t +++ b/t/10-nearest.t @@ -6,8 +6,8 @@ $^W=1; use Test; BEGIN { plan tests => 6, todo => [] } +BEGIN { $ENV{MATH_ROUND_FAIR_DEBUG} = 1 } use Math::Round::Fair qw(round_adjacent); -$Math::Round::Fair::debug = 1; srand(0); my @result = round_adjacent(); diff --git a/t/11-random.t b/t/11-random.t index 2221c92..aba1622 100644 --- a/t/11-random.t +++ b/t/11-random.t @@ -21,9 +21,9 @@ BEGIN { plan tests => $cases, todo => []; } +BEGIN { $ENV{MATH_ROUND_FAIR_DEBUG} = 0 } use Check_FairRound; use Math::Round::Fair; -$Math::Round::Fair::debug = 0; sub gen_test_case { my $n = rand(4)<1 ? 1 : (rand(3)<1 ? 2 : 1+int(rand(10))); diff --git a/t/12-random_big.t b/t/12-random_big.t index 7ff9e4b..758b612 100644 --- a/t/12-random_big.t +++ b/t/12-random_big.t @@ -21,9 +21,9 @@ BEGIN { plan tests => $cases, todo => []; } +BEGIN { $ENV{MATH_ROUND_FAIR_DEBUG} = 1 } use Check_FairRound; use Math::Round::Fair; -$Math::Round::Fair::debug = 1; sub gen_test_case { my $n = 5+int(rand(50)); diff --git a/t/99-pod_spelling.t b/t/99-pod_spelling.t index 0acfb2a..8e34ae3 100644 --- a/t/99-pod_spelling.t +++ b/t/99-pod_spelling.t @@ -18,4 +18,5 @@ all_pod_files_spelling_ok(); __DATA__ Marc Mims +runtime situ