Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/MetaCPAN/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'] };

Expand All @@ -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<Search::Elasticsearch> client configured for use with the
MetaCPAN API endpoint.

=head1 ENVIRONMENT

=over 4

=item C<METACPAN_EXAMPLES_DEBUG>

When set to C<1>, enables output of verbose debugging information.

=back

=cut