Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created June 20, 2017 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e52cfc09d2476bbf8010a8b40a9984c0 to your computer and use it in GitHub Desktop.
Save anonymous/e52cfc09d2476bbf8010a8b40a9984c0 to your computer and use it in GitHub Desktop.
concept for web action dispatching in Perl6
multi dispatch( '/', *@remaining ) {
say "Diving into root handler";
return 'root handler', |@remaining;
}
multi dispatch( 'root handler', 'GET', $req, $res ) {
say "Final request in the chain for root";
return ();
}
multi dispatch( 'root handler', 'foo', $foo_id, *@remaining ) {
say "Diving into foo $foo_id";
return "foo handler", |@remaining;
}
multi dispatch( 'foo handler', 'GET', $req, $res ) {
say "Final request in the chain for foo";
return ();
}
multi dispatch( 'foo handler', 'bar', $bar_id, *@remaining ) {
say "Diving into bar $bar_id";
return 'bar handler', |@remaining;
}
multi dispatch( 'bar handler', 'GET', $req, $res ) {
say "Final action in the chain for bar";
return ();
}
sub handle_request(*@params) {
while (@params) {
@params = dispatch(|@params)
}
}
handle_request( '/', 'foo', '1', 'bar', '2', 'GET', 'req', 'res' );
handle_request( '/', 'foo', '1', 'GET', 'req', 'res' );
handle_request( '/', 'GET', 'req', 'res' );
handle_request( '/', 'foo', 'GET', 'req', 'res' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment