Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor a tad to allow direct control of our dispatching.

There's probably a better way of doing this, but after this commit, IO::Prompter works again for the first time in … years?
  • Loading branch information...
commit 383470fa48d5f4e0220687b134392c5e24587d77 1 parent e296867
@colomon authored
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/IO/Prompter.pm
View
19 lib/IO/Prompter.pm
@@ -78,7 +78,7 @@ sub varname_to_prompt ($name) {
return $name.subst(/^<-alnum>+/, "").subst(/_/, " ", :g).tc;
}
-multi sub prompt (&block, :$in = $*IN, :$out = $*OUT) is export {
+sub prompt-block (&block, :$in = $*IN, :$out = $*OUT) {
my (%named, @positional, $eof);
my @param_prompters = gather for &block.signature.params -> $param {
@@ -110,14 +110,14 @@ multi sub prompt (&block, :$in = $*IN, :$out = $*OUT) is export {
my $first_wipe = 1;
-multi sub prompt (
+sub prompt-straight (
$prompt_str?,
# :a( :$args ) of Bool,
# :c( :$complete ) of Array|Hash|Str,
:d(:$default) as Str = "",
#--> :D(:$DEFAULT) of Str,
# :e( :$echo ) of Str,
-Bool :f(:$fail) = False,
+ :f(:$fail) = False,
IO :$in = $*IN,
# :g( :$guarantee ) of Hash = hash{},
# :h( :$history ) of Str,
@@ -142,7 +142,7 @@ Bool :Y(:$Yes) ,
Bool :YN(:$YesNo) ,
*%unexpected_options,
*@prompt,
-) is export {
+) {
# Die horribly if unknown options are offered...
if %unexpected_options {
die %unexpected_options.map({"Unknown option in call to prompt(): $_.perl()"}).join("\n");
@@ -180,4 +180,15 @@ Bool :YN(:$YesNo) ,
!! IO::Prompter::Result.new(:$input, :$failed);
}
+sub prompt (
+ *@prompt,
+ *%options
+) is export {
+ if @prompt == 1 && @prompt[0] ~~ Block {
+ prompt-block(@prompt[0], |%options);
+ } else {
+ prompt-straight(|@prompt, |%options);
+ }
+}
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.