Skip to content

Commit f2e875d

Browse files
peffgitster
authored andcommitted
t/perf: depend on perl JSON only when using --codespeed
Commit 05eb1c3 (perf/aggregate: implement codespeed JSON output, 2018-01-05) added a dependency on the perl JSON module to show output from aggregate.perl, but we only need it when the user asks for --codespeed output. While the module is pretty common, it's not part of the base system, and this dependency can get in the way of producing the default human-readable output. Let's bump the "use" down to a "require" in the code path that needs it, which will be interpreted at run-time instead of compile-time. People not using "--codespeed" won't even load the module, and anybody using it should see the same results (including the same perl error if they don't have it). Note that this skips the importing step, so we'll have to fully qualify our function call. We could accomplish the same thing in other ways. E.g., calling JSON->import() ourselves, or wrapping "use JSON" in an eval. Since there's only one such call, this seems like the least-magical way of doing it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14c0f8d commit f2e875d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

t/perf/aggregate.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use lib '../../perl/build/lib';
44
use strict;
55
use warnings;
6-
use JSON;
76
use Getopt::Long;
87
use Git;
98

@@ -342,7 +341,8 @@ sub print_codespeed_results {
342341
}
343342
}
344343

345-
print to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
344+
require JSON;
345+
print JSON::to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
346346
}
347347

348348
binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";

0 commit comments

Comments
 (0)