>>>>> "Marcos" == Marcos Barbeitos <[email protected]> writes:
Marcos> Hi, folks,
Marcos> I am trying to build a dynamic attribute as a HashRef so that every
Marcos> time that it is required it should refresh itself to reflect any
Marcos> changes effected on the corresponding data structure. The way I've
Marcos> seen people do it is simply assigning a function as the default
value
Marcos> of the attribute ( i.e. default => foo() ). I originally created
this
Marcos> attribute using 'lazy_build' because the construction of the HashRef
Marcos> requires other attributes from the object itself. I would only be
Marcos> able to use that construct if I could pass the object as an
argument,
Marcos> so it could access those attributes when building the HashRef, but I
Marcos> see no obvious way of doing this. The original bit of code (works,
Marcos> but as far as I know would build the HashRef only once) looks like
Marcos> this:
Marcos> has 'table_list' => (
Marcos> traits => ['Hash'],
Marcos> is => 'rw',
Marcos> isa => 'HashRef[Table]',
Marcos> lazy_build => 1,
Marcos> handles => {
Marcos> all_tables => 'values',
Marcos> has_table => 'exists',
Marcos> get_table => 'get'
Marcos> }
Marcos> );
Marcos> sub build_table_list
Marcos> {
Marcos> my $self = shift;
Marcos> return get_table_list( $self );
Marcos> }
Marcos> Any thoughts? Many thanks in advance.
Add a clearer to the attribute (clearer => "clear_table_list") then
after hash_modifier => sub { shift->clear_table_list };
--
Eden Cardim Need help with your perl Catalyst or DBIx::Class
project?
Software Engineer http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment
platform?
http://blog.edencardim.com http://www.shadowcat.co.uk/servers/