From 9c7b213f58fe533953953e90b5bc77087ca4d45d Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 13 Jul 2018 18:52:08 +0100 Subject: we can now parse boolean options --- lib/Getopt/Dakkar/Parameter.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/Getopt/Dakkar/Parameter.pm (limited to 'lib/Getopt/Dakkar/Parameter.pm') 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->@*), + }); + } +} -- cgit v1.2.3