package Getopt::Dakkar::Option; use Getopt::Dakkar::Style qw(class); with 'Getopt::Dakkar::Role::Piece'; # VERSION # ABSTRACT: an option has can_bundle => ( is => 'ro', isa => Bool, default => 0 ); has parameters => ( is => 'ro', isa => ArrayRef, default => sub { [] } ); sub match($self,$arg) { for my $candidate ($self->matching_strings->@*) { if (length($candidate)==1) { return 1 if $arg eq "-$candidate"; return 1 if $self->can_bundle && $arg =~ /^-\Q$candidate/; } else { return 1 if $arg eq "--$candidate"; } } return 0; } sub parse($self,$args,$stash) { my $my_option = shift $args->@*; # first, get arguments if needed for my $parameter ($self->parameters->@*) { my $argument = $parameter->parse($args,$stash); # aaarg, } # then, remove the option and put the bundle back, if needed if ($my_option =~ /^-[^-]+/) { # we're in a bundle $my_option =~ s{^-.}{-}; unshift $args->@*, $my_option; } return $the_option_argument; }