Autoload and Symbol Table

Discussion in 'Perl Misc' started by Alejandro Calbazana, Jan 27, 2004.

  1. 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
     
    Alejandro Calbazana, Jan 27, 2004
    #1
    1. Advertising

  2. Alejandro Calbazana

    Ben Morrow Guest

    (Alejandro Calbazana) wrote:
    > 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

    --
    The cosmos, at best, is like a rubbish heap scattered at random.
    - Heraclitus
     
    Ben Morrow, Jan 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Schueler

    Tricky AUTOLOAD behavior

    Jim Schueler, Aug 25, 2004, in forum: Perl
    Replies:
    1
    Views:
    441
  2. mdudlik

    Autoload to a different frame

    mdudlik, Jun 6, 2004, in forum: HTML
    Replies:
    0
    Views:
    411
    mdudlik
    Jun 6, 2004
  3. Thomas Schneider

    Autoload Page outside of Frameset

    Thomas Schneider, Jun 2, 2005, in forum: HTML
    Replies:
    6
    Views:
    2,879
    Thomas Schneider
    Jun 8, 2005
  4. baumann@pan
    Replies:
    1
    Views:
    748
    Richard Bos
    Apr 15, 2005
  5. J Krugman

    *{$AUTOLOAD} vs *$AUTOLOAD

    J Krugman, Jul 13, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    98
    Tassilo v. Parseval
    Jul 14, 2005
Loading...

Share This Page