Hi, folks,
I am trying to build a dynamic attribute as a HashRef so that every
time that it is required it should refresh itself to reflect any
changes effected on the corresponding data structure. The way I've
seen people do it is simply assigning a function as the default value
of the attribute ( i.e. default => foo() ). I originally created this
attribute using 'lazy_build' because the construction of the HashRef
requires other attributes from the object itself. I would only be
able to use that construct if I could pass the object as an argument,
so it could access those attributes when building the HashRef, but I
see no obvious way of doing this. The original bit of code (works,
but as far as I know would build the HashRef only once) looks like
this:
has 'table_list' => (
traits => ['Hash'],
is => 'rw',
isa => 'HashRef[Table]',
lazy_build => 1,
handles => {
all_tables => 'values',
has_table => 'exists',
get_table => 'get'
}
);
sub build_table_list
{
my $self = shift;
return get_table_list( $self );
}
Any thoughts? Many thanks in advance.
--
Marcos S. Barbeitos
Post-doctoral researcher
American Museum of Natural History
Department of Invertebrate Zoology
79th st and Central Park West
New York, NY 10024