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.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Moose::Util::TypeConstraints - Querying subtype() Caveat
by kcott (Archbishop) on Jul 20, 2012 at 13:56 UTC

    Thanks tobyink. I was only referring to instances with DateTime loaded.

    The documentation states that this fails silently:

    use DateTime; subtype DateTime => as Object => where { $_->isa('DateTime') };

    I am unable to reproduce this failure.

    One idea was that if the behaviour of the fat comma quoting mechanism had changed since Perl 5.8, then maybe the failure only happens with earlier versions of Perl. If this wasn't the case, my only other thought was that this was a documentation error - I provided an example of what would fail silently:

    use DateTime; subtype DateTime, as Object => where { $_->isa(q{DateTime}) };

    -- Ken