in reply to Moose Attribute constraint: Regex OR undef
Maybe you need Maybe?
See doc:subtype 'MyMatch', as 'Str', where { /$regEx/ }, message { "$_ didn't match" }; has 'attr' => ( is => 'ro', isa => 'Maybe[MyMatch]', required => 0 );
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Moose Attribute constraint: Regex OR undef
by hoppfrosch (Scribe) on Nov 01, 2016 at 09:26 UTC |