建立Perl 有枚举类型吗?,我如何执行动态类型检查(或静态类型检查,如果使用严格能够这样做)我的子例程参数正在获取正确的枚举类型?
package Phone::Type;
use constant {
HOME => 'Home',
WORK => 'Work',
};
package main;
sub fun
{
my ($my_phone_type_enum) = @_;
# How to check my_phone_type_enum, is either Phone::Type->HOME or Phone::Type->WORK or ... but not 'Dog' or 'Cat'?
}
fun(Phone::Type->HOME); # valid
fun(Phone::Type->WORK); # valid
fun('DOG'); # run-time or compile time error