Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Moose Attribute constraint: Regex OR undef

by 1nickt (Canon)
on Oct 31, 2016 at 12:57 UTC ( [id://1175020]=note: print w/replies, xml ) Need Help??


in reply to Moose Attribute constraint: Regex OR undef

Maybe you need Maybe?

subtype 'MyMatch', as 'Str', where { /$regEx/ }, message { "$_ didn't match" }; has 'attr' => ( is => 'ro', isa => 'Maybe[MyMatch]', required => 0 );
See doc:
The Maybe[`a] type deserves a special mention. Used by itself, it doesn't really mean anything (and is equivalent to Item). When it is parameterized, it means that the value is either undef or the parameterized type. So Maybe[Int] means an integer or undef.

Hope this helps!

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Moose Attribute constraint: Regex OR undef
by hoppfrosch (Scribe) on Nov 01, 2016 at 09:26 UTC
    Silly me: I was close to the same solution - but I failed due to the usage of round brackets instead of square brackets with Maybe[....]
    Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1175020]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-19 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found