find attributes type_constraints

[email protected] (Ch Lamprecht)
Newsgroups perl.moose
Message-ID <[email protected]>
Hello,
I am trying to make an object report the type constraints for its attributes.
given a class, which defines attributes like :


has 'test_attribute' => (isa     => 'ArrayRef',
                               is      => 'ro',
                               default => sub{[]},
                           );

has 'instance_view'    => (isa  => 'TkObjectsView',
                            is   => 'rw',
                        );

where 'ArrayRef' is the builtin type_constraint and 'TkObjectsView' is a simple
classname.

Is there a way to retrieve the types of these attributes from an instance?
If I do something like:

for my $attr(@attributes){
     my $tc = $attr->type_constraint;
     print Dumper $tc;
     print "\n\n";
}

I get the following output:

$VAR1 = bless( {
                  'compiled_type_constraint' => 'CODE(0x1bceb14)',
                  'parent' => 'Ref',
                  'name' => 'ArrayRef',
                  'coercion' => undef,
                  'hand_optimized_type_constraint' => 'CODE(0x1bf6660)',
                  'constraint' => 'CODE(0x1bf65f4)',
                  'message' => undef
                }, 'Moose::Meta::TypeConstraint' );


$VAR1 = bless( {
                  'compiled_type_constraint' => 'CODE(0x1c71e54)',
                  'parent' => 'Object',
                  'name' => '__ANON__',
                  'coercion' => undef,
                  'hand_optimized_type_constraint' => undef,
                  'constraint' => 'CODE(0x1c71a10)',
                  'message' => undef
                }, 'Moose::Meta::TypeConstraint' );

'ArrayRef' is in the name attribute of the TypeConstraint, but I don't see a way 
to get the classname 'TkObjectsView' back out of the second type_constraint 
object. (Except, maybe, by using B::Deparse ;) )
Am I missing something?
Will I have to explicitly create a 'Moose::Meta::TypeConstraint' for every class
I want to use in an attribute to make this work?

Thanks, Christoph Lamprecht
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.