Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bin/crypt] added verb binding logic

  • Loading branch information...
commit 457e63f913a539b3f7e991c2736627fbe180e859 1 parent 6dc3673
@masak authored
Showing with 18 additions and 6 deletions.
  1. +18 −6 bin/crypt
View
24 bin/crypt
@@ -337,6 +337,13 @@ multi MAIN() {
%descriptions{$0} = ~$1;
}
+ sub params($method) {
+ $method.signature.params
+ ==> grep { .positional && !.invocant }
+ ==> map { .name.substr(1) }
+ }
+ my %commands = map { $^m.name => params($m) }, $game.^methods;
+
loop {
my $command = prompt('> ');
given $command {
@@ -348,12 +355,17 @@ multi MAIN() {
$command .= lc;
$command .= trim;
- when 'look' {
- my @events = $game.look();
- for @events {
- when Crypt::PlayerLooked {
- say %descriptions{.description_of};
- }
+ my $verb = $command.words[0];
+ my @args = $command.words[1..*];
+ when %commands.exists($verb) {
+ my @req_args = %commands{$verb}.list;
+ when @args != @req_args {
+ say "You passed in {+@args} arguments, but $verb requires {+@req_args}.";
+ say "The arguments are {map { "<$_>" }, @req_args}.";
+ }
+ my @events = $game."$verb"(|@args);
+ CATCH {
+ when X::Adventure { say .message, '.' }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.