From 0d72c55d125e399044812b52df01929239edc03e Mon Sep 17 00:00:00 2001 From: Hugo van der Sanden Date: Tue, 4 Mar 1997 11:32:11 +0000 Subject: Benchmark: using code refs It often irritates me that I can't supply a coderef to the Benchmark:: routines: here's a small patch to allow them. p5p-msgid: 199703041132.LAA07613@tyree.iii.co.uk --- lib/Benchmark.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/Benchmark.pm') diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index c382fcb1c4..ee7cf74cc3 100644 --- a/lib/Benchmark.pm +++ b/lib/Benchmark.pm @@ -329,7 +329,9 @@ sub runloop { last if $pack ne $curpack; } - my $subcode = "sub { package $pack; my(\$_i)=$n; while (\$_i--){$c;} }"; + my $subcode = (ref $c eq 'CODE') + ? "sub { package $pack; my(\$_i)=$n; while (\$_i--){&\$c;} }" + : "sub { package $pack; my(\$_i)=$n; while (\$_i--){$c;} }"; my $subref = eval $subcode; croak "runloop unable to compile '$c': $@\ncode: $subcode\n" if $@; print STDERR "runloop $n '$subcode'\n" if ($debug); -- cgit v1.2.1