in reply to Moose::Util::TypeConstraints - Querying subtype() Caveat
Let's reduce that to the simpler:
subtype DateTime => as 'Object';
... because that's all that's necessary to see what's going on. The problem is that Perl parses this in two different ways depending on whether DateTime has been loaded. (Or more formally, depending on whether there exists a stash called DateTime::.) If DateTime is not loaded, it gets parsed effectively as:
subtype('DateTime', as('Object'));
But if DateTime is loaded, it can (at least potentially - these things are tricky to predict) be parsed as an indirect method call, i.e. like this:
DateTime::->subtype( as('Object') );
This is in fact one of the reasons why it recommends picking a name like "MyDateTime" for your datetime datatype. Differentiating between the Moose type constraint name and the Perl package name.
FWIW, MooseX::Types gives you a much more sugary syntax for types.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Moose::Util::TypeConstraints - Querying subtype() Caveat
by kcott (Archbishop) on Jul 20, 2012 at 13:56 UTC |