Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Moose "unions" and inheritance

by PetaMem (Priest)
on Nov 30, 2012 at 13:49 UTC ( #1006477=note: print w/replies, xml ) Need Help??


in reply to Re^3: Moose "unions" and inheritance
in thread Moose "unions" and inheritance

Moose type constraints are not strings, they are instances of Moose::Meta::TypeConstraint.
Sure, I assumed they have semantics beyond 'being a String'. I just meant from the syntactic perspective, Moose::Manual::Types pretty much makes it look like the types are strings. At least
... isa => Str | ArrayRef, ...

doesn't work without MooseX::Types (Bareword "Str" not allowed while "strict subs"...)

Anyway, I tried to make this inherited union constraints "do what I mean" for multiple inheritance and came up with
package ValAtom; use strict; use warnings; use 5.10.1; use Moose; use MooseX::Types::Moose -all; extends 'KeyAtom', 'JustTesting'; has '+data' => ( isa => __PACKAGE__->_existing_constraint('data') . ' | ArrayRe +f | HashRef', ); sub _existing_constraint { my ($class, $attr) = @_; return join ' | ', map { $_->meta->find_attribute_by_name($attr)->type_constraint } $class->meta->superclasses; } 1;
Back to string again - obviously - as I couldn't figure out how to do it otherwise. But this seems to work.

Bye
 PetaMem
    All Perl:   MT, NLP, NLU

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006477]
help
Chatterbox?
[thezip]: I'll try the --notest arg first when I get back from meetings (after lunch).
[thezip]: Thanks guys for your comments! :-)
[1nickt]: Quick survey: has anyone used or even heard of autobox?
[Corion]: thezip: I would expect some (fancier?) numeric formatting to fail from these test failures
[1nickt]: ( Sometimes when idle I browse remote corners of the code repo at $work ... usually this yields knowledge of projects to decline and coworkers to avoid ... )
[LanX]: sure
[Corion]: 1nickt: Finding autobox in production would give me pause, yes
[LanX]: efficient survey
[MidLifeXis]: And under MINGW64_NT-6.1 MYHOST 2.6.0(0.304/5/3) 2016-09-09 09:46 x86_64 Msys there seem to be issues with escapes in external build tool calls.
[Corion]: I mean, it's a technical feat it achieves, but... why? ;)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-03-23 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (291 votes). Check out past polls.