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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|