perl6 - Enum or symbols in Perl 6 -


i want pass parameter method may have predefined value.

   method send-http($url, $http_method) { .... } 

should create enum pass $http_method? if how?

or perl 6 have symbols in ruby?

as @christoph mentioned, can use enums:

enum method <get put post>; sub http-send(str $url, method $m) { * }  http-send("http://url/", get); 

you can use type constraints:

sub http-send(str $url, str $m { $m ∈ <get head post> }) { * }  http-send("http://url/", 'get');  http-send("http://url/", 'put'); constraint type check failed parameter '$m' 

i guess use multi dispatch:

multi sub http-send('get') { * } multi sub http-send('put') { * } multi sub http-send($m) { die "method {$m} not supported." }  http-send('get');  http-send('post'); method post not supported. 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -