Hi, claus!
Actually, I can't understand the question.
You can (and should) define type constraint for attribute via Moose
predefined types, Types::Standart module or your own type system.
use Types::Standard -all;
use Moose;
has 'attr_name' => (
'is' => 'ro',
'isa' => InstanceOf['Package::Name'],
...
);
sub some_method {
my ($self, @args) = @_;
say ref ( $self->attr_name() );
# here you can be sure that attr_name is instance of Package::Name
class, constuctor will die unless.
}
Writing some generic attribute constraints (attr_name should be blessed
reference) and trying to make some polimorphic method based on type of
attr_name is not a good idea generally. It's better to use inheritance
or roles or some other mechanism to achieve this.29.09.16 14:06, Klaus
Jantzen пишет:
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?
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/