Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

G'day Monks,

In Moose::Util::TypeConstraints, under Slightly Less Important Caveat, this is shown as silently failing:

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

The recommended solution is given as:

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

This didn't look right to me, especially as the quoting mechanism of => is supposed to be implicit and ignoring precedence (see perlop - Comma Operator).

I ran both forms through B::Deparse and got the same results:

$ perl -MO=Deparse,-p -e ' use Moose; use Moose::Util::TypeConstraints; use DateTime; subtype DateTime => as Object => where { $_->isa(q{DateTime}) }; ' use Moose; use Moose::Util::TypeConstraints; use DateTime; use warnings; use strict 'refs'; subtype('DateTime', as('Object', where(sub { $_->isa('DateTime'); } ))); -e syntax OK
$ perl -MO=Deparse,-p -e ' use Moose; use Moose::Util::TypeConstraints; use DateTime; subtype q{DateTime}, as Object => where { $_->isa(q{DateTime}) }; ' use Moose; use Moose::Util::TypeConstraints; use DateTime; use warnings; use strict 'refs'; subtype('DateTime', as('Object', where(sub { $_->isa('DateTime'); } ))); -e syntax OK

I ran diff on both outputs: they're identical.

The versions of Moose and Moose::Util::TypeConstraints that I'm using are both 2.0603 and I'm using Perl 5.14.2.

Two thoughts occurred to me regarding this:

  1. Moose source has use 5.008;. Perhaps the quoting mechanism of => worked differently under an earlier version of Perl than I'm using: while the wording has changed between versions, I don't see anything indicating delayed quoting. For reference, here's perlop - Comma Operator for 5.8.8, 5.14.2 and latest (5.16.0).
  2. Perhaps this is a documentation error. If the type name is not quoted (explicitly or implicitly), the syntax is still fine but the output is quite different:
    $ perl -MO=Deparse,-p -e ' use Moose; use Moose::Util::TypeConstraints; use DateTime; subtype DateTime, as Object => where { $_->isa(q{DateTime}) }; ' use Moose; use Moose::Util::TypeConstraints; use DateTime; use warnings; use strict 'refs'; ('DateTime'->subtype, as('Object', where(sub { $_->isa('DateTime'); } ))); -e syntax OK

Can anyone shed any light on this? Thanks in advance.

Update: I added use DateTime; to both of the first two statements to avoid ambiguity with similar code in the linked documentation.

-- Ken


In reply to Moose::Util::TypeConstraints - Querying subtype() Caveat by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2013-05-24 02:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best material for plates (tableware) is:









      Results (494 votes), past polls