Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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();


Comment on Re: Moose::Util::TypeConstraints - Querying subtype() Caveat
Download Code
Replies are listed 'Best First'.
Re^2: Moose::Util::TypeConstraints - Querying subtype() Caveat
by kcott (Abbot) 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 +e_quote.pl 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 (Canon) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://982798]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2015-07-31 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls