Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Moose: Include Enum in Regex

by aartist (Pilgrim)
on Jan 29, 2019 at 22:09 UTC ( [id://1229131]=perlquestion: print w/replies, xml ) Need Help??

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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1229131]
Approved by johngg
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-25 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found