Data::Object::Opts
Opts Class for Perl 5
method: exists method: get method: name method: parse method: set method: stashed method: warned method: warnings
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
Types::Standard
Data::Object::Role::Buildable Data::Object::Role::Proxyable Data::Object::Role::Stashable
args: ro, opt, ArrayRef[Str] spec: ro, opt, ArrayRef[Str] named: ro, opt, HashRef
This package provides methods for accessing command-line arguments.
The exists method takes a name or index and returns truthy if an associated value exists.
exists(Str $key) : Any
=example-1 exists
# given: synopsis
$opts->exists('resource'); # truthy
=example-2 exists
# given: synopsis
$opts->exists('method'); # truthy
=example-3 exists
# given: synopsis
$opts->exists('resources'); # falsy
The get method takes a name or index and returns the associated value.
get(Str $key) : Any
=example-1 get
# given: synopsis
$opts->get('resource'); # users
=example-2 get
# given: synopsis
$opts->get('method'); # users
=example-3 get
# given: synopsis
$opts->get('resources'); # undef
The name method takes a name or index and returns index if the the associated value exists.
name(Str $key) : Any
=example-1 name
# given: synopsis
$opts->name('resource'); # resource
=example-2 name
# given: synopsis
$opts->name('method'); # resource
=example-3 name
# given: synopsis
$opts->name('resources'); # undef
The parse method optionally takes additional Getopt::Long parser configuration options and retuns the options found based on the object args and spec values.
parse(Maybe[ArrayRef] $config) : HashRef
=example-1 parse
# given: synopsis
$opts->parse;
=example-2 parse
# given: synopsis
$opts->parse(['bundling']);
The set method takes a name or index and sets the value provided if the associated argument exists.
set(Str $key, Maybe[Any] $value) : Any
=example-1 set
# given: synopsis
$opts->set('method', 'people'); # people
=example-2 set
# given: synopsis
$opts->set('resource', 'people'); # people
=example-3 set
# given: synopsis
$opts->set('resources', 'people'); # undef
# is not set
The stashed method returns the stashed data associated with the object.
stashed() : HashRef
=example-1 stashed
# given: synopsis
$opts->stashed;
The warned method returns the number of warnings emitted during option parsing.
warned() : Num
=example-1 warned
package main;
use Data::Object::Opts;
my $opts = Data::Object::Opts->new(
args => ['-vh'],
spec => ['verbose|v', 'help|h']
);
$opts->warned;
The warnings method returns the set of warnings emitted during option parsing.
warnings() : ArrayRef[ArrayRef[Str]]
=example-1 warnings
package main;
use Data::Object::Opts;
my $opts = Data::Object::Opts->new(
args => ['-vh'],
spec => ['verbose|v', 'help|h']
);
$opts->warnings;
24 POD Errors
The following errors were encountered while parsing the POD:
- Around line 10:
Unknown directive: =name
- Around line 16:
Unknown directive: =abstract
- Around line 22:
Unknown directive: =includes
- Around line 35:
Unknown directive: =synopsis
- Around line 55:
Unknown directive: =libraries
- Around line 61:
Unknown directive: =integrates
- Around line 69:
Unknown directive: =attributes
- Around line 77:
Unknown directive: =description
- Around line 83:
Unknown directive: =method
- Around line 88:
Unknown directive: =signature
- Around line 112:
Unknown directive: =method
- Around line 116:
Unknown directive: =signature
- Around line 140:
Unknown directive: =method
- Around line 145:
Unknown directive: =signature
- Around line 169:
Unknown directive: =method
- Around line 175:
Unknown directive: =signature
- Around line 193:
Unknown directive: =method
- Around line 198:
Unknown directive: =signature
- Around line 224:
Unknown directive: =method
- Around line 228:
Unknown directive: =signature
- Around line 240:
Unknown directive: =method
- Around line 244:
Unknown directive: =signature
- Around line 263:
Unknown directive: =method
- Around line 267:
Unknown directive: =signature