No such thing as a small change | |
PerlMonks |
Re^3: Moose "unions" and inheritanceby tobyink (Canon) |
on Nov 30, 2012 at 12:06 UTC ( [id://1006465]=note: print w/replies, xml ) | Need Help?? |
Moose type constraints are not strings, they are instances of Moose::Meta::TypeConstraint. has (and indeed the Moose::Meta::Attribute class that powers has) just gives you a little sugar allowing you to indicate type constraints as strings. But internally it translates those to type constraint objects. MooseX::Types basically gives you functions defined along these lines:
So that you can use:
It also plays some fancy tricks overloading bitwise operators so that HashRef | ArrayRef "just works". So everything I did in the previous example would work without MooseX::Types; you'd just need to do a bit of work with Moose::Meta::TypeConstraint objects, so it wouldn't look as pretty.
Multiple inheritance is always going to make things messier. For example, if you're inheriting from classes A and B where:
... what on earth would you expect to happen?! In cases like this, I'd want the class that's doing the multi-inheritance to define as much of the data attribute as it can, and rely on its base classes' definitions as little as possible.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
In Section
Seekers of Perl Wisdom
|
|