Autoload and Symbol Table

  • Thread starter Alejandro Calbazana
  • Start date
A

Alejandro Calbazana

Hello,

I have a question about Autoload and the Symbol Table. I would like
to create setters and getters for various object attributes using
Autoload in order to populate object's from data at runtime given a
mapping. The idea here is that I would create objects dynamically
based on a type and then be able to "set" the newly created object's
attributes knowing nothing more than what's in it's the symbol table.

My setters are named something like "set_xxx" where "xxx" is the
attribute I want to set. These live in Autoload and work as expected.

My problem is that when I dump the symbol table, none of the Autoload
methods appear until after the first invocation. I am wondering if
there is a way to get these loaded into the symbol table from my
constructor without calling each "set_xxx" explicitly.

Is there any way to do this?

Thanks,

Alejandro
 
B

Ben Morrow

I have a question about Autoload and the Symbol Table. I would like
to create setters and getters for various object attributes using
Autoload in order to populate object's from data at runtime given a
mapping. The idea here is that I would create objects dynamically
based on a type and then be able to "set" the newly created object's
attributes knowing nothing more than what's in it's the symbol table.

My setters are named something like "set_xxx" where "xxx" is the
attribute I want to set. These live in Autoload and work as expected.

My problem is that when I dump the symbol table, none of the Autoload
methods appear until after the first invocation. I am wondering if
there is a way to get these loaded into the symbol table from my
constructor without calling each "set_xxx" explicitly.

Is there any way to do this?

Yes there is, but it would almost certainly be better not to do it
this way. What I would do is have a method 'get_attributes' or some
such on each of these objects that returns a list of which attributes
are valid for that object: this is much safer than messing around with
the symbol table when you don't need to.

OTOH, if you *must* do this, the easiest way is

require subs;
import subs qw/set_one set_two/;

..

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top