Using the enum type
In Perl 6 the
enum type is much more complex than in some other languages, and the details are found in its type description here: enum.
This short document will give a simple example of its use similar to use in C-like languages.
Say we have a program that needs to write to various directories so we want a function that, given a directory name, tests it for (1) its existence and (2) whether it can be written to by the user of the program. The results of the test will determine what actions the program takes next.
# the directory will have one of these three statuses from the user's perspective:<CanWrite NoDir NoWrite>;sub check-dir-status( --> DirStat)# test each of three directories by a non-root usermy ='/tmp', # normally writable by any user'/', # writable only by root'~/tmp'; # a non-existent dir in the user's home dirfor -># output# status of dir '/tmp': CanWrite# user can write to dir: /tmp# status of dir '/': NoWrite# status of dir '~/tmp': NoDir