This is what the meta object is for:
#!/usr/bin/perl
{ package Foo;
use Moose;
use warnings;
has num => ( is => "rw", isa => "Int" );
has str => ( is => "rw", isa => "Str" );
}
use strict;
use feature "say";
use warnings;
my $foo = Foo->new;
for my $attr ("num", "str") {
say "$attr is of type: ",
$foo->meta->get_attribute($attr)->type_constraint->name;
}
See http://search.cpan.org/dist/Moose/lib/Moose/Meta/Class.pm
On Thu, Sep 29, 2016 at 3:34 PM Klaus Jantzen <[email protected]>
wrote:
> Hello,
>
> I have defined Moose-classes with various attributes.
>
> During the execution of a program that uses such a class I would like to
> determine the data type of a specific attribute at the time I am using it.
>
> How can I do that?
> --
>
> K.D.J.
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>