From 54f70fc60d33628464c2f1f4a555eb6764959916 Mon Sep 17 00:00:00 2001 From: Hugo van der Sanden Date: Tue, 4 Mar 1997 11:32:11 +0000 Subject: [PATCH] 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(-) diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index c382fcb..ee7cf74 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); -- 2.7.4