Subject: | RFE: Need methods to identify the datatype of the attributes declared |
We are heavily using Class::MethodMaker to declare the attributes
of the class.
Eg:
package my_package;
use Class::MethodMaker [
scalar => 'xyz',
scalar => [
{ '-default_ctor' => sub {
my $self = $_[0];
return $self->invoke_method_abc();
}
},
'abc'
]
];
sub foo {
# 'abc' is a mandatory option. Reads _attributes() to determine the
list of mandatory options
}
sub foo1 {
# 'abc' is a mandatory option. Reads _attributes() to determine the
list of mandatory options
}
sub invoke_method_abc {
...
}
sub _attributes {
return ['xyz', 'abc'];
}
It's very useful to provide methods which return back the datatype
of the attributes.
Eg: my $type = my_package->get_datatype('abc') # Returns 'scalar'
There is a base class for the above described package which
obtains the attribute names of each of its subclasses by calling
_attributes() and it would like to know the datatype for the
attributes to perform some other action.
Currently it does
$value = $pkg_name->$attribute_name();
and it inspects $value. If it is undef, then the attribute is treated
as a scalar whereas if it is an empty array ref, then the attribute is
considered as an array. This doesn't work well when the attribute is
associated with a 'default_ctor' in which case just to find the
datatype, the attribute value is unnecessarily populated.
So new methods which return the datatype of the attribute would be
desired.