NAME

Venus::Opts - Opts Class

ABSTRACT

Opts Class for Perl 5

SYNOPSIS

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

DESCRIPTION

This package provides methods for handling command-line arguments.

ATTRIBUTES

This package has the following attributes:

named

named(HashRef)

This attribute is read-write, accepts (HashRef) values, is optional, and defaults to {}.

parsed

parsed(HashRef)

This attribute is read-write, accepts (HashRef) values, is optional, and defaults to {}.

specs

specs(ArrayRef)

This attribute is read-write, accepts (ArrayRef) values, is optional, and defaults to [].

warns

warns(ArrayRef)

This attribute is read-write, accepts (ArrayRef) values, is optional, and defaults to [].

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Accessible

Venus::Role::Proxyable

METHODS

This package provides the following methods:

default

default() (ArrayRef)

The default method returns the default value, i.e. [@ARGV].

Since 0.01

default example 1
# given: synopsis;

my $default = $opts->default;

# []

exists

exists(Str $key) (Bool)

The exists method takes a name or index and returns truthy if an associated value exists.

Since 0.01

exists example 1
# given: synopsis;

my $exists = $opts->exists('resource');

# 1
exists example 2
# given: synopsis;

my $exists = $opts->exists('method');

# 1
exists example 3
# given: synopsis;

my $exists = $opts->exists('resources');

# undef

get

get(Str $key) (Any)

The get method takes a name or index and returns the associated value.

Since 0.01

get example 1
# given: synopsis;

my $get = $opts->get('resource');

# "users"
get example 2
# given: synopsis;

my $get = $opts->get('method');

# "users"
get example 3
# given: synopsis;

my $get = $opts->get('resources');

# undef

name

name(Str $key) (Str | Undef)

The name method takes a name or index and returns index if the the associated value exists.

Since 0.01

name example 1
# given: synopsis;

my $name = $opts->name('resource');

# "resource"
name example 2
# given: synopsis;

my $name = $opts->name('method');

# "resource"
name example 3
# given: synopsis;

my $name = $opts->name('resources');

# undef

parse

parse(ArrayRef $args) (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.

Since 0.01

parse example 1
# given: synopsis;

my $parse = $opts->parse;

# { help => 1, resource => "users" }
parse example 2
# given: synopsis;

my $parse = $opts->parse(['bundling']);

# { help => 1, resource => "users" }

set

set(Str $key, Any $data) (Any)

The set method takes a name or index and sets the value provided if the associated argument exists.

Since 0.01

set example 1
# given: synopsis;

my $set = $opts->set('method', 'people');

# "people"
set example 2
# given: synopsis;

my $set = $opts->set('resource', 'people');

# "people"
set example 3
# given: synopsis;

my $set = $opts->set('resources', 'people');

# undef

unnamed

unnamed() (ArrayRef)

The unnamed method returns an arrayref of values which have not been named using the named attribute.

Since 0.01

unnamed example 1
# given: synopsis;

my $unnamed = $opts->unnamed;

# [1]

AUTHORS

Cpanery, cpanery@cpan.org

LICENSE

Copyright (C) 2021, Cpanery

Read the "license" file.