aartist has asked for the wisdom of the Perl Monks concerning the following question:

I have subtype in Moose and I am checking if it has one of the values in enums.
enum conf => [qw /access input/]; enum version => [qw /1 2/]; and I like to have subtype 'FileName', as 'Str', where { /(access|input).(1|2).txt/ }; and then has filename => (is => 'rw', isa=> 'FileName');
I like to replace the values in where clause by specifying the enum names. How I can do that?
Thanks.

Replies are listed 'Best First'.
Re: Moose: Include Enum in Regex
by tobyink (Canon) on Jan 30, 2019 at 10:52 UTC

    Something like this help?

    my @conf_enum_values = @{ Moose::Util::TypeConstraints::find_type_cons +traint('conf')->values };

    Also, cos I'm me, here's the same thing using Type::Tiny type constraints instead:

    use Types::Standard -types; my $Conf = Enum[qw/ access input /]; my $Version = Enum[1 .. 2]; my $FileName = StrMatch[qr/^(\w+)\.(\d+)\.txt$/, Tuple[$Conf, $Version +]]; has filename => (is => 'rw', isa => $FileName);