Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Moose::Util::TypeConstraints - Querying subtype() Caveat

by Khen1950fx (Canon)
on Jul 20, 2012 at 11:50 UTC ( #982798=note: print w/replies, xml ) Need Help??

in reply to Moose::Util::TypeConstraints - Querying subtype() Caveat

The recommended solution is the right solution. I got a bareword warning if I didn't quote. Here's the test that I ran:
#!/usr/bin/perl; use Moose; use Moose::Util::TypeConstraints; use DateTime; use Test::More tests => 1; subtype 'DateTime', => as 'Object', => where { $_->isa('DateTime') }; has 'datetime' => (is => 'ro', isa => 'DateTime', required => 1); my $type = find_type_constraint('DateTime'); ok( $type, 'made a DateTime constraint' ); done_testing();

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

    Thanks for your reply, Khen1950fx.

    I wasn't suggesting not quoting. Rather, I was saying that I thought subtype DateTime => ... should perform the same quoting as subtype 'DateTime', ...: the B::Deparse tests, showing subtype('DateTime', ... for both forms, suggest this is correct.

    My subsequent example without quoting (in "Perhaps this is a documentation error. ...") was intended to show what would actually fail silently. With this form, B::Deparse gives 'DateTime'->subtype, ....

    In your test code, I note you've doubled up on the commas (i.e. 'XXX', => ...) in two places. With your code as is, I get

    1..1 ok 1 - made a DateTime constraint

    Removing the quotes around DateTime (i.e. subtype DateTime,\n  => ...), I get

    1..1 Can't locate object method "subtype" via package "DateTime" at pm_moos line 9. # Looks like your test exited with 255 before it could output anything +.

    Then removing the comma after DateTime (i.e. subtype DateTime\n  => ...), I get

    1..1 ok 1 - made a DateTime constraint

    The fat comma is now quoting DateTime.

    -- Ken

Re^2: Moose::Util::TypeConstraints - Querying subtype() Caveat
by choroba (Bishop) on Jul 20, 2012 at 11:59 UTC
    Interestingly, the only thing really needed to be quoted is DateTime, and only if the line ends after it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://982798]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2018-03-21 21:32 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (270 votes). Check out past polls.