Created
June 20, 2017 16:44
-
-
Save anonymous/e52cfc09d2476bbf8010a8b40a9984c0 to your computer and use it in GitHub Desktop.
concept for web action dispatching in Perl6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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