Data::Object::Args
Args Class
Args Class for Perl 5
method: exists method: get method: name method: set method: stashed method: unnamed
package main;
use Data::Object::Args;
local @ARGV = qw(--help execute);
my $args = Data::Object::Args->new(
named => { flag => 0, command => 1 }
);
# $args->flag; # $ARGV[0]
# $args->get(0); # $ARGV[0]
# $args->get(1); # $ARGV[1]
# $args->action; # $ARGV[1]
# $args->exists(0); # exists $ARGV[0]
# $args->exists('flag'); # exists $ARGV[0]
# $args->get('flag'); # $ARGV[0]
Types::Standard
Data::Object::Role::Buildable Data::Object::Role::Proxyable Data::Object::Role::Stashable
named: ro, opt, HashRef
This package provides methods for accessing @ARGS items.
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
$args->exists(0); # truthy
=example-2 exists
# given: synopsis
$args->exists('flag'); # truthy
=example-3 exists
# given: synopsis
$args->exists(2); # falsy
The get method takes a name or index and returns the associated value.
get(Str $key) : Any
=example-1 get
# given: synopsis
$args->get(0); # --help
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
$args->name('flag'); # 0
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
$args->set(0, '-?'); # -?
=example-2 set
# given: synopsis
$args->set('flag', '-?'); # -?
=example-3 set
# given: synopsis
$args->set('verbose', 1); # undef
# is not set
The stashed method returns the stashed data associated with the object.
stashed() : HashRef
=example-1 stashed
# given: synopsis
$args->stashed
The unnamed method returns an arrayref of values which have not been named using the named attribute.
unnamed() : ArrayRef
=example-1 unnamed
package main;
use Data::Object::Args;
local @ARGV = qw(--help execute --format markdown);
my $args = Data::Object::Args->new(
named => { flag => 0, command => 1 }
);
$args->unnamed # ['--format', 'markdown']
=example-2 unnamed
package main;
use Data::Object::Args;
local @ARGV = qw(execute phase-1 --format markdown);
my $args = Data::Object::Args->new(
named => { command => 1 }
);
$args->unnamed # ['execute', '--format', 'markdown']
21 POD Errors
The following errors were encountered while parsing the POD:
- Around line 10:
Unknown directive: =name
- Around line 16:
Unknown directive: =tagline
- Around line 22:
Unknown directive: =abstract
- Around line 28:
Unknown directive: =includes
- Around line 39:
Unknown directive: =synopsis
- Around line 61:
Unknown directive: =libraries
- Around line 67:
Unknown directive: =integrates
- Around line 75:
Unknown directive: =attributes
- Around line 81:
Unknown directive: =description
- Around line 87:
Unknown directive: =method
- Around line 92:
Unknown directive: =signature
- Around line 116:
Unknown directive: =method
- Around line 120:
Unknown directive: =signature
- Around line 144:
Unknown directive: =method
- Around line 149:
Unknown directive: =signature
- Around line 161:
Unknown directive: =method
- Around line 166:
Unknown directive: =signature
- Around line 192:
Unknown directive: =method
- Around line 196:
Unknown directive: =signature
- Around line 206:
Unknown directive: =method
- Around line 211:
Unknown directive: =signature