From 9f347c8746552777e7196667725242ea2f575d70 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Wed, 13 Jul 2022 23:26:49 -0400 Subject: [PATCH] Add debug flag $ENV{METACPAN_EXAMPLES_DEBUG} This makes the output less verbose by default. --- lib/MetaCPAN/Util.pm | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/MetaCPAN/Util.pm b/lib/MetaCPAN/Util.pm index 58983e4..e6905f4 100644 --- a/lib/MetaCPAN/Util.pm +++ b/lib/MetaCPAN/Util.pm @@ -3,6 +3,8 @@ package MetaCPAN::Util; use strict; use warnings; +use constant DEBUG => !!$ENV{METACPAN_EXAMPLES_DEBUG}; + use Search::Elasticsearch; use Sub::Exporter -setup => { exports => ['es'] }; @@ -12,8 +14,35 @@ sub es { cxn_pool => 'Static::NoPing', nodes => 'https://fastapi.metacpan.org/v1', send_get_body_as => 'POST', - trace_to => 'Stdout', + ( trace_to => 'Stdout' ) x !!(DEBUG), ); } 1; + +=head1 NAME + +MetaCPAN::Util - Utilities for accessing MetaCPAN + +=head1 DESCRIPTION + +Provides shared utility code for examples. + +=head1 FUNCTIONS + +=head2 es + +Returns a L client configured for use with the +MetaCPAN API endpoint. + +=head1 ENVIRONMENT + +=over 4 + +=item C + +When set to C<1>, enables output of verbose debugging information. + +=back + +=cut