Venus::Opts - Opts Class
Opts Class for Perl 5
package main; use Venus::Opts; my $opts = Venus::Opts->new( value => ['--resource', 'users', '--help'], specs => ['resource|r=s', 'help|h'], named => { method => 'resource' } # optional ); # $opts->method; # $resource # $opts->get('resource'); # $resource # $opts->help; # $help # $opts->get('help'); # $help
This package provides methods for handling command-line arguments.
This package has the following attributes:
named(HashRef)
This attribute is read-write, accepts (HashRef) values, is optional, and defaults to {}.
(HashRef)
{}
parsed(HashRef)
specs(ArrayRef)
This attribute is read-write, accepts (ArrayRef) values, is optional, and defaults to [].
(ArrayRef)
[]
warns(ArrayRef)
unused(ArrayRef)
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Accessible
Venus::Role::Buildable
Venus::Role::Proxyable
Venus::Role::Valuable
This package provides the following methods:
default() (arrayref)
The default method returns the default value, i.e. [@ARGV].
[@ARGV]
Since 0.01
0.01
# given: synopsis; my $default = $opts->default; # []
exists(string $key) (boolean)
The exists method takes a name or index and returns truthy if an associated value exists.
# given: synopsis; my $exists = $opts->exists('resource'); # 1
# given: synopsis; my $exists = $opts->exists('method'); # 1
# given: synopsis; my $exists = $opts->exists('resources'); # undef
get(string $key) (any)
The get method takes a name or index and returns the associated value.
# given: synopsis; my $get = $opts->get('resource'); # "users"
# given: synopsis; my $get = $opts->get('method'); # "users"
# given: synopsis; my $get = $opts->get('resources'); # undef
name(string $key) (string | undef)
The name method takes a name or index and returns index if the the associated value exists.
# given: synopsis; my $name = $opts->name('resource'); # "resource"
# given: synopsis; my $name = $opts->name('method'); # "resource"
# given: synopsis; my $name = $opts->name('resources'); # undef
parse(arrayref $args) (Venus::Opts)
The parse method optionally takes additional Getopt::Long parser configuration options and retuns the options found based on the object args and spec values.
args
spec
# given: synopsis; my $parse = $opts->parse; # bless({...}, 'Venus::Opts')
# given: synopsis; my $parse = $opts->parse(['bundling']); # bless({...}, 'Venus::Opts')
reparse(arrayref $specs, arrayref $args) (Venus::Opts)
The reparse method resets the parser, calls the "parse" method and returns the result.
Since 2.55
2.55
# given: synopsis; my $reparse = $opts->reparse(['resource|r=s']); # bless({...}, 'Venus::Opts')
# given: synopsis; my $reparse = $opts->reparse(['resource|r=s'], ['bundling']); # bless({...}, 'Venus::Opts')
set(string $key, any $data) (any)
The set method takes a name or index and sets the value provided if the associated argument exists.
# given: synopsis; my $set = $opts->set('method', 'people'); # "people"
# given: synopsis; my $set = $opts->set('resource', 'people'); # "people"
# given: synopsis; my $set = $opts->set('resources', 'people'); # undef
unnamed() (arrayref)
The unnamed method returns an arrayref of values which have not been named using the named attribute.
named
# given: synopsis; my $unnamed = $opts->unnamed; # [1]
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2000, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.