Skip to content

Commit

Permalink
Hide $debug since it can only be set at compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
semifor committed Dec 8, 2010
1 parent ce9d5c0 commit cd190ba
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
14 changes: 8 additions & 6 deletions lib/Math/Round/Fair.pm
Expand Up @@ -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();
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion t/01-round_fair.t
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion t/10-nearest.t
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion t/11-random.t
Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion t/12-random_big.t
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions t/99-pod_spelling.t
Expand Up @@ -18,4 +18,5 @@ all_pod_files_spelling_ok();
__DATA__
Marc
Mims
runtime
situ

0 comments on commit cd190ba

Please sign in to comment.