NAME
Data::Object::Opts
ABSTRACT
Opts Class for Perl 5
SYNOPSIS
package
main;
use
Data::Object::Opts;
my
$opts
= Data::Object::Opts->new(
args
=> [
'--resource'
,
'users'
,
'--help'
],
spec
=> [
'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 accessing command-line arguments.
INTEGRATES
This package integrates behaviors from:
LIBRARIES
This package uses type constraints from:
ATTRIBUTES
This package has the following attributes:
args
args(ArrayRef[Str])
This attribute is read-only, accepts (ArrayRef[Str])
values, and is optional.
named
named(HashRef)
This attribute is read-only, accepts (HashRef)
values, and is optional.
spec
spec(ArrayRef[Str])
This attribute is read-only, accepts (ArrayRef[Str])
values, and is optional.
METHODS
This package implements the following methods:
exists
exists
(Str
$key
) : Any
The exists method takes a name or index and returns truthy if an associated value exists.
get
get(Str
$key
) : Any
The get method takes a name or index and returns the associated value.
name
name(Str
$key
) : Any
The name method takes a name or index and returns index if the the associated value exists.
parse
parse(Maybe[ArrayRef]
$config
) : HashRef
The parse method optionally takes additional Getopt::Long parser configuration options and retuns the options found based on the object args
and spec
values.
set
set(Str
$key
, Maybe[Any]
$value
) : Any
The set method takes a name or index and sets the value provided if the associated argument exists.
stashed
stashed() : HashRef
The stashed method returns the stashed data associated with the object.
warned
warned() : Num
The warned method returns the number of warnings emitted during option parsing.
- warned example #1
-
package
main;
use
Data::Object::Opts;
my
$opts
= Data::Object::Opts->new(
args
=> [
'-vh'
],
spec
=> [
'verbose|v'
,
'help|h'
]
);
$opts
->warned;
warnings
warnings() : ArrayRef[ArrayRef[Str]]
The warnings method returns the set of warnings emitted during option parsing.
- warnings example #1
-
package
main;
use
Data::Object::Opts;
my
$opts
= Data::Object::Opts->new(
args
=> [
'-vh'
],
spec
=> [
'verbose|v'
,
'help|h'
]
);
$opts
->warnings;
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".