Getopt-Pad
view release on metacpan or search on metacpan
examples/07-config.json view on Meta::CPAN
{
"Network": {
"endpoint": "https://api.example.com/v1",
"retries": 5
}
}
examples/07-config.pl view on Meta::CPAN
#!/usr/bin/env perl
# Config files. Values come from the command line, then from config files,
# then from the spec default. Without --config, every existing file in
# 'paths' is loaded in order, and a later file overrides an earlier one
# option by option. --config FILE loads only that file; a bare --config
# loads 'defaultPath'. --create-default-config writes a starter file with
# the defaults. Config files are grouped like the help output: 'retries'
# and 'endpoint' are set under "Network".
#
# 07-config.json next to this script is the first file in 'paths'. The
# second one, ~/.example07.json, does not exist until you create it.
#
# Try:
# perl examples/07-config.pl (endpoint and retries from 07-config.json)
# perl examples/07-config.pl --retries 1 (the command line wins over the file)
# perl examples/07-config.pl --create-default-config ~/.example07.json
# (edit retries in ~/.example07.json, e.g. to 9, then:)
# perl examples/07-config.pl (retries from ~/.example07.json, endpoint still from 07-config.json)
# perl examples/07-config.pl --config (only the defaultPath, ~/.example07.json)
# perl examples/07-config.pl --config examples/07-config.json
# perl examples/07-config.pl --help
use v5.26;
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib", $FindBin::Bin;
examples/07-config.pl view on Meta::CPAN
valid => [qw(debug info warn error)],
help => 'How much to log',
},
'retries' => {
type => 'int',
default => 3,
min => 0,
group => 'Network',
help => 'How often to retry a failed request',
},
'endpoint' => {
type => 'url',
group => 'Network',
help => 'The server to talk to',
},
},
config => {
format => 'json',
paths => ["$FindBin::Bin/07-config.json", '~/.example07.json'],
defaultPath => '~/.example07.json',
},
lib/Getopt/Pad/Type/Url.pm view on Meta::CPAN
=head1 NAME
Getopt::Pad::Type::Url - The url option type
=head1 SYNOPSIS
=for highlighter language=perl
options => {
endpoint => { type => 'url', default => 'https://api.example.com/' },
},
=head1 DESCRIPTION
The type of options and args declared with C<< type => 'url' >> or
C<'uri'>. It accepts values of the form C<scheme://rest>: a scheme that
starts with a letter and continues with letters, digits, C<+>, C<.> or
C<->, then C<://>, then at least one character. The value must not contain
whitespace. C<https://example.com/x>, C<ssh://git@example.com/repo.git>
and C<file:///tmp/x> are accepted; C<example.com> and
( run in 1.118 second using v1.01-cache-2.11-cpan-062aa07a564 )