Skip to content

Commit

Permalink
Add 'initialize' trigger for options
Browse files Browse the repository at this point in the history
  • Loading branch information
exodist committed Nov 30, 2023
1 parent 4fd5651 commit 883bd8a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/Getopt/Yath/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,21 @@ sub process_args {
for my $opt (@$options) {
my $group = $settings->group($opt->group, 1);
my $ref = $group->option_ref($opt->field, 1);
${$ref} //= $opt->get_initial_value($settings);
unless(defined ${$ref}) {
my $val = $opt->get_initial_value($settings);
my $rt = ref($val);
if (!defined($val)) {
$val = [];
}
elsif ($rt) {
$val = [ $rt eq 'ARRAY' ? @$val : %$val ];
}
else {
$val = [$val];
}
$opt->trigger(action => 'initialize', ref => $ref, val => $val, state => $state, options => $self, settings => $settings, group => $group);
$opt->add_value($ref, @$val);
}
$opt->init_settings($state, $settings, $group, $ref);
}

Expand Down

0 comments on commit 883bd8a

Please sign in to comment.