summaryrefslogtreecommitdiff
path: root/lib/Getopt/Dakkar/Parameter.pm
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-07-13 18:52:08 +0100
committerdakkar <dakkar@thenautilus.net>2018-07-13 18:52:08 +0100
commit9c7b213f58fe533953953e90b5bc77087ca4d45d (patch)
treec78cd04844a4ba1e92f1bf1dc29c14b3813e4bc7 /lib/Getopt/Dakkar/Parameter.pm
parentI'm losing the plot, here (diff)
downloadGetopt-Dakkar-master.tar.gz
Getopt-Dakkar-master.tar.bz2
Getopt-Dakkar-master.zip
we can now parse boolean optionsHEADmaster
Diffstat (limited to 'lib/Getopt/Dakkar/Parameter.pm')
-rw-r--r--lib/Getopt/Dakkar/Parameter.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Getopt/Dakkar/Parameter.pm b/lib/Getopt/Dakkar/Parameter.pm
new file mode 100644
index 0000000..d544c74
--- /dev/null
+++ b/lib/Getopt/Dakkar/Parameter.pm
@@ -0,0 +1,31 @@
+package Getopt::Dakkar::Parameter;
+use Getopt::Dakkar::Style qw(class);
+use Getopt::Dakkar::Argument;
+with 'Getopt::Dakkar::Role::Piece';
+# VERSION
+# ABSTRACT: a (positional) parameter
+
+# this will need to be generalised and depend on the type
+has is_slurpy => ( is => 'ro', isa => Bool, default => 0 );
+
+sub match($self,$arg) {
+ # this may need to throw if the type is wrong?
+ return 1;
+}
+
+sub parse($self,$args,$stash) {
+ if ($self->is_slurpy) {
+ my $value = [ $args->@* ];
+ $args->@* = ();
+ return Getopt::Dakkar::Argument->new({
+ name => $self->name,
+ value => $value,
+ });
+ }
+ else {
+ return Getopt::Dakkar::Argument->new({
+ name => $self->name,
+ value => (shift $args->@*),
+ });
+ }
+}