in reply to Re^2: Moose type question
in thread Moose type question
The problem is that Maybe[] doesn't currently work with coercion, and that's behaviour that should be changed.
The type 'Maybe[Foo]' is different the type 'Foo' and Maybe[`a] is a parameterized type, and parameterized types do not support deep coercion like that. We have discussed the topic of deep coercion, but it is simply deemed too magical and prone to action-at-a-distance type issues.
Along with MooseX::UndefTolerant, it is also possible to subtype a Maybe[`a] type and then add coercions to that.
Of course your coercions would need to account for the possibility of undef, but that shouldn't be too hard.subtype 'MaybeDateTime' => as 'Maybe[DateTime]'; coerce 'MaybeDateTime' => from 'St' => via { ... };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Moose type question
by ikegami (Patriarch) on Jun 14, 2010 at 22:13 UTC |