summaryrefslogtreecommitdiff
path: root/lib/Getopt/Dakkar/Option.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Getopt/Dakkar/Option.pm')
-rw-r--r--lib/Getopt/Dakkar/Option.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Getopt/Dakkar/Option.pm b/lib/Getopt/Dakkar/Option.pm
new file mode 100644
index 0000000..0dfd882
--- /dev/null
+++ b/lib/Getopt/Dakkar/Option.pm
@@ -0,0 +1,38 @@
+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;
+}