summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo van der Sanden <hv@iii.co.uk>1997-03-04 11:32:11 +0000
committerChip Salzenberg <chip@atlantic.net>1997-03-01 18:40:49 +1200
commit54f70fc60d33628464c2f1f4a555eb6764959916 (patch)
treea89bf4280d7c1bea75c27d9b0b507fff6e6cae4b
parent24384a9180bedb10a3538c0d9619bf91ad703d62 (diff)
downloadperl-54f70fc60d33628464c2f1f4a555eb6764959916.tar.gz
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
-rw-r--r--lib/Benchmark.pm4
1 files changed, 3 insertions, 1 deletions
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);