develooper Front page | perl.moose | Postings from June 2014

RE: coerce a sub-subtype

Thread Previous
From:
John Macdonald
Date:
June 16, 2014 21:16
Subject:
RE: coerce a sub-subtype
Message ID:
01EF6156B387B14E8278ECC376793BE16FAD84F0@exmb3.ad.oicr.on.ca
While I am using Moose::Util::TypeConstraints, I simplified my typenames for this discussion, so the Type::Chr names I used below are all actually prefixed by BoutrosLab::TSVStream::... so there is less concern about namespace collison.  Using local lexical types doesn't work directly when you want to refer to the types in a sub-type defined in a separate mdule in a differnt lexical scope.

I've put a TODO into my code to convert to Type::Tiny when I get to the point of adding more subtype variants.

John Macdonald
Software Engineer

Ontario Institute for Cancer Research
MaRS Centre

661 University Avenue

Suite 510
Toronto, Ontario

Canada M5G 0A3


Tel:

Email: John.Macdonald@oicr.on.ca

Toll-free: 1-866-678-6427
Twitter: @OICR_news


www.oicr.on.ca

This message and any attachments may contain confidential and/or privileged information for the sole use of the intended recipient. Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited. If you have received this message in error, please contact the sender and delete all copies. Opinions, conclusions or other information contained in this message may not be that of the organization.

________________________________________
From: Karen Etheridge [perl@froods.org]
Sent: June 16, 2014 4:07 PM
To: moose@perl.org
Subject: Re: coerce a sub-subtype

On Mon, Jun 16, 2014 at 07:41:29PM +0000, John Macdonald wrote:
> In general, though, having a way of inheriting subtypes could be potentially a big saving in this sort of case.

This would be a really nice feature to have in MooseX::Types - no one's
made this happen yet though, sadly. (Patches welcome!) :)
Also, Types::Tiny does have an option to support this already.

I'd strongly suggest avoiding declaring named types using
Moose::Util::TypeConstraints though, because such types are global (as are
their coercions), which can cause nasty action-at-a-distance errors. You
can get around this problem by declaring types only as local lexicals, e.g:

my $type = subtype as ...;

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About