App-Getconf
view release on metacpan or search on metacpan
lib/App/Getconf.pm view on Meta::CPAN
any.
Help message will not retain any formatting, all whitespaces are converted to
single space (empty lines are squeezed to single empty line). On the other
hand, the message will be pretty wrapped and indented, while you don't need to
worry about formatting the string if it is longer and broken to separate lines
in your source code, so I think it's a good trade-off.
=cut
sub opt($) {
my ($data) = @_;
my $type = $data->{type} || "string";
my $check = $data->{check};
my $storage = $data->{storage};
my $help = $data->{help};
my $value = $data->{value}; # not necessary, but kept for convention
my $default = $data->{default}; # not necessary, but kept for convention
if (ref $storage) {
lib/App/Getconf.pm view on Meta::CPAN
=item C<opt_alias($option)>
Create an alias for C<$option>. Note that aliases are purely for command line.
L<App::Getconf::View(3)> and C<options()> method don't honour them.
Aliases may only point to non-alias options.
=cut
sub opt_alias($) {
my ($dest_option) = @_;
return new App::Getconf::Node(alias => $dest_option);
}
=item C<opt_flag()>
Flag option (like I<--help>, I<--verbose> or I<--debug>).
=cut
sub opt_flag() {
return opt { type => 'flag' };
}
=item C<opt_bool()>
Boolean option (like I<--recursive>). Such option gets its counterpart
called I<--no-${option}> (mentioned I<--recursive> gets I<--no-recursive>).
=cut
sub opt_bool() {
return opt { type => 'bool' };
}
=item C<opt_int()>
Integer option (I<--retries=3>).
=cut
sub opt_int() {
return opt { type => 'int' };
}
=item C<opt_float()>
Option specifying a floating point number.
=cut
sub opt_float() {
return opt { type => 'float' };
}
=item C<opt_string()>
Option specifying a string.
=cut
sub opt_string() {
return opt { type => 'string' };
}
=item C<opt_path()>
Option specifying a path in local filesystem.
=cut
sub opt_path() {
# TODO: some checks on how this looks like
# * existing file
# * existing directory
# * non-existing file (directory exists)
# * Maasai?
return opt { type => 'string' };
}
=item C<opt_hostname()>
Option specifying a hostname.
B<NOTE>: This doesn't check DNS for the hostname to exist. This only checks
hostname's syntactic correctness (and only to some degree).
=cut
sub opt_hostname() {
return opt { check => qr/^[a-z0-9-]+(\.[a-z0-9-]+)*$/i };
}
=item C<opt_re(qr/.../)>
Option specifying a string, with check specified as regexp.
=cut
sub opt_re($) {
my ($re) = @_;
return opt { check => $re };
}
=item C<opt_sub(sub {...})>
=item C<opt_sub {...}>
Option specifying a string, with check specified as function (code ref).
Subroutine will have C<$_> set to value to check, and the value will be the
only argument (C<@_>) passed.
Subroutine should return C<TRUE> when option value should be accepted,
C<FALSE> otherwise.
=cut
sub opt_sub(&) {
my ($sub) = @_;
return opt { check => $sub };
}
=item C<opt_enum ["first", ...]>
Option specifying a string. The string must be one of the specified in the
array.
=cut
sub opt_enum($) {
my ($choices) = @_;
return opt { check => $choices };
}
#-----------------------------------------------------------------------------
=back
=cut
t/release.t view on Meta::CPAN
if ($ENV{RELEASE_TESTING}) {
plan(tests => 3);
} else {
plan(skip_all => "Author tests not required for installation");
}
#-----------------------------------------------------------------------------
# auxiliary functions
sub make_version($) {
my ($string) = @_;
if (not $string) {
# default version number
$string = "0.01";
}
$string =~ s/^v|\s+$//g;
my @ve = split /\./, $string;
( run in 0.765 second using v1.01-cache-2.11-cpan-65fba6d93b7 )