Data::Object::Opts
Data-Object Command-line Options
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
This package provides an object-oriented interface to the process' command-line options.
This package integrates behaviors from:
Data::Object::Role::Stashable
This package uses type constraints defined by:
Data::Object::Library
This package has the following attributes.
args(ArrayRef[Str])
The attribute is read-only, accepts (ArrayRef[Str]) values, and is optional.
(ArrayRef[Str])
spec(ArrayRef[Str])
named(HashRef)
The attribute is read-only, accepts (HashRef) values, and is optional.
(HashRef)
This package implements the following methods.
exists(Str $key) : Any
The exists method takes a name and returns truthy if an associated value exists.
$opts->exists('method'); # exists $resource $opts->exists('resource'); # exists $resource
get(Str $key) : Any
The get method takes a name and returns the associated value.
$opts->get('method'); # $resource $opts->get('resource'); # $resource
name(Str $key) : Any
The name method takes a name and returns the stash key if the the associated value exists.
$opts->name('method'); # resource $opts->name('resource'); # resource
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.
args
spec
my $options = $opts->parse; my $options = $opts->parse(['bundle']);
set(Str $key, Maybe[Any] $value) : Any
The set method takes a name and sets the value provided if the associated argument exists.
$opts->set('method', 'people'); # people $opts->set('resource', 'people'); # people
stashed() : HashRef
The stashed method returns the stashed data associated with the object.
$opts->stashed; # {...}
warned() : Num
The warned method returns the number of warnings emitted during option parsing.
my $warned = $opts->warned; # $count
warnings() : ArrayRef[ArrayRef[Str]]
The warnings method returns the set of warnings emitted during option parsing.
my $warnings = $opts->warnings; my $warning = $warnings->[0][0]; die $warning;
Al Newkirk, +309
+309
Anthony Brummett, +10
+10
Adam Hopkins, +2
+2
José Joaquín Atria, +1
+1
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To get the most out of this distribution, consider reading the following:
Do
Data::Object
Data::Object::Class
Data::Object::ClassHas
Data::Object::Role
Data::Object::RoleHas
To install Do, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Do
CPAN shell
perl -MCPAN -e shell install Do
For more information on module installation, please visit the detailed CPAN module installation guide.